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

LDAP and local accounts #31

Closed
keans opened this issue Jan 11, 2018 · 4 comments
Closed

LDAP and local accounts #31

keans opened this issue Jan 11, 2018 · 4 comments

Comments

@keans
Copy link

keans commented Jan 11, 2018

I am using the module in combination with the sqlalchemy module. As far as I can see it is not possible to have LDAP as well as local users. Is it planned or am I missing something?

@nickw444
Copy link
Owner

nickw444 commented Jan 11, 2018

This is definitely possible - I have done this in many projects. I.e. having local root privilege users.

You can do this by providing a custom Login Form. See forms.py - it provides LDAPLoginForm. You can either make your own, or create a subclass of this to provide the custom validation.

Your best bet here would be to do something like:

from flask_ldap3_login.forms import LDAPLoginForm
from flask_wtf import FlaskForm

class MyAuthForm(LDAPLoginForm):
    def validate(self,  *args, **kwargs):
        valid = FlaskForm.validate(self, *args, **kwargs)
        if not valid:
            print("Form validation failed")
            return valid
        if self.username.data == 'root' and self.password.data == 'mycoolpassword':
            # TODO: Replace this with a call to your users datastore.
            return True

        # User not a local user, just do the normal LDAP validation
        return super().validate(*args, **kwargs)

@keans
Copy link
Author

keans commented Jan 12, 2018

Thanks for the reply. Yes, I also thought about overwriting the form, but I thought that is a common desire that could be implemented as part of the module. Anyways, I will try your suggestion...

@nickw444
Copy link
Owner

I aim to keep this module as use-case agnostic as possible to allow it to be as flexible as possible and work for the masses.

@nickw444
Copy link
Owner

Closing this issue out for now, if you have any other problems feel free to reply or open another issue.

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

No branches or pull requests

2 participants