Ejemplo n.º 1
0
    def __init__(self, username_pattern, base_dn):
        authenticator = LdapAuthenticator(
            {
                'url': 'unused',
                'username_pattern': username_pattern,
                'base_dn': base_dn
            }, test_utils.temp_folder)

        def connect(username, password):
            server = Server('mock_server', get_info=OFFLINE_AD_2012_R2)
            connection = Connection(server,
                                    user=username,
                                    password=password,
                                    authentication=SIMPLE,
                                    read_only=True,
                                    client_strategy=MOCK_SYNC)

            for dn, attrs in self._entries.items():
                dn = safe_dn(dn).lower()

                entry_added = connection.strategy.add_entry(dn, attrs)
                if not entry_added:
                    raise Exception('Failed to add entry ' + dn)

                lower_keys = {key.lower(): key for key in attrs.keys()}

                if 'samaccountname' in lower_keys:
                    account_name = attrs[lower_keys['samaccountname']][0]
                    domain_start = dn.find('dc=') + 3
                    domain_end = dn.find(',', domain_start)
                    domain = dn[domain_start:domain_end]
                    connection.server.dit[
                        domain + '\\' +
                        account_name] = connection.server.dit[dn]

                if 'userprincipalname' in lower_keys:
                    principal_name = attrs[lower_keys['userprincipalname']][0]
                    connection.server.dit[
                        principal_name] = connection.server.dit[dn]

            connection.bind()
            return connection

        authenticator._connect = connect

        self.base_dn = base_dn
        self._entries = {}
        self.authenticator = authenticator
Ejemplo n.º 2
0
def create_authenticator(auth_object, temp_folder):
    auth_type = auth_object.get('type')

    if not auth_type:
        raise Exception('Auth type should be specified')

    auth_type = auth_type.strip().lower()
    if auth_type == 'ldap':
        from auth.auth_ldap import LdapAuthenticator
        authenticator = LdapAuthenticator(auth_object, temp_folder)
    elif auth_type == 'google_oauth':
        from auth.auth_google_oauth import GoogleOauthAuthenticator
        authenticator = GoogleOauthAuthenticator(auth_object)
    elif auth_type == 'gitlab':
        from auth.auth_gitlab import GitlabOAuthAuthenticator
        authenticator = GitlabOAuthAuthenticator(auth_object)
    elif auth_type == 'htpasswd':
        from auth.auth_htpasswd import HtpasswdAuthenticator
        authenticator = HtpasswdAuthenticator(auth_object)
    else:
        raise Exception(auth_type + ' auth is not supported')

    authenticator.auth_expiration_days = float(
        auth_object.get('expiration_days', 30))

    authenticator.auth_type = auth_type

    return authenticator
Ejemplo n.º 3
0
def create_authenticator(auth_object, temp_folder):
    auth_type = auth_object.get('type')

    if not auth_type:
        raise Exception('Auth type should be specified')

    auth_type = auth_type.strip().lower()
    if auth_type == 'ldap':
        from auth.auth_ldap import LdapAuthenticator
        authenticator = LdapAuthenticator(auth_object, temp_folder)
    elif auth_type == 'google_oauth':
        from auth.auth_google_oauth import GoogleOauthAuthenticator
        authenticator = GoogleOauthAuthenticator(auth_object)
    else:
        raise Exception(auth_type + ' auth is not supported')

    authenticator.auth_type = auth_type

    return authenticator
Ejemplo n.º 4
0
def create_authenticator(auth_object, temp_folder):
    auth_type = auth_object.get('type')

    if not auth_type:
        raise Exception('Auth type should be specified')

    auth_type = auth_type.strip().lower()
    if auth_type == 'ldap':
        from auth.auth_ldap import LdapAuthenticator
        authenticator = LdapAuthenticator(auth_object, temp_folder)
    elif auth_type == 'google_oauth':
        from auth.auth_google_oauth import GoogleOauthAuthenticator
        authenticator = GoogleOauthAuthenticator(auth_object)
    else:
        raise Exception(auth_type + ' auth is not supported')

    authenticator.auth_type = auth_type

    return authenticator