use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.
the class ServerGroupConfigurationTest method shouldReturnCorrectLDAPURLforSimpleConnections.
@Test
public void shouldReturnCorrectLDAPURLforSimpleConnections() {
// Given
String hostName = "localhost";
int port = 389;
Server one = mock(Server.class);
given(one.getServerName()).willReturn(hostName);
given(one.getPort()).willReturn(port);
given(one.getConnectionType()).willReturn(Server.Type.CONN_SIMPLE);
ServerInstance mockInstance = mock(ServerInstance.class);
ServerGroup mockGroup = mock(ServerGroup.class);
given(mockGroup.getServersList()).willReturn(Arrays.asList(one));
ServerGroupConfiguration config = new ServerGroupConfiguration(mockGroup, mockInstance);
// When
Set<LDAPURL> result = config.getLDAPURLs();
// Then
assertThat(result).hasSize(1);
LDAPURL url = result.iterator().next();
assertThat(url.getHost()).isEqualTo(hostName);
assertThat(url.getPort()).isEqualTo(port);
assertThat(url.isSSL()).isFalse();
}
use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.
the class AdminUtils method initialize.
public static void initialize() {
debug = Debug.getInstance(IUMSConstants.UMS_DEBUG);
try {
DSConfigMgr dscMgr = DSConfigMgr.getDSConfigMgr();
ServerInstance svrInstance = dscMgr.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
if (svrInstance != null) {
adminDN = svrInstance.getAuthID();
String adminPW = (String) AccessController.doPrivileged(new ServerInstanceAction(svrInstance));
adminPassword = xor(adminPW.getBytes());
} else {
debug.error("AdminUtils.initialize: server instance not found");
}
} catch (LDAPServiceException e) {
if (SystemProperties.isServerMode()) {
debug.error("AdminUtils.initialize: Initialize admin info ", e);
} else if (debug.messageEnabled()) {
debug.message("AdminUtilsinitialize: Could not initialize admin info message:" + e.getMessage());
}
}
}
use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.
the class LocalLdapAuthModule method authenticate.
private boolean authenticate(String dn, String passwd) throws LoginException {
// LDAP connection used for authentication
Connection localConn = null;
String host;
int port;
Options ldapOptions = Options.defaultOptions();
// Check if organization is present in options
String orgUrl = (String) options.get(LoginContext.ORGNAME);
if ((orgUrl == null) || (orgUrl.equals(LoginContext.LDAP_AUTH_URL)) || (orgUrl.equals(LoginContext.LDAPS_AUTH_URL)) || !(orgUrl.startsWith(LoginContext.LDAP_AUTH_URL) || orgUrl.startsWith(LoginContext.LDAPS_AUTH_URL))) {
try {
DSConfigMgr dscm = DSConfigMgr.getDSConfigMgr();
// We need a handle on server instance so we can know the
// Connection type. If it is SSL, the connection needs to be
// accordingly created. Note: The user type does not make
// a difference, as the connection type is Server group based,
// so passing any user type for the second argument.
ServerInstance si = dscm.getServerInstance(DSConfigMgr.DEFAULT, LDAPUser.Type.AUTH_BASIC);
String hostName = dscm.getHostName(DSConfigMgr.DEFAULT);
if (si.getConnectionType() == Server.Type.CONN_SSL) {
try {
ldapOptions.set(LDAPConnectionFactory.SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
} catch (GeneralSecurityException e) {
debug.error("getConnection.JSSESocketFactory", e);
throw new LDAPServiceException(AuthI18n.authI18n.getString(IUMSConstants.DSCFG_JSSSFFAIL));
}
}
if (dn != null && passwd != null) {
// The 389 port number passed is overridden by the
// hostName:port
// constructed by the getHostName method. So, this is not
// a hardcoded port number.
host = hostName;
port = 389;
} else {
// Throw LoginException
throw new LoginException(AuthI18n.authI18n.getString(IUMSConstants.DSCFG_CONNECTFAIL));
}
} catch (LDAPServiceException ex) {
debug.error("Authenticate failed: " + ex);
throw new LoginException(ex.getMessage());
}
} else {
try {
if (debug.messageEnabled()) {
debug.message("authenticate(): orgUrl= " + orgUrl);
}
// Get hostname
int start;
boolean useSSL = false;
if (orgUrl.startsWith(LoginContext.LDAPS_AUTH_URL)) {
start = LoginContext.LDAPS_AUTH_URL.length();
useSSL = true;
} else {
start = LoginContext.LDAP_AUTH_URL.length();
}
int end = orgUrl.indexOf(':', start);
if (end == -1) {
end = orgUrl.indexOf('/', start);
if (end == -1)
end = orgUrl.length();
}
String hostName = orgUrl.substring(start, end);
// Get port number
String portNumber = "389";
start = end + 1;
if (start < orgUrl.length()) {
end = orgUrl.indexOf('/', start);
if (end == -1)
end = orgUrl.length();
portNumber = orgUrl.substring(start, end);
}
if (useSSL) {
try {
ldapOptions.set(LDAPConnectionFactory.SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
} catch (GeneralSecurityException e) {
debug.error("authentication().JSSESocketFactory()", e);
throw (new LoginException(e.getMessage()));
}
}
if (debug.messageEnabled()) {
debug.message("before connect(), hostName=" + hostName + ",port=" + portNumber);
}
host = hostName;
port = Integer.parseInt(portNumber);
} catch (Exception e) {
debug.error("authentication", e);
throw (new LoginException(e.getMessage()));
}
}
try (ConnectionFactory factory = LDAPUtils.createFailoverConnectionFactory(host, port, dn, passwd, ldapOptions);
Connection conn = factory.getConnection()) {
return true;
} catch (LdapException e) {
throw new LoginException(e.getMessage());
}
}
use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.
the class LocalLdapAuthModule method readServerConfig.
private void readServerConfig() throws LoginException {
if (readServerConfiguration)
return;
try {
DSConfigMgr cfgMgr = DSConfigMgr.getDSConfigMgr();
conn = cfgMgr.getNewBasicConnectionFactory().getConnection();
ServerInstance si = cfgMgr.getServerInstance(DSConfigMgr.DEFAULT, LDAPUser.Type.AUTH_BASIC);
baseDN = si.getBaseDN();
readServerConfiguration = true;
} catch (LDAPServiceException | LdapException ex) {
throw new LoginException(ex.getMessage());
}
}
use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.
the class ServerConfigurationFactory method getServerConfiguration.
/**
* Select the Server Group from the configuration.
*
* If the server group is valid then this ServerConfigurationFactory will select
* the Server Group and Instance for subsequent calls.
*
* @param groupName The name of the server group. For example: "default" or "sms".
* @param authType The type of connection credentials that should be selected.
*
* @throws IllegalStateException If the Server Configuration did not exist for the
* named Server Group or the Server Group did not have credentials for the requested
* connection type.
*/
public ServerGroupConfiguration getServerConfiguration(String groupName, LDAPUser.Type authType) throws ServerConfigurationNotFound, ConnectionCredentialsNotFound {
ServerGroup serverGroup = config.getServerGroup(groupName);
ServerInstance instance = config.getServerInstance(groupName, authType);
if (serverGroup == null) {
throw new ServerConfigurationNotFound(groupName);
}
if (instance == null) {
throw new ConnectionCredentialsNotFound(authType);
}
return new ServerGroupConfiguration(serverGroup, instance);
}
Aggregations