用Django和mod_wsgi設定SVN基本的授權認證
Consider this use case:
You have Django web application up and running on Apache and ‘mod_wsgi’. You plan to host Subversion repository on the same server and want it to be accessible to your web application users.
By default, Subversion will use ‘htpasswd’ file to authenticate users. So you will need to maintain two sets of users – one in ‘Django’ database and the other in Subversion ‘htpasswd’ file. You also need to keep them in sync so that the users have the same password and username for Subversion as well for logging in the web application.
Does that look like a lot of work to do? Is there a better way to do this? Yes, there is!
You can configure Apache to use Django’s authentication mechanism to authenticate users.
The ‘mod_wsgi’ comes to your rescue and makes things a lot easier for you.
Firstly, you need to define a ‘wsgi’ authentication handler script. which will tell Apache to use Django’s authentication for users accessing a Subversion repository.
import sys
import os
from django.contrib.auth.models import User
sys.path[0:0] = [
'/usr/lib/python/site-packages',
'/srv/src/app',
]
os.environ['DJANGO_SETTINGS_MODULE']='apphandler.settings'
from django.conf import settings
def check_password(environ, username, password):
user = None
try :
user = User.objects.get(**kwargs)
except :
return None
return user.check_password(password)
You have Django web application up and running on Apache and ‘mod_wsgi’. You plan to host Subversion repository on the same server and want it to be accessible to your web application users.
By default, Subversion will use ‘htpasswd’ file to authenticate users. So you will need to maintain two sets of users – one in ‘Django’ database and the other in Subversion ‘htpasswd’ file. You also need to keep them in sync so that the users have the same password and username for Subversion as well for logging in the web application.
Does that look like a lot of work to do? Is there a better way to do this? Yes, there is!
You can configure Apache to use Django’s authentication mechanism to authenticate users.
The ‘mod_wsgi’ comes to your rescue and makes things a lot easier for you.
Firstly, you need to define a ‘wsgi’ authentication handler script. which will tell Apache to use Django’s authentication for users accessing a Subversion repository.
CODE:
#! /usr/local/bin/pythonimport sys
import os
from django.contrib.auth.models import User
sys.path[0:0] = [
'/usr/lib/python/site-packages',
'/srv/src/app',
]
os.environ['DJANGO_SETTINGS_MODULE']='apphandler.settings'
from django.conf import settings
def check_password(environ, username, password):
user = None
try :
user = User.objects.get(**kwargs)
except :
return None
return user.check_password(password)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-739609/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Django(59)驗證和授權Django
- shiro授權和認證(四)
- 授權(Authorization)和認證(Authentication)
- 認證授權
- 【認證與授權】Spring Security的授權流程Spring
- 細說API - 認證、授權和憑證API
- 認證授權的設計與實現
- 認證授權:IdentityServer4 - 各種授權模式應用IDEServer模式
- 認證授權方案之JwtBearer認證JWT
- 認證授權方案之授權初識
- SpringSecurity認證和授權流程詳解SpringGse
- 認證授權方案之授權揭祕 (上篇)
- Spring Security OAuth2.0認證授權四:分散式系統認證授權SpringOAuth分散式
- 【認證與授權】2、基於session的認證方式Session
- OAuth 2.0 授權碼認證OAuth
- 認證授權:IdentityServer4IDEServer
- 認證授權:學習OIDC
- Ocelot(四)- 認證與授權
- Ceph配置與認證授權
- 認證授權問題概覽
- OAuth 2.0 授權認證詳解OAuth
- EMQX Cloud 更新:外部認證授權MQCloud
- DRF比Django的認證和許可權高在哪裡Django
- ASP.NET Core之身份認證和授權JWTASP.NETJWT
- EMQX Cloud 更新:新增 Redis 和 JWT 外部認證授權MQCloudRedisJWT
- ASP.NET Core 6.0 新增 JWT 認證和授權ASP.NETJWT
- 【認證與授權】Spring Security系列之認證流程解析Spring
- Django REST framework中認證和許可權的使用方法DjangoRESTFramework
- OAuth2.0認證授權workflow探究OAuth
- 認證授權:學習OAuth協議OAuth協議
- 微服務下認證授權框架的探討微服務框架
- 聊聊常見的服務(介面)認證授權
- gRPC四種模式、認證和授權實戰演示,必贊~~~RPC模式
- SpringSecurity(1)---認證+授權程式碼實現SpringGse
- SpringBoot--- 使用SpringSecurity進行授權認證Spring BootGse
- 中介軟體---登陸認證授權---Shiro
- 一看就懂的IdentityServer4認證授權設計方案IDEServer
- MongoDB資料庫授權認證的實現JRMYMongoDB資料庫
- 快速理解ASP.NET Core的認證與授權ASP.NET