Search in sources :

Example 6 with ServerGroup

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();
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) Server(com.iplanet.services.ldap.Server) LDAPURL(org.forgerock.openam.ldap.LDAPURL) ServerInstance(com.iplanet.services.ldap.ServerInstance) Test(org.testng.annotations.Test)

Example 7 with ServerGroup

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);
    }
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) IOutput(com.sun.identity.cli.IOutput) Connection(org.forgerock.opendj.ldap.Connection) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) CLIException(com.sun.identity.cli.CLIException) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 8 with ServerGroup

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;
}
Also used : ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) ServerGroup(com.iplanet.services.ldap.ServerGroup) SSOToken(com.iplanet.sso.SSOToken) DebugPropertiesObserver(com.sun.identity.common.DebugPropertiesObserver) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) SystemProperties(com.iplanet.am.util.SystemProperties) Properties(java.util.Properties)

Example 9 with ServerGroup

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);
}
Also used : ServerConfigurationNotFound(org.forgerock.openam.sm.exceptions.ServerConfigurationNotFound) ServerGroup(com.iplanet.services.ldap.ServerGroup) ServerInstance(com.iplanet.services.ldap.ServerInstance) ConnectionCredentialsNotFound(org.forgerock.openam.sm.exceptions.ConnectionCredentialsNotFound)

Example 10 with ServerGroup

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());
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) Server(com.iplanet.services.ldap.Server) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException)

Aggregations

ServerGroup (com.iplanet.services.ldap.ServerGroup)16 ServerInstance (com.iplanet.services.ldap.ServerInstance)11 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)8 Test (org.testng.annotations.Test)8 Server (com.iplanet.services.ldap.Server)6 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)4 ServerConfigurationFactory (org.forgerock.openam.sm.ServerConfigurationFactory)3 SystemProperties (com.iplanet.am.util.SystemProperties)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 MBeanServer (javax.management.MBeanServer)2 LDAPURL (org.forgerock.openam.ldap.LDAPURL)2 Connection (org.forgerock.opendj.ldap.Connection)2 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)2 Matchers.anyString (org.mockito.Matchers.anyString)2 SSOToken (com.iplanet.sso.SSOToken)1 CLIException (com.sun.identity.cli.CLIException)1 IOutput (com.sun.identity.cli.IOutput)1