我的团队正在开发securedjango项目,我们将django请求传输到自定义数据库后端。你知道吗
我们在django中为GSSAPI(SPNEGO)身份验证和委派用户凭据(用于代表用户查询服务器)制作了这样一个算法:
if 'HTTP_AUTHORIZATION' in request.META:
kind, initial_client_token = request.META['HTTP_AUTHORIZATION'].split(' ', 1)
if kind == 'Negotiate':
server = 'HTTP@server.domain.ru'
_ignore_result, krb_context = kerberos.authGSSServerInit(server)
kerberos.authGSSServerStep(krb_context, initial_client_token)
principal = kerberos.authGSSServerUserName(krb_context)
_ignore_result = kerberos.authGSSServerStoreDelegate(krb_context)
conn = psycopg2.connect(
host='krb5-dbhost',
user=principal,
dbname='db',
)
cursor = conn.cursor()
cursor.execute("SELECT version()")
records = cursor.fetchall()
这在django视图中效果很好。Kerberos服务器可以授权用户并缓存krb5票据,以便凭证委派在psycopg中查询。现在我们需要把它注入django。你知道吗
我们希望继承postgresql数据库后端,如下所示:
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper
class CustomDatabaseWrapper(DatabaseWrapper):
def __init__(self, *args, **kwargs):
super(CustomDatabaseWrapper, self).__init__(*args, **kwargs)
def get_connection_params(self):
'''We need to customize this function,
We need get request here when query processed by web interface,'''
#.... the source code could be here, but it is not necessary
return conn_params
所以问题是:“我们怎样才能请求.META(用于获取用户的协商令牌)以及如何将来自web界面的用户请求与管理命令分开
对不起我的英语技能。谢谢你!你知道吗
这是中间件和数据库后端,用于缓存django-lrucache-backend
以及postgresql的数据库后端
相关问题 更多 >
编程相关推荐