use of com.iplanet.services.ldap.ServerGroup 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.ServerGroup in project OpenAM by OpenRock.
the class ImportServiceConfiguration method getLDAPConnection.
private Connection getLDAPConnection() throws CLIException {
IOutput outputWriter = getOutputWriter();
if (isVerbose()) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-connecting-to-ds"));
}
try {
Connection conn;
DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
ServerGroup sg = dsCfg.getServerGroup("sms");
if (sg != null) {
conn = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN).getConnection();
} else {
throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
}
if (isVerbose()) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-connected-to-ds"));
}
return conn;
} catch (LDAPServiceException | LdapException e) {
throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
}
}
use of com.iplanet.services.ldap.ServerGroup in project OpenAM by OpenRock.
the class Bootstrap method getConfiguration.
/**
* Returns System Property with an URL.
*
* @param bootstrapData an URL that contains information on how to
* fetch the server configuration properties.
* @param reinit <code>true</code> to re initialize the system.
* @throws Exception if properties cannot be loaded.
*/
private static Properties getConfiguration(BootstrapData bootstrapData, boolean reinit, boolean bStartDS) throws Exception {
Properties properties = null;
bootstrapData.initSMS(bStartDS);
if (reinit) {
AdminUtils.initialize();
SMSAuthModule.initialize();
}
DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
ServerGroup sg = dsCfg.getServerGroup("sms");
if (sg == null) {
return null;
}
try (ConnectionFactory factory = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN);
Connection conn = factory.getConnection()) {
// Success case. Managed to get connection
} catch (LDAPServiceException e) {
// ignore, DS is down
return null;
}
String dsbasedn = bootstrapData.getUserBaseDN();
String pwd = bootstrapData.getDsameUserPassword();
String dsameUser = "cn=dsameuser,ou=DSAME Users," + dsbasedn;
String instanceName = bootstrapData.getInstanceName();
SSOToken ssoToken = getSSOToken(dsbasedn, dsameUser, JCECrypt.decode(pwd));
try {
properties = ServerConfiguration.getServerInstance(ssoToken, instanceName);
if (properties != null) {
// set debug level to error because debug.message in
// SMSEntry.initializedClass won't work and will print out
// error message. Save the debug level and will be restored
// after SMSEntry.initializedClass.
String debugLevel = (String) properties.get(Constants.SERVICES_DEBUG_LEVEL);
boolean debugSetAtDefault = false;
if (debugLevel == null) {
debugSetAtDefault = true;
}
properties.setProperty(Constants.SERVICES_DEBUG_LEVEL, Debug.STR_ERROR);
SystemProperties.initializeProperties(properties, true, false);
DebugPropertiesObserver debugPO = DebugPropertiesObserver.getInstance();
String serverConfigXML = ServerConfiguration.getServerConfigXML(ssoToken, instanceName);
Crypt.reinitialize();
BootstrapData.loadServerConfigXML(serverConfigXML);
SMSEntry.initializeClass();
if (debugSetAtDefault) {
properties.remove(Constants.SERVICES_DEBUG_LEVEL);
} else {
properties.setProperty(Constants.SERVICES_DEBUG_LEVEL, debugLevel);
}
SystemProperties.initializeProperties(properties, true, true);
String defaultDebugLevel = SystemProperties.getProperties().getProperty(Constants.SERVICES_DEBUG_LEVEL);
if (debugSetAtDefault) {
properties.setProperty(Constants.SERVICES_DEBUG_LEVEL, defaultDebugLevel);
SystemProperties.initializeProperties(properties, true, true);
}
AdminUtils.initialize();
SMSAuthModule.initialize();
debugPO.notifyChanges();
SMSPropertiesObserver.getInstance().notifyChanges();
SystemProperties.setServerInstanceName(instanceName);
// ConfigurationObserver is already added when
// DebugPropertiesObserver.getInstance().notifyChanges();
// is called. Adding again causes 2 notification events
// to be sent.
// ServiceConfigManager scm = new ServiceConfigManager(
// Constants.SVC_NAME_PLATFORM, (SSOToken)
// AccessController.doPrivileged(
// AdminTokenAction.getInstance()));
// scm.addListener(ConfigurationObserver.getInstance());
}
} catch (SMSException e) {
//ignore. product is not configured yet.
System.out.println("Bootstrap.getConfiguration :" + e);
properties = null;
}
return properties;
}
use of com.iplanet.services.ldap.ServerGroup 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);
}
use of com.iplanet.services.ldap.ServerGroup in project OpenAM by OpenRock.
the class UpgradeHttpServletRequest method initialize.
private void initialize(String baseDir) throws UpgradeException {
parameters.put(SetupConstants.CONFIG_VAR_DATA_STORE, EmbeddedOpenDS.isStarted() ? SetupConstants.SMS_EMBED_DATASTORE : SetupConstants.SMS_DS_DATASTORE);
parameters.put(SetupConstants.CONFIG_VAR_BASE_DIR, baseDir);
parameters.put(SetupConstants.CONFIG_VAR_SERVER_URI, getContextPath());
parameters.put(SetupConstants.CONFIG_VAR_SERVER_URL, getServerURL());
//workaround for ServicesDefaultValues#validatePassword
parameters.put(SetupConstants.CONFIG_VAR_DS_MGR_PWD, "********");
parameters.put(SetupConstants.CONFIG_VAR_ADMIN_PWD, "********");
parameters.put(SetupConstants.CONFIG_VAR_CONFIRM_ADMIN_PWD, "********");
parameters.put(SetupConstants.CONFIG_VAR_AMLDAPUSERPASSWD, "********!");
parameters.put(SetupConstants.CONFIG_VAR_AMLDAPUSERPASSWD_CONFIRM, "********!");
parameters.put(SetupConstants.CONFIG_VAR_SERVER_HOST, SystemProperties.get(Constants.AM_SERVER_HOST));
try {
ServerGroup sg = DSConfigMgr.getDSConfigMgr().getServerGroup("sms");
Server server = (Server) sg.getServersList().iterator().next();
parameters.put(SetupConstants.CONFIG_VAR_DIRECTORY_SERVER_HOST, server.getServerName());
parameters.put(SetupConstants.CONFIG_VAR_DIRECTORY_SERVER_PORT, Integer.toString(server.getPort()));
parameters.put(SetupConstants.CONFIG_VAR_DIRECTORY_SERVER_SSL, server.getConnectionType().toString());
} catch (LDAPServiceException ldapse) {
UpgradeUtils.debug.error("Unable to get SMS LDAP configuration!");
throw new UpgradeException(ldapse);
}
parameters.put(SetupConstants.CONFIG_VAR_ROOT_SUFFIX, SMSEntry.getRootSuffix());
}
Aggregations