8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
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 * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
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 * $Id: Bootstrap.java,v 1.18 2009/05/13 21:26:36 hengming Exp $
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington * Portions Copyrighted 2011-2015 ForgeRock AS.
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunningtonimport static org.forgerock.openam.utils.IOUtils.writeToFile;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport javax.security.auth.login.LoginException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.LDAPServiceException;
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;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSPropertiesObserver;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.Connection;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.ConnectionFactory;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class is responsible for bootstrapping the WAR.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Directory where bootstrap file resides.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String JVM_OPT_BOOTSTRAP = "bootstrap.dir";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Loads System Property with the bootstrap file that is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * found in <code>JVM_OPT_BOOTSTRAP</code> stated directory.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if properties cannot be loaded.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String basedir = System.getProperty(JVM_OPT_BOOTSTRAP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.initializeProperties("com.iplanet.am.naming.url",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.getServerInstanceName() + "/namingservice");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Loads System Property with the bootstrap file that is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * found in a directory.
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 public static Properties load(String basedir, boolean bServer)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster InputStream propIn = new FileInputStream(amConfigProperties);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BootstrapData bData = new BootstrapData(basedir);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static boolean load(BootstrapData bootstrap, boolean reinit)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean configured = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns <code>true</code> if able to bootstrap the system.
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 public static boolean bootstrap(BootstrapData bootstrapInfo, boolean reinit)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (getConfiguration(bootstrapInfo, reinit, true) != null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns System Property with an URL.
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 DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
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 // ignore, DS is down
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();
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington SSOToken ssoToken = getSSOToken(dsbasedn, dsameUser,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties = ServerConfiguration.getServerInstance(
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 boolean debugSetAtDefault = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties.setProperty(Constants.SERVICES_DEBUG_LEVEL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties, true, false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BootstrapData.loadServerConfigXML(serverConfigXML);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties.remove(Constants.SERVICES_DEBUG_LEVEL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties.setProperty(Constants.SERVICES_DEBUG_LEVEL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.getProperties().getProperty(Constants.SERVICES_DEBUG_LEVEL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster properties.setProperty(Constants.SERVICES_DEBUG_LEVEL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSPropertiesObserver.getInstance().notifyChanges();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.setServerInstanceName(instanceName);
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 //ignore. product is not configured yet.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Bootstrap.getConfiguration :" + e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws LoginException, InvalidAuthContextException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthPrincipal principal = new AuthPrincipal(bindUser);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ac.getLoginStatus() == AuthContext.AUTH_SUCCESS) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //No handling requried
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Modifies the <code>dsameuser</code> password in bootstrap file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param password New Password.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if modification fails.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void modifyDSAMEUserPassword(String password)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String bootstrapFile = baseDir + "/" + AMSetupServlet.BOOTSTRAP_EXTRA;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator i = urls.iterator(); i.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buff.append(modifyDSAMEUserPassword(url, password)).append("\n");
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington writeToFile(bootstrapFile, buff.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String modifyDSAMEUserPassword(String url, String password)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int start = url.indexOf("&" + BootstrapData.PWD + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster start = url.indexOf("?" + BootstrapData.PWD + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster url = url.substring(0, start + 5) + encPassword;