Exemplo n.º 1
0
def create_user(username):
    oauth_attrs = lookupUser(username)
    attributes = oauth_formatAttrs(oauth_attrs)
    # FIXME: valid user should actually be set
    valid_user = None
    user = get_or_create_user(valid_user, attributes)
    return user
Exemplo n.º 2
0
    def authenticate(self, username=None, password=None, request=None):
        """
        Return user if validated by LDAP.
        Return None otherwise.
        """
        #First argument, username, should hold the OAuth Token, no password.
        # if 'username' in username, the authentication is meant for CAS
        # if username and password, the authentication is meant for LDAP
        logger.debug("[OAUTH] Authentication Test")
        if not request:
            logger.debug("[OAUTH] Authentication skipped - No Request.")
            return None
        auth = request.META.get('HTTP_AUTHORIZATION', '').split()
        if len(auth) == 2 and auth[0].lower() == "Bearer":
            oauth_token = auth[1]
        logger.debug("[OAUTH] OAuth Token - %s " % oauth_token)

        valid_user, _ = get_user_for_token(oauth_token)
        if not valid_user:
            logger.debug("[OAUTH] Token %s invalid, no user found."
                         % oauth_token)
            return None
        logger.debug("[OAUTH] Authorized user %s" % valid_user)
        oauth_attrs = oauth_lookupUser(valid_user)
        attributes = oauth_formatAttrs(oauth_attrs)
        logger.debug("[OAUTH] Authentication Success - " + valid_user)
        return get_or_create_user(valid_user, attributes)
Exemplo n.º 3
0
def create_user(username):
    oauth_attrs = lookupUser(username)
    attributes = oauth_formatAttrs(oauth_attrs)
    # FIXME: valid user should actually be set
    valid_user = None
    user = get_or_create_user(valid_user, attributes)
    return user
Exemplo n.º 4
0
 def authenticate(self, username=None, password=None, request=None):
     """
     Return user if Always
     Return None Never.
     """
     return get_or_create_user(username, {
         'firstName':"Mocky Mock",
         'lastName':"MockDoodle",
         'email': '*****@*****.**'})
Exemplo n.º 5
0
 def authenticate(self, username=None, password=None, request=None):
     """
     Return user if Always
     Return None Never.
     """
     return get_or_create_user(username, {
         'firstName':"Mocky Mock",
         'lastName':"MockDoodle",
         'email': '*****@*****.**'})
Exemplo n.º 6
0
 def _mock_oauth_login(self, oauth_token):
     username = settings.ALWAYS_AUTH_USER
     user = get_or_create_user(username, {
         'firstName': "Mocky Mock",
         'lastName': "MockDoodle",
         'email': '*****@*****.**' % settings.ALWAYS_AUTH_USER,
         'entitlement': []})
     _, token = self.model.objects.get_or_create(key=oauth_token, user=user)
     return user, token
Exemplo n.º 7
0
 def authenticate(self, username=None, password=None, request=None):
     """
     Return user if validated by LDAP.
     Return None otherwise.
     """
     if not ldap_validate(username, password):
         logger.debug("LDAP Authentication failed - "+username)
         return None
     ldap_attrs = ldap_lookupUser(username)
     attributes = ldap_formatAttrs(ldap_attrs)
     return get_or_create_user(username, attributes)
Exemplo n.º 8
0
 def _mock_oauth_login(self, oauth_token):
     username = settings.ALWAYS_AUTH_USER
     user = get_or_create_user(
         username, {
             'firstName': "Mocky Mock",
             'lastName': "MockDoodle",
             'email':
             '*****@*****.**' % settings.ALWAYS_AUTH_USER,
             'entitlement': []
         })
     _, token = self.model.objects.get_or_create(key=oauth_token, user=user)
     return user, token
Exemplo n.º 9
0
 def _mock_oauth_login(self, oauth_token):
     username = settings.ALWAYS_AUTH_USER
     user = get_or_create_user(
         username,
         {
             "firstName": "Mocky Mock",
             "lastName": "MockDoodle",
             "email": "*****@*****.**" % settings.ALWAYS_AUTH_USER,
             "entitlement": [],
         },
     )
     _, token = self.model.objects.get_or_create(key=oauth_token, user=user)
     return user, token
Exemplo n.º 10
0
 def authenticate(self, username=None, password=None, request=None):
     """
     Return user if validated by LDAP.
     Return None otherwise.
     """
     # logger.debug("LDAPBackend-- U:%s P:%s R:%s"
     #              % (username, password, request))
     if not ldap_validate(username, password):
         logger.debug("LDAP Authentication failed - "+username)
         return None
     ldap_attrs = ldap_lookupUser(username)
     attributes = ldap_formatAttrs(ldap_attrs)
     logger.debug("[LDAP] Authentication Success - " + username)
     return get_or_create_user(username, attributes)
Exemplo n.º 11
0
 def authenticate(self, username=None, password=None, request=None):
     """
     Return user if validated by LDAP.
     Return None otherwise.
     """
     # logger.debug("LDAPBackend-- U:%s P:%s R:%s"
     #              % (username, password, request))
     if not ldap_validate(username, password):
         logger.debug("LDAP Authentication failed - " + username)
         return None
     ldap_attrs = ldap_lookupUser(username)
     attributes = ldap_formatAttrs(ldap_attrs)
     logger.debug("[LDAP] Authentication Success - " + username)
     return get_or_create_user(username, attributes)
Exemplo n.º 12
0
 def authenticate(self, username=None, password=None, request=None):
     """
     Return user if validated by CAS
     Return None otherwise.
     """
     logger.debug("U:%s P:%s R:%s" % (username, password, request))
     if not username:
         logger.debug("CAS Authentication skipped - No Username.")
         return None
     (success, cas_response) = cas_validateUser(username)
     logger.info("Authenticate by CAS: %s - %s %s"
                 % (username, success, cas_response))
     if not success:
         logger.debug("CAS Authentication failed - "+username)
         return None
     attributes = cas_response.attributes
     return get_or_create_user(username, attributes)
Exemplo n.º 13
0
 def authenticate(self, username=None, password=None, auth_token=None,
                  request=None):
     """
     Return user if validated by their auth_token
     Return None otherwise.
     """
     try:
         valid_token = Token.objects.get(key=auth_token)
     except Token.DoesNotExist:
         return None
     if valid_token.is_expired():
         logger.debug(
             "[AUTHTOKEN] Token %s is expired. (User:%s)"
             % (valid_token.key, valid_token.user))
         return None
     logger.debug(
         "[AUTHTOKEN] Valid Token %s (User:%s)"
         % (valid_token.key, valid_token.user))
     valid_user = valid_token.user
     return get_or_create_user(valid_user.username, None)
Exemplo n.º 14
0
 def authenticate(self, username=None, password=None, auth_token=None,
                  request=None):
     """
     Return user if validated by their auth_token
     Return None otherwise.
     """
     try:
         valid_token = Token.objects.get(key=auth_token)
     except Token.DoesNotExist:
         return None
     if valid_token.is_expired():
         logger.debug(
             "[AUTHTOKEN] Token %s is expired. (User:%s)"
             % (valid_token.key, valid_token.user))
         return None
     logger.debug(
         "[AUTHTOKEN] Valid Token %s (User:%s)"
         % (valid_token.key, valid_token.user))
     valid_user = valid_token.user
     return get_or_create_user(valid_user, None)
Exemplo n.º 15
0
def create_user(username):
    oauth_attrs = lookupUser(username)
    attributes = oauth_formatAttrs(oauth_attrs)
    user = get_or_create_user(valid_user, attributes)
    return user