def agent_from_uf(ldap_folder, **config): """ Get agent instance based on acl_users LDAP User Folder""" server = ldap_folder._delegate._servers[0] config['ldap_server'] = "%s:%s" % (server['host'], server['port']) try: config['users_dn'] = ldap_folder.users_base config['roles_dn'] = ldap_folder.groups_base except AttributeError: # Leave eea.userdb defaults pass db = UsersDB(**config) if config.get('bind') == True: user_dn, user_pwd = config.get('user_dn'), config.get('user_pw', '') if not user_dn: user = getSecurityManager().getUser() if isinstance(user, LDAPUser): user_dn = user.getUserDN() user_pwd = user._getPassword() if not user_pwd or user_pwd == 'undef': # This user object did not result from a login user_dn = user_pwd = '' else: user_dn = user_pwd = '' db.perform_bind(user_dn, user_pwd) return db
def agent_from_uf(ldap_folder, **config): """ Get agent instance based on acl_users LDAP User Folder""" server = ldap_folder._delegate._servers[0] config['ldap_server'] = "%s:%s" % (server['host'], server['port']) try: config['users_dn'] = ldap_folder.users_base config['roles_dn'] = ldap_folder.groups_base except AttributeError: # Leave eea.userdb defaults pass db = UsersDB(**config) if config.get('bind') is True: user_dn, user_pwd = config.get('user_dn'), config.get('user_pw', '') if not user_dn: user = getSecurityManager().getUser() if isinstance(user, LDAPUser): user_dn = user.getUserDN() user_pwd = user._getPassword() if not user_pwd or user_pwd == 'undef': # This user object did not result from a login user_dn = user_pwd = '' else: user_dn = user_pwd = '' db.perform_bind(user_dn, user_pwd) return db
def get_ldap_user_info(user_id): ldap_server = flask.current_app.config.get('EEA_LDAP_SERVER', '') users_db = UsersDB(ldap_server=ldap_server) try: return users_db.user_info(user_id) except UserNotFound: return None except ldap.INVALID_DN_SYNTAX: return None
def ldap_agent_with_config(config, bind=False, secondary=False): db = UsersDB( ldap_server=config['ldap_server'], # next is for bwd compat with objects created with v1.0.0 users_rdn=config.get('users_rdn', defaults['users_rdn']), users_dn=config['users_dn'], orgs_dn=config['orgs_dn'], roles_dn=config['roles_dn']) if bind: if secondary: db.perform_bind(config['secondary_admin_dn'], config['secondary_admin_pw']) else: db.perform_bind(config['admin_dn'], config['admin_pw']) legacy_ldap_server = config.get('legacy_ldap_server', None) if legacy_ldap_server: from eea.userseditor.users_editor import (CircaUsersDB, CIRCA_USERS_DN_SUFFIX, DualLDAPProxy) legacy_db = CircaUsersDB(ldap_server=legacy_ldap_server, users_dn=CIRCA_USERS_DN_SUFFIX, encoding="ISO-8859-1") legacy_db.perform_bind(config['legacy_admin_dn'], config['legacy_admin_pw']) db = DualLDAPProxy(db, legacy_db) return db
def ldap_agent_with_config(config, bind=False, secondary=False): db = UsersDB(ldap_server=config['ldap_server'], # next is for bwd compat with objects created with v1.0.0 users_rdn=config.get('users_rdn', defaults['users_rdn']), users_dn=config['users_dn'], orgs_dn=config['orgs_dn'], roles_dn=config['roles_dn']) if bind: if secondary: db.perform_bind(config['secondary_admin_dn'], config['secondary_admin_pw']) else: db.perform_bind(config['admin_dn'], config['admin_pw']) legacy_ldap_server = config.get('legacy_ldap_server', None) if legacy_ldap_server: from eea.userseditor.users_editor import ( CircaUsersDB, CIRCA_USERS_DN_SUFFIX, DualLDAPProxy) legacy_db = CircaUsersDB(ldap_server=legacy_ldap_server, users_dn=CIRCA_USERS_DN_SUFFIX, encoding="ISO-8859-1") legacy_db.perform_bind(config['legacy_admin_dn'], config['legacy_admin_pw']) db = DualLDAPProxy(db, legacy_db) return db
def get_ldap_groups(user_id): app = flask.current_app ldap_server = urlparse.urlsplit(app.config['LDAP_SERVER']).netloc udb = UsersDB(ldap_server=ldap_server) return [r for r, _info in udb.member_roles_info('user', user_id)]