需要用户帐户的Nexus Django应用程序的核心库
django-genomix-users的Python项目详细描述
需要用户帐户的Nexus Django应用程序的核心库
快速启动
安装Django Genomix用户:
pip install django-genomix-users
在settings.py文件中对已安装的应用程序进行以下更改:
INSTALLED_APPS=(...'django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.sites','django.contrib.staticfiles',...'rest_framework','rest_framework.authtoken','rest_auth','django_filters',...'django_python3_ldap',...'genomix_users',...)
添加django genomix用户的url模式:
fromgenomix_usersimporturlsasgenomix_users_urlsurlpatterns=[...url(r'^',include(genomix_users_urls,namespace='users')),...]
确保settings.py文件已设置模板和静态URL设置(如下示例):
TEMPLATES=[{# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND'BACKEND':'django.template.backends.django.DjangoTemplates',# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs'DIRS':[os.path.join(ROOT_DIR,'templates'),os.path.join(APPS_DIR,'templates'),],'OPTIONS':{# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug'debug':DEBUG,# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types'loaders':['django.template.loaders.filesystem.Loader','django.template.loaders.app_directories.Loader',],# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors'context_processors':['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.template.context_processors.i18n','django.template.context_processors.media','django.template.context_processors.static','django.template.context_processors.tz','django.contrib.messages.context_processors.messages',# Your stuff: custom template context processors go here],},},]STATIC_URL='/static/'
确保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.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',]
可选设置
在settings.py中关闭关联用户配置文件的创建。
CREATE_PROFILE_ON_SAVE=False
在settings.py中启用身份验证以使用JSON Web令牌:
REST_USE_JWT=TrueREST_FRAMEWORK={'DEFAULT_PERMISSION_CLASSES':('rest_framework.permissions.IsAuthenticated',),'DEFAULT_AUTHENTICATION_CLASSES':('rest_framework_jwt.authentication.JSONWebTokenAuthentication','rest_framework.authentication.SessionAuthentication','rest_framework.authentication.BasicAuthentication',),}
在settings.py中启用LDAP身份验证:
LDAP_AUTH_URL='ldap://chop.edu:3268'LDAP_AUTH_USE_TLS=FalseLDAP_AUTH_SEARCH_BASE='dc=chop,dc=edu'LDAP_AUTH_OBJECT_CLASS='person'LDAP_AUTH_USER_LOOKUP_FIELDS=('username',)LDAP_AUTH_USER_FIELDS={"username":"sAMAccountName","first_name":"givenName","last_name":"sn","email":"mail",}LDAP_AUTH_FORMAT_USERNAME='django_python3_ldap.utils.format_username_active_directory'LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN='chop-edu'AUTHENTICATION_BACKENDS=['django.contrib.auth.backends.ModelBackend','django_python3_ldap.auth.LDAPBackend',]
在settings.py中启用LDAP用户组筛选:
LDAP_AUTH_FORMAT_SEARCH_FILTERS='genomix_users.authentication.genomix_search_filters'LDAP_AUTH_SEARCH_FILTER='CN=dgd_nexus_users,ou=DGD Groups,ou=SecurityGroups,ou=Research,ou=Managed By Others,dc=chop,dc=edu'
将用户配置文件与settings.py中的ldap字段同步:
注意
如果在保存时创建配置文件=false,LDAP配置文件将不同步!
LDAP_AUTH_SYNC_USER_RELATIONS="genomix_users.authentication.sync_genomix_profile"# User model fields mapped to the LDAP attributes that represent them.LDAP_AUTH_PROFILE_FIELDS={"title":"title",}
功能
- genomix rest api用于使用django-rest-auth
- 使用django-python3-ldap 的Genomix LDAP身份验证
运行测试
代码真的有用吗?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
历史记录
0.1.0(2017-12-03)
- pypi上的第一个版本。
- 初始模型和rest api。
0.5.0(2017-04-07)
- 增加了对django 2.0和python 3.6的支持
- 放弃了对django<;1.11和python 2.7、3.3、3.4的支持