(self, form)
| 49 | return gettext("ldap") |
| 50 | |
| 51 | def authenticate(self, form): |
| 52 | self.username = form.data['email'] |
| 53 | self.password = form.data['password'] |
| 54 | self.dedicated_user = True |
| 55 | self.start_tls = False |
| 56 | user_email = None |
| 57 | |
| 58 | # Check the dedicated ldap user |
| 59 | self.bind_user = getattr(config, 'LDAP_BIND_USER', None) |
| 60 | self.bind_pass = getattr(config, 'LDAP_BIND_PASSWORD', None) |
| 61 | |
| 62 | # Check for the anonymous binding |
| 63 | self.anonymous_bind = getattr(config, 'LDAP_ANONYMOUS_BIND', False) |
| 64 | |
| 65 | if self.bind_user and not self.bind_pass: |
| 66 | return False, gettext( |
| 67 | "LDAP configuration error: Set the bind password.") |
| 68 | |
| 69 | # if no dedicated ldap user is configured then use the login |
| 70 | # username and password |
| 71 | if not self.bind_user and not self.bind_pass and\ |
| 72 | self.anonymous_bind is False: |
| 73 | |
| 74 | user_dn = config.LDAP_BIND_FORMAT\ |
| 75 | .format( |
| 76 | LDAP_USERNAME=self.username, |
| 77 | LDAP_BASE_DN=config.LDAP_BASE_DN, |
| 78 | LDAP_USERNAME_ATTRIBUTE=config.LDAP_USERNAME_ATTRIBUTE |
| 79 | ) |
| 80 | |
| 81 | self.bind_user = user_dn |
| 82 | self.bind_pass = self.password |
| 83 | self.dedicated_user = False |
| 84 | |
| 85 | # Connect ldap server |
| 86 | status, msg = self.connect() |
| 87 | |
| 88 | if not status: |
| 89 | return status, msg |
| 90 | |
| 91 | status, ldap_user = self.search_ldap_user() |
| 92 | |
| 93 | if not status: |
| 94 | return status, ldap_user |
| 95 | |
| 96 | # If dedicated user is configured |
| 97 | if self.dedicated_user: |
| 98 | # Get the user DN from the user ldap entry |
| 99 | self.bind_user = ldap_user.entry_dn |
| 100 | self.bind_pass = self.password |
| 101 | self.anonymous_bind = False |
| 102 | status, msg = self.connect() |
| 103 | |
| 104 | if not status: |
| 105 | return status, msg |
| 106 | |
| 107 | if 'mail' in ldap_user: |
| 108 | mail = ldap_user['mail'].value |
no test coverage detected