Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

userena breaks ldap authentication #87

Open
trbs opened this issue Oct 16, 2013 · 9 comments
Open

userena breaks ldap authentication #87

trbs opened this issue Oct 16, 2013 · 9 comments

Comments

@trbs
Copy link

trbs commented Oct 16, 2013

Because userena and localshop use a different set of login parameters then the default this breaks thirdparty backends like django_auth_ldap.

The workaround is some additional code like this:

from django_auth_ldap.backend import LDAPBackend as Orig

class LDAPBackend(Orig):
    def authenticate(self, username=None, password=None, identification=None):
        if identification and not username:
            username = identification
        return super(LDAPBackend, self).authenticate(username, password)

But it's kind of silly that users have to jump through all these hoops for a django app that should just-work(tm).

@cocoy
Copy link

cocoy commented Mar 17, 2014

Hi @trbs I've tried adding your code see #102 it work, but other pages are now now forbidden when accessed. Any tips to solve this? Thanks in advance.

@trbs
Copy link
Author

trbs commented Mar 17, 2014

Hi @cocoy I'm using a very similar setup to your #102

Differences are:

In settings.py:

AUTHENTICATION_BACKENDS = (
    'ldap_workaround.LDAPBackend',
    'userena.backends.UserenaAuthenticationBackend',
    'guardian.backends.ObjectPermissionBackend',
    'localshop.apps.permissions.backend.CredentialBackend',
    'django.contrib.auth.backends.ModelBackend',
)

I have LDAP as the first AUTHENTICATION_BACKENDS

And I'm using in ldap_workaround.py:

# {{ ansible_managed }}

from django_auth_ldap.backend import LDAPBackend as Orig

class LDAPBackend(Orig):
    def authenticate(self, username=None, password=None, identification=None):
        if identification and not username:
            username = identification
        return super(LDAPBackend, self).authenticate(username, password)

from django.db.models.signals import post_save
from django.contrib.auth.models import User
from localshop.apps.permissions.models import AuthProfile

def create_auth_profile(sender, **kwargs):
    user = kwargs['instance']
    if kwargs['created']:
        AuthProfile(user=user).save()

post_save.connect(create_auth_profile, sender=User, dispatch_uid="create_auth_profile")

Maybe be that the order of the AUTHENTICATION_BACKENDS is causing problems for you ?

@cocoy
Copy link

cocoy commented Mar 17, 2014

@trbs Seems I missed the lines below to create profiles, I assume this is required.
Thanks, will try it out.

@cocoy
Copy link

cocoy commented Mar 18, 2014

LDAP login works fine, can login without problem. But clicking on other pages like says Forbidden
http://mylocalserver/packages/

@sposs
Copy link

sposs commented Nov 10, 2014

For the forbidden thing, make sure you have

AUTH_LDAP_USER_FLAGS_BY_GROUP = {
        "is_active": "cn=group,cn=groups,dc=company,dc=com",
        "is_staff": ["cn=group,cn=groups,dc=company,dc=com"],
        "is_superuser": "cn=group,cn=groups,dc=company,dc=com"
    }

Seems the is_superuser is what is required to be able to browse the other pages...

@cocoy
Copy link

cocoy commented Nov 11, 2014

Seems my issue on Forbidden pages, because the group in LDAP has no access on the packages.

I have to allow package | packages | can View Packages on the admin page i.e http://localhost:8000/admin/auth/group/

Maybe this one fixes the same config at localshop.conf.py

@cocoy
Copy link

cocoy commented Nov 11, 2014

Indeed @sposs it works!

@cocoy
Copy link

cocoy commented Nov 11, 2014

ah, problem is the other permissions on admin pages were granted to the ldap user when set to is_superuser

@mvantellingen
Copy link
Owner

Just a FYI, i've just removed django-userena in the develop branch so i'm hoping to get ldap support built-in by default now. Let me know if you have any tips or can even help me with a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants