LdapGroupsMapping implements GroupMappingServiceProvider, Configurable { @Override public synchronized void setConf(Configuration conf) { this.conf = conf; String[] urls = conf.getStrings(LDAP_URL_KEY, LDAP_URL_DEFAULT); if (urls == null || urls.length == 0) { throw new RuntimeException("LDAP URL(s) are not configured"); } ldapUrls = Iterators.cycle(urls); currentLdapUrl = ldapUrls.next(); useSsl = conf.getBoolean(LDAP_USE_SSL_KEY, LDAP_USE_SSL_DEFAULT); if (useSsl) { loadSslConf(conf); } initializeBindUsers(); String baseDN = conf.getTrimmed(BASE_DN_KEY, BASE_DN_DEFAULT); userbaseDN = conf.getTrimmed(USER_BASE_DN_KEY, baseDN); LOG.debug("Usersearch baseDN: {}", userbaseDN); groupbaseDN = conf.getTrimmed(GROUP_BASE_DN_KEY, baseDN); LOG.debug("Groupsearch baseDN: {}", groupbaseDN); groupSearchFilter = conf.get(GROUP_SEARCH_FILTER_KEY, GROUP_SEARCH_FILTER_DEFAULT); userSearchFilter = conf.get(USER_SEARCH_FILTER_KEY, USER_SEARCH_FILTER_DEFAULT); isPosix = groupSearchFilter.contains(POSIX_GROUP) && userSearchFilter .contains(POSIX_ACCOUNT); memberOfAttr = conf.get(MEMBEROF_ATTR_KEY, MEMBEROF_ATTR_DEFAULT); useOneQuery = !memberOfAttr.isEmpty(); groupMemberAttr = conf.get(GROUP_MEMBERSHIP_ATTR_KEY, GROUP_MEMBERSHIP_ATTR_DEFAULT); groupNameAttr = conf.get(GROUP_NAME_ATTR_KEY, GROUP_NAME_ATTR_DEFAULT); groupHierarchyLevels = conf.getInt(GROUP_HIERARCHY_LEVELS_KEY, GROUP_HIERARCHY_LEVELS_DEFAULT); posixUidAttr = conf.get(POSIX_UID_ATTR_KEY, POSIX_UID_ATTR_DEFAULT); posixGidAttr = conf.get(POSIX_GID_ATTR_KEY, POSIX_GID_ATTR_DEFAULT); int dirSearchTimeout = conf.getInt(DIRECTORY_SEARCH_TIMEOUT, DIRECTORY_SEARCH_TIMEOUT_DEFAULT); SEARCH_CONTROLS.setTimeLimit(dirSearchTimeout); String[] returningAttributes; if (useOneQuery) { returningAttributes = new String[] { groupNameAttr, posixUidAttr, posixGidAttr, memberOfAttr}; } else { returningAttributes = new String[] { groupNameAttr, posixUidAttr, posixGidAttr}; } SEARCH_CONTROLS.setReturningAttributes(returningAttributes); Class<? extends InitialContextFactory> ldapCtxFactoryClass = conf.getClass(LDAP_CTX_FACTORY_CLASS_KEY, null, InitialContextFactory.class); if (ldapCtxFactoryClass != null) { ldapCtxFactoryClassName = ldapCtxFactoryClass.getName(); } else { ldapCtxFactoryClassName = LDAP_CTX_FACTORY_CLASS_DEFAULT; } this.numAttempts = conf.getInt(LDAP_NUM_ATTEMPTS_KEY, LDAP_NUM_ATTEMPTS_DEFAULT); this.numAttemptsBeforeFailover = conf.getInt( LDAP_NUM_ATTEMPTS_BEFORE_FAILOVER_KEY, LDAP_NUM_ATTEMPTS_BEFORE_FAILOVER_DEFAULT); }  @Override synchronized List<String> getGroups(String user); @Override void cacheGroupsRefresh(); @Override void cacheGroupsAdd(List<String> groups); @Override Set<String> getGroupsSet(String user); @Override synchronized Configuration getConf(); @Override synchronized void setConf(Configuration conf); Iterator<String> getLdapUrls(); static final String LDAP_CONFIG_PREFIX; static final String LDAP_URL_KEY; static final String LDAP_URL_DEFAULT; static final String LDAP_USE_SSL_KEY; static final Boolean LDAP_USE_SSL_DEFAULT; static final String LDAP_KEYSTORE_KEY; static final String LDAP_KEYSTORE_DEFAULT; static final String LDAP_KEYSTORE_PASSWORD_KEY; static final String LDAP_KEYSTORE_PASSWORD_DEFAULT; static final String LDAP_KEYSTORE_PASSWORD_FILE_KEY; static final String LDAP_KEYSTORE_PASSWORD_FILE_DEFAULT; static final String LDAP_TRUSTSTORE_KEY; static final String LDAP_TRUSTSTORE_PASSWORD_KEY; static final String LDAP_TRUSTSTORE_PASSWORD_FILE_KEY; static final String BIND_USERS_KEY; static final String BIND_USER_SUFFIX; static final String BIND_USER_KEY; static final String BIND_USER_DEFAULT; static final String BIND_PASSWORD_SUFFIX; static final String BIND_PASSWORD_KEY; static final String BIND_PASSWORD_DEFAULT; static final String BIND_PASSWORD_FILE_SUFFIX; static final String BIND_PASSWORD_FILE_KEY; static final String BIND_PASSWORD_FILE_DEFAULT; static final String BIND_PASSWORD_ALIAS_SUFFIX; static final String BIND_PASSWORD_ALIAS_KEY; static final String BIND_PASSWORD_ALIAS_DEFAULT; static final String BASE_DN_KEY; static final String BASE_DN_DEFAULT; static final String USER_BASE_DN_KEY; static final String GROUP_BASE_DN_KEY; static final String USER_SEARCH_FILTER_KEY; static final String USER_SEARCH_FILTER_DEFAULT; static final String GROUP_SEARCH_FILTER_KEY; static final String GROUP_SEARCH_FILTER_DEFAULT; static final String MEMBEROF_ATTR_KEY; static final String MEMBEROF_ATTR_DEFAULT; static final String GROUP_MEMBERSHIP_ATTR_KEY; static final String GROUP_MEMBERSHIP_ATTR_DEFAULT; static final String GROUP_NAME_ATTR_KEY; static final String GROUP_NAME_ATTR_DEFAULT; static final String GROUP_HIERARCHY_LEVELS_KEY; static final int GROUP_HIERARCHY_LEVELS_DEFAULT; static final String POSIX_UID_ATTR_KEY; static final String POSIX_UID_ATTR_DEFAULT; static final String POSIX_GID_ATTR_KEY; static final String POSIX_GID_ATTR_DEFAULT; static final String POSIX_GROUP; static final String POSIX_ACCOUNT; static final String DIRECTORY_SEARCH_TIMEOUT; static final int DIRECTORY_SEARCH_TIMEOUT_DEFAULT; static final String CONNECTION_TIMEOUT; static final int CONNECTION_TIMEOUT_DEFAULT; static final String READ_TIMEOUT; static final int READ_TIMEOUT_DEFAULT; static final String LDAP_NUM_ATTEMPTS_KEY; static final int LDAP_NUM_ATTEMPTS_DEFAULT; static final String LDAP_NUM_ATTEMPTS_BEFORE_FAILOVER_KEY; static final int LDAP_NUM_ATTEMPTS_BEFORE_FAILOVER_DEFAULT; static final String LDAP_CTX_FACTORY_CLASS_KEY; static final String LDAP_CTX_FACTORY_CLASS_DEFAULT; }
@Test(timeout = 10000) public void testSetConf() throws Exception { Configuration conf = getBaseConf(TEST_LDAP_URL); Configuration mockConf = Mockito.spy(conf); when(mockConf.getPassword(anyString())) .thenThrow(new IOException("injected IOException")); LdapGroupsMapping groupsMapping = getGroupsMapping(); groupsMapping.setConf(mockConf); }