Hello,
I'm handling authentication with a SAML2 IdP, using djangosaml2, in order to have single sign-on functionality. However, I need to be able to do authorization via ldap groups which are not part of the SAML assertion. From my understanding of the django_auth_ldap, I should be able to do this using AUTH_LDAP_AUTHORIZE_ALL_USERS and AUTH_LDAP_FIND_GROUP_PERMS settings, but I'm having some difficulties. My authentication works correctly, but it doesn't seem the ldap backend ever gets called for the authz part, as I don't see any group searches on the LDAP server. Below are what I think are my relevant settings. I've tested basic connectivity to my ldap server. I was also able to remove the saml2 backend, use a user dn template, and successfully authenticate with LDAP, so I know there isn't anything wrong with the basic installation or setup. I'm fairly new to django so any assistance would be greatly appreciated.
AUTHENTICATION_BACKENDS = (
'djangosaml2.backends.Saml2Backend',
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_LDAP_SERVER_URI = ldap://
ldap.myserver.orgAUTH_LDAP_GROUP_SEARCH = LDAPSearch('ou=Groups,dc=mydomain,dc=org', ldap.SCOPE_SUBTREE, '(objectClass=groupOfNames)')
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr="cn")
AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_AUTHORIZE_ALL_USERS = True
In my view code I'm using an @user_passes_test decorator and checking is the user is in a special group in order to grant access, like;
def in_allow_group(user):
"""Use with a ``user_passes_test`` decorator to restrict access to
authenticated users who are in allowed group."""
return user.is_authenticated() and user.groups.filter(name=allow_group).exists()
Should I be making a call directly to the LDAPBackend code instead of user.groups or is there something else I should be doing to have the LDAP code map the users group membership?
Thanks for any assistance.
-Brian