我有一个带有以下参数的Django应用程序:
Debian:9.9 Apache2:2.4.25-3 + deb9u7 的Django:2.2.1 MySQL的:mariadb-server-10.1
。对于身份验证,我想使用远程身份验证,但要通过本地数据库。有任何认证类吗?
我的目标是弹出apache2进行身份验证,但是身份验证数据(例如)不应来自ldap,而应来自本地数据库,并且还应设置REMOTE_USER变量。
我当前的apache conf文件现在看起来像这样:
<VirtualHost *:80>
ServerName 127.0.0.25
ServerAlias infokom.localhost prj.256.hu prj.128.hu
DocumentRoot /usr/share/prj
<Directory /usr/share/prj>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess prj.djangoserver user=prj processes=10 threads=20 display-name=%{GROUP} python-path=/usr/share/prj:/home/prj/.virtualenvs/prj/lib/python3.5/site-packages
WSGIProcessGroup prj.djangoserver
WSGIScriptAlias / /usr/share/prj/prj/wsgi.py
CustomLog ${APACHE_LOG_DIR}/prj-access.log combined
ErrorLog ${APACHE_LOG_DIR}/prj-error.log
LogLevel debug
</VirtualHost>
。 wsgi.py文件很简单:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cworld.settings')
application = get_wsgi_application()
。相关的settings.py部分:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
...
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.RemoteUserBackend']
。在需要日志的情况下,使用此当前设置,它会将我重定向到登录页面(例如:/ accounts / login /?next = ...),但我希望在此处使用apache2弹出窗口进行身份验证。