コード例 #1
0
ファイル: ldap.py プロジェクト: EthanChen-Field/atmosphere
def lookupUser(userid):
    """
    Grabs email for the user based on LDAP attrs
    """
    try:
        attr = _search_ldap(userid)
        user_attrs = attr[0][1]
        return user_attrs
    except Exception as e:
        logger.warn("Error occurred looking up user: %s" % userid)
        logger.exception(e)
        raise
コード例 #2
0
ファイル: ldap.py プロジェクト: Angelfirenze/atmosphere
def _search_ldap(userid, conn=None):
    try:
        if not conn:
            conn = ldap_driver.initialize(secrets.LDAP_SERVER)
        result = conn.search_s(secrets.LDAP_SERVER_DN,
                               ldap_driver.SCOPE_SUBTREE,
                               '(uid=' + userid + ')')
        return result
    except Exception as e:
        logger.warn("Error occurred on ldap search for: %s" % userid)
        logger.exception(e)
        return None
コード例 #3
0
ファイル: ldap.py プロジェクト: Angelfirenze/atmosphere
def lookupUser(userid):
    """
    Grabs email for the user based on LDAP attrs
    """
    try:
        attr = _search_ldap(userid)
        user_attrs = attr[0][1]
        return user_attrs
    except Exception as e:
        logger.warn("Error occurred looking up user: %s" % userid)
        logger.exception(e)
        raise
コード例 #4
0
def oauth_formatAttrs(oauth_attrs):
    """
    Formats attrs into a unified dict to ease in user creation
    """
    try:
        return {
            'email': oauth_attrs['mail'],
            'firstName': oauth_attrs['givenname'],
            'lastName': oauth_attrs['sn'],
        }
    except KeyError as nokey:
        logger.exception(nokey)
        return None
コード例 #5
0
ファイル: oauth.py プロジェクト: EmilyCressey/atmosphere
def oauth_formatAttrs(oauth_attrs):
    """
    Formats attrs into a unified dict to ease in user creation
    """
    try:
        return {
            'email': oauth_attrs['mail'],
            'firstName': oauth_attrs['givenname'],
            'lastName': oauth_attrs['sn'],
        }
    except KeyError as nokey:
        logger.exception(nokey)
        return None
コード例 #6
0
ファイル: ldap.py プロジェクト: Angelfirenze/atmosphere
def ldap_formatAttrs(ldap_attrs):
    """
    Formats attrs into a unified dict to ease in user creation
    """
    logger.info(ldap_attrs)
    try:
        return {
            'email': ldap_attrs['mail'][0],
            'firstName': ldap_attrs['givenName'][0],
            'lastName': ldap_attrs['sn'][0],
        }
    except KeyError as nokey:
        logger.exception(nokey)
        return None
コード例 #7
0
ファイル: ldap.py プロジェクト: EthanChen-Field/atmosphere
def _search_ldap(userid, conn=None):
    try:
        if not conn:
            conn = ldap_driver.initialize(auth_settings.LDAP_SERVER)
        result = conn.search_s(
            auth_settings.LDAP_SERVER_DN,
            ldap_driver.SCOPE_SUBTREE,
            '(uid=' + userid + ')'
        )
        return result
    except Exception as e:
        logger.warn("Error occurred on ldap search for: %s" % userid)
        logger.exception(e)
        return None
コード例 #8
0
ファイル: ldap.py プロジェクト: EthanChen-Field/atmosphere
def get_members(groupname):
    """
    """
    try:
        ldap_server = auth_settings.LDAP_SERVER
        ldap_group_dn = auth_settings.LDAP_SERVER_DN.replace(
            "ou=people", "ou=Groups")
        ldap_conn = ldap_driver.initialize(ldap_server)
        group_users = ldap_conn.search_s(
            ldap_group_dn, ldap_driver.SCOPE_SUBTREE, '(cn=%s)' % groupname)
        return group_users[0][1]['memberUid']
    except Exception as e:
        logger.exception(e)
        return []
コード例 #9
0
ファイル: ldap.py プロジェクト: EthanChen-Field/atmosphere
def ldap_formatAttrs(ldap_attrs):
    """
    Formats attrs into a unified dict to ease in user creation
    """
    logger.info(ldap_attrs)
    try:
        return {
            'email': ldap_attrs['mail'][0],
            'firstName': ldap_attrs['givenName'][0],
            'lastName': ldap_attrs['sn'][0],
        }
    except KeyError as nokey:
        logger.exception(nokey)
        return None
コード例 #10
0
ファイル: ldap.py プロジェクト: Angelfirenze/atmosphere
def get_members(groupname):
    """
    """
    try:
        ldap_server = secrets.LDAP_SERVER
        ldap_group_dn = secrets.LDAP_SERVER_DN.replace("ou=people",
                                                       "ou=Groups")
        ldap_conn = ldap_driver.initialize(ldap_server)
        group_users = ldap_conn.search_s(ldap_group_dn,
                                         ldap_driver.SCOPE_SUBTREE,
                                         '(cn=%s)' % groupname)
        return group_users[0][1]['memberUid']
    except Exception as e:
        logger.exception(e)
        return []
コード例 #11
0
ファイル: ldap.py プロジェクト: EthanChen-Field/atmosphere
def lookupEmail(userid):
    """
    Grabs email for the user based on LDAP attrs
    """
    try:
        logger.debug(type(userid))
        if isinstance(userid, WSGIRequest):
            raise Exception("WSGIRequest invalid.")
        attr = _search_ldap(userid)
        emailaddr = attr[0][1]['mail'][0]
        return emailaddr
    except Exception as e:
        logger.warn("Error occurred looking up email for user: %s" % userid)
        logger.exception(e)
        raise
