def authenticate(self, request=None, username=None, password=None, **kwargs): if request is None: try: group = kwargs.get('group') if group.searh_user(username): return User(username=username) return None except: return None token = get_credentials(request, **kwargs) if token is not None: payload = get_payload(token, request) username = jwt_settings.JWT_PAYLOAD_GET_USERNAME_HANDLER(payload) ldap_user = _LDAPUser(self, username=username.strip(), request=request) if self.settings.USER_SEARCH is not None: user_dn = ldap_user._search_for_user_dn() elif self.settings.USER_DN_TEMPLATE is not None: user_dn = ldap_user._construct_simple_user_dn() else: user_dn = None if user_dn is not None: try: result_search = ldap_user.connection.search_s(user_dn, 0) if len(result_search) == 1 and result_search is not None: return User(username=username) return None except: return None if password or self.settings.PERMIT_EMPTY_PASSWORD: ldap_user = _LDAPUser(self, username=username.strip(), request=request) user = self.authenticate_ldap_user(ldap_user, password) else: logger.debug('Rejecting empty password for {}'.format(username)) user = None return user
def get_user_by_payload(payload): username = jwt_settings.JWT_PAYLOAD_GET_USERNAME_HANDLER(payload) if not username: raise exceptions.JSONWebTokenError(_("Invalid payload")) auth = AuthenticationDB.objects.get(name='AuthenticationDB') if auth.search_user(username): user = User(username=username) else: user = None if user is not None and not user.is_active: raise exceptions.JSONWebTokenError(_("User is disabled")) return user
def test_foreign_key_pk(self, *args): payload = utils.jwt_payload(self.user) username = jwt_settings.JWT_PAYLOAD_GET_USERNAME_HANDLER(payload) self.assertEqual(username, 'test')