cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: Bootstrap.java,v 1.18 2009/05/13 21:26:36 hengming Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington * Portions Copyrighted 2011-2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.setup;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunningtonimport static org.forgerock.openam.utils.IOUtils.writeToFile;
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport javax.security.auth.login.LoginException;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.io.BufferedReader;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.io.File;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.io.FileInputStream;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.io.FileReader;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.io.IOException;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.io.InputStream;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.net.URLEncoder;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.ArrayList;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.Iterator;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.List;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.Locale;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.Properties;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.util.AdminUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.util.SystemProperties;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.DSConfigMgr;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.LDAPServiceException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.LDAPUser;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.ServerGroup;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.util.Crypt;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOToken;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.internal.AuthContext;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.internal.AuthPrincipal;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.internal.InvalidAuthContextException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.internal.server.SMSAuthModule;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.DebugPropertiesObserver;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.configuration.ServerConfiguration;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport com.sun.identity.shared.Constants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSEntry;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSPropertiesObserver;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.Connection;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.ConnectionFactory;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class is responsible for bootstrapping the WAR.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class Bootstrap {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Directory where bootstrap file resides.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String JVM_OPT_BOOTSTRAP = "bootstrap.dir";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean isBootstrap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Bootstrap() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Loads System Property with the bootstrap file that is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * found in <code>JVM_OPT_BOOTSTRAP</code> stated directory.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if properties cannot be loaded.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public synchronized static void load()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!isBootstrap) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String basedir = System.getProperty(JVM_OPT_BOOTSTRAP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (load(basedir, false) == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "configurator.cannot.bootstrap", null,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Locale.getDefault());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.initializeProperties("com.iplanet.am.naming.url",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.getServerInstanceName() + "/namingservice");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Loads System Property with the bootstrap file that is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * found in a directory.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param basedir Directory where bootstrap file resides.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * bootstrap file can contain either an URL where
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * we can go fetch the server configuration properties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * or a file that contains the properties.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param bServer <code>true</code> if server.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if properties cannot be loaded.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static Properties load(String basedir, boolean bServer)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!basedir.endsWith(File.separator)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster basedir = basedir + File.separator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Properties prop = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String amConfigProperties = basedir +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.AMCONFIG_PROPERTIES;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster File file = new File(amConfigProperties);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (file.exists()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster prop = new Properties();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster InputStream propIn = new FileInputStream(amConfigProperties);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster prop.load(propIn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } finally {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster propIn.close();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.initializeProperties(prop);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster isBootstrap = true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BootstrapData bData = new BootstrapData(basedir);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster prop = getConfiguration(bData, true, bServer);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return prop;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static boolean load(BootstrapData bootstrap, boolean reinit)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean configured = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (bootstrap != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster configured = bootstrap(bootstrap, reinit);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster isBootstrap = true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return configured;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns <code>true</code> if able to bootstrap the system.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param bootstrapInfo object that contains information on how to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * fetch the server configuration properties.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param reinit <code>true</code> to re initialize the system.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if there are errors in bootstrapping.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static boolean bootstrap(BootstrapData bootstrapInfo, boolean reinit)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (getConfiguration(bootstrapInfo, reinit, true) != null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns System Property with an URL.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
aee26cce86cd7acccbcd94284b027d11cb9ac327jeff.schenk * @param bootstrapData an URL that contains information on how to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * fetch the server configuration properties.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param reinit <code>true</code> to re initialize the system.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if properties cannot be loaded.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Properties getConfiguration(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BootstrapData bootstrapData,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean reinit,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean bStartDS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Properties properties = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster bootstrapData.initSMS(bStartDS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (reinit) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AdminUtils.initialize();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSAuthModule.initialize();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServerGroup sg = dsCfg.getServerGroup("sms");
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington if (sg == null) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington try (ConnectionFactory factory = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington Connection conn = factory.getConnection()) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington // Success case. Managed to get connection
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington } catch (LDAPServiceException e) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington // ignore, DS is down
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dsbasedn = bootstrapData.getUserBaseDN();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String pwd = bootstrapData.getDsameUserPassword();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dsameUser = "cn=dsameuser,ou=DSAME Users," + dsbasedn;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String instanceName = bootstrapData.getInstanceName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington SSOToken ssoToken = getSSOToken(dsbasedn, dsameUser,
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington JCECrypt.decode(pwd));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties = ServerConfiguration.getServerInstance(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ssoToken, instanceName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (properties != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // set debug level to error because debug.message in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // SMSEntry.initializedClass won't work and will print out
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // error message. Save the debug level and will be restored
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // after SMSEntry.initializedClass.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String debugLevel = (String)properties.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Constants.SERVICES_DEBUG_LEVEL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean debugSetAtDefault = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debugLevel == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debugSetAtDefault = true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties.setProperty(Constants.SERVICES_DEBUG_LEVEL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.STR_ERROR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.initializeProperties(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties, true, false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DebugPropertiesObserver debugPO =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DebugPropertiesObserver.getInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String serverConfigXML =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServerConfiguration.getServerConfigXML(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ssoToken, instanceName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Crypt.reinitialize();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BootstrapData.loadServerConfigXML(serverConfigXML);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSEntry.initializeClass();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debugSetAtDefault) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties.remove(Constants.SERVICES_DEBUG_LEVEL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties.setProperty(Constants.SERVICES_DEBUG_LEVEL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debugLevel);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.initializeProperties(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties, true, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String defaultDebugLevel =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.getProperties().getProperty(Constants.SERVICES_DEBUG_LEVEL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debugSetAtDefault) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties.setProperty(Constants.SERVICES_DEBUG_LEVEL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster defaultDebugLevel);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.initializeProperties(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties, true, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AdminUtils.initialize();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSAuthModule.initialize();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debugPO.notifyChanges();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSPropertiesObserver.getInstance().notifyChanges();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.setServerInstanceName(instanceName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // ConfigurationObserver is already added when
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // DebugPropertiesObserver.getInstance().notifyChanges();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // is called. Adding again causes 2 notification events
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // to be sent.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // ServiceConfigManager scm = new ServiceConfigManager(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Constants.SVC_NAME_PLATFORM, (SSOToken)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // AccessController.doPrivileged(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // AdminTokenAction.getInstance()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // scm.addListener(ConfigurationObserver.getInstance());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SMSException e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //ignore. product is not configured yet.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Bootstrap.getConfiguration :" + e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return properties;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static SSOToken getSSOToken(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String basedn,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String bindUser,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String bindPwd
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws LoginException, InvalidAuthContextException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOToken ssoToken = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthPrincipal principal = new AuthPrincipal(bindUser);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthContext ac = new AuthContext(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster basedn, principal, bindPwd.toCharArray());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ac.getLoginStatus() == AuthContext.AUTH_SUCCESS) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ssoToken = ac.getSSOToken();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ssoToken;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static List readFile(String file)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws IOException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster List list = new ArrayList();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BufferedReader in = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String str = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster in = new BufferedReader(new FileReader(file));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (in.ready()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster str = in.readLine();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (str != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster list.add(str);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster str = in.readLine();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } finally {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (in != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster in.close();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //No handling requried
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return list;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Modifies the <code>dsameuser</code> password in bootstrap file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param password New Password.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if modification fails.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void modifyDSAMEUserPassword(String password)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws IOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String bootstrapFile = baseDir + "/" + AMSetupServlet.BOOTSTRAP_EXTRA;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster List urls = readFile(bootstrapFile);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder buff = new StringBuilder();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator i = urls.iterator(); i.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String url = (String)i.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buff.append(modifyDSAMEUserPassword(url, password)).append("\n");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington writeToFile(bootstrapFile, buff.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String modifyDSAMEUserPassword(String url, String password)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws IOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int start = url.indexOf("&" + BootstrapData.PWD + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (start == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster start = url.indexOf("?" + BootstrapData.PWD + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (start != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String encPassword = URLEncoder.encode(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster JCECrypt.encode(password), "UTF-8");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int end = url.indexOf("&", start+1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (end == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster url = url.substring(0, start + 5) + encPassword;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster url = url.substring(0, start + 5) + encPassword +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster url.substring(end);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return url;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}