コード例 #12
0
ファイル: ldap.py プロジェクト: Angelfirenze/atmosphere
def lookupEmail(userid):
    """
    Grabs email for the user based on LDAP attrs
    """
    try:
        logger.debug(type(userid))
        if isinstance(userid, WSGIRequest):
            raise Exception("WSGIRequest invalid.")
        attr = _search_ldap(userid)
        emailaddr = attr[0][1]['mail'][0]
        return emailaddr
    except Exception as e:
        logger.warn("Error occurred looking up email for user: %s" % userid)
        logger.exception(e)
        raise
コード例 #13
0
ファイル: ldap.py プロジェクト: Angelfirenze/atmosphere
def getAllUsers():
    """
    Grabs all users in LDAP
    """
    try:
        conn = ldap_driver.initialize(secrets.LDAP_SERVER)
        user_list = []
        for letter in string.lowercase:
            attr = _search_ldap("%s*" % letter, conn)
            for i in xrange(0, len(attr)):
                user_attrs = attr[i][1]
                user_list.append(user_attrs)
        return user_list
    except Exception as e:
        logger.warn("Error occurred looking up all user")
        logger.exception(e)
        return None
コード例 #14
0
ファイル: ldap.py プロジェクト: EthanChen-Field/atmosphere
def getAllUsers():
    """
    Grabs all users in LDAP
    """
    try:
        conn = ldap_driver.initialize(auth_settings.LDAP_SERVER)
        user_list = []
        for letter in string.lowercase:
            attr = _search_ldap("%s*" % letter, conn)
            for i in xrange(0, len(attr)):
                user_attrs = attr[i][1]
                user_list.append(user_attrs)
        return user_list
    except Exception as e:
        logger.warn("Error occurred looking up all user")
        logger.exception(e)
        return None
コード例 #15
0
ファイル: ldap.py プロジェクト: EthanChen-Field/atmosphere
def ldap_validate(username, password):
    """
    ldap_validate
    Using the username and password parameters, test with an LDAP bind.
    If the connection succeeds, the credentials are authentic.
    """
    if not username or not password:
        logger.warn("[LDAP] Skip Test - Username/Password combination missing")
        return

    try:
        ldap_server = auth_settings.LDAP_SERVER
        ldap_server_dn = auth_settings.LDAP_SERVER_DN
        logger.warn("[LDAP] Validation Test - %s" % username)
        ldap_conn = ldap_driver.initialize(ldap_server)
        dn = "uid=" + username + "," + ldap_server_dn
        ldap_conn.simple_bind_s(dn, password)
        return True
    except Exception as e:
        logger.exception(e)
        return False
コード例 #16
0
ファイル: ldap.py プロジェクト: Angelfirenze/atmosphere
def ldap_validate(username, password):
    """
    ldap_validate
    Using the username and password parameters, test with an LDAP bind.
    If the connection succeeds, the credentials are authentic.
    """
    if not username or not password:
        logger.warn("[LDAP] Skip Test - Username/Password combination missing")
        return

    try:
        ldap_server = secrets.LDAP_SERVER
        ldap_server_dn = secrets.LDAP_SERVER_DN
        logger.warn("[LDAP] Validation Test - %s" % username)
        ldap_conn = ldap_driver.initialize(ldap_server)
        dn = "uid=" + username + "," + ldap_server_dn
        ldap_conn.simple_bind_s(dn, password)
        return True
    except Exception as e:
        logger.exception(e)
        return False
コード例 #17
0
ファイル: cas.py プロジェクト: EmilyCressey/atmosphere
def cas_validateUser(username):
    """
    Because this is a programmatic request
    and CAS requires user input when expired,
    We MUST use CAS Proxy Service,
    and see if we can reauthenticate the user.
    """
    try:
        userProxy = UserProxy.objects.filter(username=username).latest('pk')
        logger.debug("[CAS] Validation Test - %s" % username)
        if userProxy is None:
            logger.debug("User %s does not have a proxy" % username)
            return (False, None)
        proxyTicket = userProxy.proxyTicket
        caslib = get_cas_client()
        (validUser, cas_response) =\
            caslib.reauthenticate(proxyTicket, username=username)
        logger.debug("Valid User: %s Proxy response: %s"
                     % (validUser, cas_response))
        return (validUser, cas_response)
    except Exception:
        logger.exception('Error validating user %s' % username)
        return (False, None)
コード例 #18
0
ファイル: ldap.py プロジェクト: cnbeining2/atmosphere
def lookupEmail(userid):
    """
    Grabs email for the user based on LDAP attrs
    """
    try:
        logger.debug(type(userid))
        if isinstance(userid, WSGIRequest):
            raise Exception("WSGIRequest invalid.")
        attr = _search_ldap(userid)
        emailaddr = attr[0][1]['mail'][0]
        return emailaddr
    except Exception as e:
        logger.warn("Error occurred looking up email for user: %s" % userid)
        logger.exception(e)
        import traceback
        import sys
        import inspect
        s = inspect.stack()
        for i in range(0, 4):
            logger.debug(s[i])
        etype, value, tb = sys.exc_info()
        logger.error("TB = %s" % traceback.format_tb(tb))

        return None