LdapGroupsMapping implements GroupMappingServiceProvider, Configurable { @Override public synchronized void setConf(Configuration conf) { ldapUrl = conf.get(LDAP_URL_KEY, LDAP_URL_DEFAULT); if (ldapUrl == null || ldapUrl.isEmpty()) { throw new RuntimeException("LDAP URL is not configured"); } useSsl = conf.getBoolean(LDAP_USE_SSL_KEY, LDAP_USE_SSL_DEFAULT); if (useSsl) { loadSslConf(conf); } bindUser = conf.get(BIND_USER_KEY, BIND_USER_DEFAULT); bindPassword = getPassword(conf, BIND_PASSWORD_KEY, BIND_PASSWORD_DEFAULT); if (bindPassword.isEmpty()) { bindPassword = extractPassword( conf.get(BIND_PASSWORD_FILE_KEY, BIND_PASSWORD_FILE_DEFAULT)); } String baseDN = conf.getTrimmed(BASE_DN_KEY, BASE_DN_DEFAULT); userbaseDN = conf.getTrimmed(USER_BASE_DN_KEY, baseDN); if (LOG.isDebugEnabled()) { LOG.debug("Usersearch baseDN: " + userbaseDN); } groupbaseDN = conf.getTrimmed(GROUP_BASE_DN_KEY, baseDN); if (LOG.isDebugEnabled()) { LOG.debug("Groupsearch baseDN: " + userbaseDN); } 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); this.conf = conf; }  @Override synchronized List<String> getGroups(String user); @Override void cacheGroupsRefresh(); @Override void cacheGroupsAdd(List<String> groups); @Override synchronized Configuration getConf(); @Override synchronized void setConf(Configuration conf); 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_USER_KEY; static final String BIND_USER_DEFAULT; static final String BIND_PASSWORD_KEY; static final String BIND_PASSWORD_DEFAULT; static final String BIND_PASSWORD_FILE_KEY; static final String BIND_PASSWORD_FILE_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 int RECONNECT_RETRY_COUNT; }
@Test(timeout = 10000) public void testSetConf() throws Exception { Configuration conf = new Configuration(); Configuration mockConf = Mockito.spy(conf); when(mockConf.getPassword(anyString())) .thenThrow(new IOException("injected IOException")); mockConf.set(LdapGroupsMapping.LDAP_URL_KEY, "ldap: LdapGroupsMapping groupsMapping = getGroupsMapping(); groupsMapping.setConf(mockConf); }