cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2006 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: ServicesDefaultValues.java,v 1.38 2009/01/28 05:35:02 ww203982 Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott * Portions Copyrighted 2013-2016 ForgeRock AS.
44a62998f373c4089cb2e6b478cdb5e7ac71ccaeAlin Brici */
44a62998f373c4089cb2e6b478cdb5e7ac71ccaeAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.setup;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.net.MalformedURLException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.net.URL;
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshottimport java.security.SecureRandom;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Enumeration;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Locale;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.ResourceBundle;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshottimport org.forgerock.openam.ldap.LDAPUtils;
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshottimport org.forgerock.openam.utils.ValidateIPaddress;
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshottimport org.forgerock.opendj.ldap.DN;
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshottimport com.iplanet.am.util.SecureRandomManager;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport com.iplanet.am.util.SystemProperties;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport com.iplanet.services.util.Crypt;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport com.sun.identity.common.DNUtils;
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshottimport com.sun.identity.shared.encode.Base64;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport com.sun.identity.shared.encode.Hash;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport com.sun.identity.shared.xml.XMLUtils;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport com.sun.identity.sm.SMSSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class holds the default values of service schema.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class ServicesDefaultValues {
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott public static final String RANDOM_SECURE = "@128_BIT_RANDOM_SECURE@";
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static ServicesDefaultValues instance = new ServicesDefaultValues();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Set preappendSlash = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Set trimSlash = new HashSet();
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott private static SecureRandom secureRandom;
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Map defValues = new HashMap();
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster preappendSlash.add(SetupConstants.CONFIG_VAR_PRODUCT_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster preappendSlash.add(SetupConstants.CONFIG_VAR_OLD_CONSOLE_URI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster preappendSlash.add(SetupConstants.CONFIG_VAR_CONSOLE_URI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster preappendSlash.add(SetupConstants.CONFIG_VAR_SERVER_URI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster trimSlash.add(SetupConstants.CONFIG_VAR_CONSOLE_URI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster trimSlash.add(SetupConstants.CONFIG_VAR_SERVER_URI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private ServicesDefaultValues() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ResourceBundle bundle = ResourceBundle.getBundle(
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici "serviceDefaultValues");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Enumeration e = bundle.getKeys();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (e.hasMoreElements()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String key = (String)e.nextElement();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster defValues.put(key, bundle.getString(key));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott try {
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott secureRandom = SecureRandomManager.getSecureRandom();
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott } catch (Exception ex) {
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott throw new IllegalStateException("Failed to initialise secure random");
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method validates the form fields and populates the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * map with valid values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param request is the Servlet Request.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void setServiceConfigValues(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IHttpServletRequest request
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Locale locale = (Locale)request.getLocale();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = instance.defValues;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.putAll(request.getParameterMap());
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String base = (String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_BASE_DIR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster base = base.replace('\\', '/');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_BASE_DIR, base);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!isEncryptionKeyValid()){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException("configurator.encryptkey",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // this set the encryption password for crypt class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // otherwises password in serverconfig.xml will be incorrect
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ekey = ((String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_ENCRYPTION_KEY));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.initializeProperties("am.encryption.pwd", ekey);
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster validatePassword(locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!isServiceURLValid()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException("configurator.invalidhostname",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String cookieDomain = (String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_COOKIE_DOMAIN);
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici if (!isCookieDomainValid(cookieDomain)) {
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici throw new ConfiguratorException("configurator.invalidcookiedomain",
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setDeployURI(request.getContextPath(), map);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String hostname = (String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_SERVER_HOST);
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici map.put(SetupConstants.CONFIG_VAR_COOKIE_DOMAIN,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster getCookieDomain(cookieDomain, hostname));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setPlatformLocale();
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dbOption = (String)map.get(SetupConstants.CONFIG_VAR_DATA_STORE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean embedded = dbOption.equals(SetupConstants.SMS_EMBED_DATASTORE);
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMSetupDSConfig dsConfig = AMSetupDSConfig.getInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dsConfig.setDSValues();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!embedded) { //Sun DS as SM datastore
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String sslEnabled = (String) map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_DIRECTORY_SERVER_SSL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean ssl = (sslEnabled != null) && sslEnabled.equals("SSL");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!dsConfig.isDServerUp(ssl)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dsConfig = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "configurator.dsconnnectfailure", null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington if ((!LDAPUtils.isDN((String) map.get(
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington SetupConstants.CONFIG_VAR_ROOT_SUFFIX))) ||
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (!dsConfig.connectDSwithDN(ssl))) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dsConfig = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException("configurator.invalidsuffix",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.DIT_LOADED, dsConfig.isDITLoaded(ssl));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
441eb21527d5501b2edf4dcd91b9756f8a784d0bJaco Jooste // Enable data store notifications and switch persistent search on for sms.
441eb21527d5501b2edf4dcd91b9756f8a784d0bJaco Jooste // This is now done by default for embedded data stores as well as external
441eb21527d5501b2edf4dcd91b9756f8a784d0bJaco Jooste // to ensure consistent behaviour for refreshing data store cache.
441eb21527d5501b2edf4dcd91b9756f8a784d0bJaco Jooste map.put(SetupConstants.DATASTORE_NOTIFICATION, "true");
441eb21527d5501b2edf4dcd91b9756f8a784d0bJaco Jooste map.put(SetupConstants.DISABLE_PERSISTENT_SEARCH, "aci,um");
441eb21527d5501b2edf4dcd91b9756f8a784d0bJaco Jooste
4e8a549dc885858e1d99b551f4964753e68d3046Mark de Reeper Map userRepo = (Map)map.get(SetupConstants.USER_STORE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String umRootSuffix = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean bUseExtUMDS = (userRepo != null) && !userRepo.isEmpty();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (bUseExtUMDS) {
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici map.put(SetupConstants.UM_DS_DIRMGRDN,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UserIdRepo.getBindDN(userRepo));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.UM_DS_DIRMGRPASSWD,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UserIdRepo.getBindPassword(userRepo));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.UM_DIRECTORY_SERVER,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UserIdRepo.getHost(userRepo));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.UM_DIRECTORY_PORT,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UserIdRepo.getPort(userRepo));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String s = (String) userRepo.get(SetupConstants.USER_STORE_SSL);
597f05fe6c5f9c5b48ee85ea72f7af5cfc8ae83eSachiko Wallace final String isSecure = ((s != null) && s.equals("SSL")) ? "true" : "false";
597f05fe6c5f9c5b48ee85ea72f7af5cfc8ae83eSachiko Wallace map.put(SetupConstants.UM_SSL, isSecure);
597f05fe6c5f9c5b48ee85ea72f7af5cfc8ae83eSachiko Wallace if (Boolean.parseBoolean(isSecure)) {
597f05fe6c5f9c5b48ee85ea72f7af5cfc8ae83eSachiko Wallace map.put(SetupConstants.LDAP_CONNECTION_MODE_TAG, SetupConstants.LDAP_CONNECTION_MODE_LDAPS);
597f05fe6c5f9c5b48ee85ea72f7af5cfc8ae83eSachiko Wallace } else {
597f05fe6c5f9c5b48ee85ea72f7af5cfc8ae83eSachiko Wallace map.put(SetupConstants.LDAP_CONNECTION_MODE_TAG, SetupConstants.LDAP_CONNECTION_MODE_LDAP);
597f05fe6c5f9c5b48ee85ea72f7af5cfc8ae83eSachiko Wallace }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster umRootSuffix =(String)userRepo.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.USER_STORE_ROOT_SUFFIX);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici map.put(SetupConstants.UM_DS_DIRMGRDN,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.get(SetupConstants.CONFIG_VAR_DS_MGR_DN));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.UM_DS_DIRMGRPASSWD,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.get(SetupConstants.CONFIG_VAR_DS_MGR_PWD));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.UM_DIRECTORY_SERVER,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.get(SetupConstants.CONFIG_VAR_DIRECTORY_SERVER_HOST));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.UM_DIRECTORY_PORT,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.get(SetupConstants.CONFIG_VAR_DIRECTORY_SERVER_PORT));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.UM_SSL, "false");
597f05fe6c5f9c5b48ee85ea72f7af5cfc8ae83eSachiko Wallace map.put(SetupConstants.LDAP_CONNECTION_MODE_TAG, SetupConstants.LDAP_CONNECTION_MODE_LDAP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster umRootSuffix = (String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_ROOT_SUFFIX);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster umRootSuffix = umRootSuffix.trim();
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String normalizedDN = DN.valueOf(umRootSuffix).toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String escapedDN = SMSSchema.escapeSpecialCharacters(normalizedDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.UM_NORMALIZED_ORGBASE, escapedDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Set the platform locale.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static void setPlatformLocale() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = instance.defValues;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String locale = (String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_PLATFORM_LOCALE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (locale == null) {
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici map.put(SetupConstants.CONFIG_VAR_PLATFORM_LOCALE,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.DEFAULT_PLATFORM_LOCALE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Validates serverURL.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>true</code> if service URL is valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean isServiceURLValid() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String protocol = "http";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String port = "80";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String hostName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = instance.defValues;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String hostURL = (String)map.get(SetupConstants.CONFIG_VAR_SERVER_URL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean valid = (hostURL != null) && (hostURL.length() > 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (valid) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((hostURL.indexOf("http", 0) == -1) &&
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (hostURL.indexOf("https", 0) == -1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx = hostURL.lastIndexOf(":");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idx != -1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster port = hostURL.substring(idx + 1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster hostName = hostURL.substring(0, idx);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster hostName = hostURL;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (port.equals("443")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protocol = "https";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster URL serverURL = new URL(hostURL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int intPort = serverURL.getPort();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protocol = serverURL.getProtocol();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (intPort < 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (protocol.equalsIgnoreCase("https")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster port = "443";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster port = Integer.toString(intPort);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster hostName = serverURL.getHost();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (isHostnameValid(hostName)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_SERVER_HOST, hostName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_SERVER_PROTO, protocol);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_SERVER_PORT, port);
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici map.put(SetupConstants.CONFIG_VAR_SERVER_URL,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protocol + "://" + hostName + ":" + port);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster valid = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (MalformedURLException mue){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster valid = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return valid;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * valid: localhost (no period)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * valid: abc.sun.com (two periods)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param hostname is the user specified host name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>true</code> if syntax for host is correct.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean isHostnameValid(String hostname) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean valid = (hostname != null) && (hostname.length() > 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (valid) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx = hostname.lastIndexOf(".");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idx != -1) && (idx != (hostname.length() -1))) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx1 = hostname.lastIndexOf(".", idx-1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster valid = (idx1 != -1) && (idx1 < (idx -1));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return valid;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Validates if cookie Domain is syntactically correct.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param cookieDomain is the user specified cookie domain.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>true</code> if syntax for cookie domain is correct.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean isCookieDomainValid(String cookieDomain) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean valid = (cookieDomain == null) || (cookieDomain.length() == 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!valid) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx1 = cookieDomain.lastIndexOf(".");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // need to have a period and cannot be the last char.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster valid = (idx1 == -1) || (idx1 != (cookieDomain.length() -1));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (valid) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx2 = cookieDomain.lastIndexOf(".", idx1-1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * need to be have a period before the last one e.g.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * .sun.com and cannot be ..com
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster valid = (idx2 != -1) && (idx2 < (idx1 -1));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return valid;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the cookie Domain based on the hostname.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param cookieDomain is the user specified cookie domain.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param hostname is the host for which the cookie domain is set.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return cookieDomain containing the valid cookie domain for
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the specified hostname.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String getCookieDomain(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String cookieDomain,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String hostname
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx = hostname.lastIndexOf(".");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idx == -1) || (idx == (hostname.length() -1)) ||
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington ValidateIPaddress.isValidIP(hostname)
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cookieDomain = "";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if ((cookieDomain == null) || (cookieDomain.length() == 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // try to determine the cookie domain if it is not set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String topLevelDomain = hostname.substring(idx+1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx2 = hostname.lastIndexOf(".", idx-1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idx2 != -1) && (idx2 < (idx -1))) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cookieDomain = hostname.substring(idx2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return cookieDomain;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Validates the encryption key.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>true</code> if ecryption key is valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean isEncryptionKeyValid() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = instance.defValues;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ekey = ((String)map.get(
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici SetupConstants.CONFIG_VAR_ENCRYPTION_KEY));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ekey == null) {
cfba646ddfa9d543f0c40e4c7788c65b4a24b34dPhill Cunnington ekey = AMSetupUtils.getRandomString().trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_ENCRYPTION_KEY, ekey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // in future release need to check if length of greater from 10.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ((ekey != null) && (ekey.length() > 0)) ? true : false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Validates Admin passwords.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static void validatePassword(Locale locale) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = instance.defValues;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String adminPwd = ((String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_ADMIN_PWD)).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String confirmAdminPwd = ((String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_CONFIRM_ADMIN_PWD)).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (isPasswordValid(adminPwd, confirmAdminPwd, locale)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemProperties.initializeProperties(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.ENC_PWD_PROPERTY, (((String) map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_ENCRYPTION_KEY)).trim()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Crypt.reinitialize();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.HASH_ADMIN_PWD, (String)Hash.hash(adminPwd));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String urlAccessAgentPwd = (String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_AMLDAPUSERPASSWD);
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (urlAccessAgentPwd != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster urlAccessAgentPwd.trim();
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String urlAccessAgentPwdConfirm = ((String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_AMLDAPUSERPASSWD_CONFIRM)).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster validateURLAccessAgentPassword(adminPwd, urlAccessAgentPwd,
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici urlAccessAgentPwdConfirm, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.remove(SetupConstants.CONFIG_VAR_AMLDAPUSERPASSWD_CONFIRM);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dbOption = (String)map.get(SetupConstants.CONFIG_VAR_DATA_STORE);
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici boolean embedded =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbOption.equals(SetupConstants.SMS_EMBED_DATASTORE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean dbSunDS = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean dbMsAD = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (embedded) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbSunDS = true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else { // Keep old behavior for now.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbSunDS = dbOption.equals(SetupConstants.SMS_DS_DATASTORE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbMsAD = dbOption.equals(SetupConstants.SMS_AD_DATASTORE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (dbSunDS || dbMsAD) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dsMgrPwd = ((String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_DS_MGR_PWD)).trim();
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (embedded) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (dsMgrPwd.length() == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_DS_MGR_PWD, adminPwd);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dsMgrPwd = ((String)map.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SetupConstants.CONFIG_VAR_DS_MGR_PWD));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.ENCRYPTED_SM_DS_PWD,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (String)Crypt.encrypt(dsMgrPwd));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ldapUserPwd = (String)map.get(SetupConstants.LDAP_USER_PWD);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ldapUserPwd != null) {
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici ldapUserPwd.trim();
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici map.put(SetupConstants.ENCRYPTED_LDAP_USER_PWD,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (String)Crypt.encrypt(ldapUserPwd));
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici map.put(SetupConstants.HASH_LDAP_USER_PWD,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (String)Hash.hash(ldapUserPwd));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici map.put(SetupConstants.SSHA512_LDAP_USERPWD,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (String)EmbeddedOpenDS.hash(adminPwd));
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String encryptAdminPwd = Crypt.encrypt(adminPwd);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.ENCRYPTED_ADMIN_PWD, encryptAdminPwd);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.ENCRYPTED_AD_ADMIN_PWD, encryptAdminPwd);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.remove(SetupConstants.CONFIG_VAR_CONFIRM_ADMIN_PWD);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * valid: password greater than 8 characters
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * valid: password and confirm passwords match
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pwd is the Admin password.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param cPwd is the confirm Admin password.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param locale Locale of the HTTP Request.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>true</code> if password is valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean isPasswordValid(
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici String pwd,
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici String cPwd,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Locale locale
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((pwd != null) && (pwd.length() > 7)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!pwd.equals(cPwd)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException("configurator.nopasswdmatch",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException("configurator.passwdlength",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean validateURLAccessAgentPassword(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String amadminPwd,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String pwd,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String cPwd,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Locale locale
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((pwd != null) && (pwd.length() > 7)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!pwd.equals(cPwd)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "configurator.urlaccessagent.passwd.nomatch", null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (amadminPwd.equals(pwd)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "configurator.urlaccessagent.passwd.match.amadmin.pwd",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ConfiguratorException("configurator.passwdlength",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster null, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the map of default attribute name to its value.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the map of default attribute name to its value.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static Map getDefaultValues() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return instance.defValues;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Set the deploy URI.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param deployURI Deploy URI.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param map Service attribute values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void setDeployURI(String deployURI, Map map) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_PRODUCT_NAME, deployURI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_OLD_CONSOLE_URI, deployURI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_CONSOLE_URI, deployURI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster map.put(SetupConstants.CONFIG_VAR_SERVER_URI, deployURI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the tag swapped string.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param orig String to be tag swapped.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the tag swapped string.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static String tagSwap(String orig) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return tagSwap(orig, false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the tag swapped string.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param orig String to be tag swapped.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param bXML <code>true</code> if it is an XML file. and value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * needs to be escaped.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the tag swapped string.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static String tagSwap(String orig, boolean bXML) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = instance.defValues;
555117dd1feaaefe2b92e283b589e3201063e259jeff.schenk for (Object okey : map.keySet().toArray() ) {
555117dd1feaaefe2b92e283b589e3201063e259jeff.schenk String key = (String)okey;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String value = (String)map.get(key);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (value != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = value.replaceAll("[$]", "\\\\\\$");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (preappendSlash.contains(key)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (bXML) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = XMLUtils.escapeSpecialCharacters(value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orig = orig.replaceAll("/@" + key + "@", value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (trimSlash.contains(key)) {
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici orig = orig.replaceAll("@" + key + "@",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value.substring(1));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equals(SetupConstants.CONFIG_VAR_ROOT_SUFFIX)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String normalized = DNUtils.normalizeDN(value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String tmp = normalized.replaceAll(",", "^");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tmp = (bXML) ? XMLUtils.escapeSpecialCharacters(tmp) :
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tmp ;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orig = orig.replaceAll(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "@" + SetupConstants.SM_ROOT_SUFFIX_HAT + "@", tmp);
0be6372051459d02acfe49de71e8d6653f0b412eAlin Brici
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String rfced = DN.valueOf(value).toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tmp = (bXML) ? XMLUtils.escapeSpecialCharacters(rfced) :
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rfced;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orig = orig.replaceAll(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "@" + SetupConstants.CONFIG_VAR_ROOT_SUFFIX + "@",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tmp);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster key.equals(SetupConstants.SM_ROOT_SUFFIX_HAT) ||
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster key.equals(SetupConstants.NORMALIZED_RS) ||
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster key.equals(SetupConstants.NORMALIZED_ORG_BASE) ||
9fa57a4f31580310b62bb2f08906e6b73d510817jeff.schenk key.equals(SetupConstants.SM_ROOT_SUFFIX_HAT) ||
9fa57a4f31580310b62bb2f08906e6b73d510817jeff.schenk key.equals(SetupConstants.CONFIG_VAR_SESSION_ROOT_SUFFIX) ||
9fa57a4f31580310b62bb2f08906e6b73d510817jeff.schenk key.equals(SetupConstants.CONFIG_VAR_SESSION_STORE_TYPE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orig = orig.replaceAll("@" + key + "@", value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (bXML) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = XMLUtils.escapeSpecialCharacters(value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orig = orig.replaceAll("@" + key + "@", value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott // Each Secure Random tag should be a newly generated random.
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott while (orig.contains(RANDOM_SECURE)) {
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott byte[] bytes = new byte[16]; // 16 * 8 = 128 bits
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott secureRandom.nextBytes(bytes);
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott orig = orig.replace(RANDOM_SECURE, Base64.encode(bytes));
d78764efc954da87cd81023cc846a6a5af360d95Robert Wapshott }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return orig;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}