Search in sources :

Example 1 with DebugPropertiesObserver

use of com.sun.identity.common.DebugPropertiesObserver 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)

Aggregations

SystemProperties (com.iplanet.am.util.SystemProperties)1 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)1 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 ServerGroup (com.iplanet.services.ldap.ServerGroup)1 SSOToken (com.iplanet.sso.SSOToken)1 DebugPropertiesObserver (com.sun.identity.common.DebugPropertiesObserver)1 SMSException (com.sun.identity.sm.SMSException)1 Properties (java.util.Properties)1 Connection (org.forgerock.opendj.ldap.Connection)1 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)1