Step4.java revision 8af80418ba1ec431c8027fa9668e5678658d3611
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync/**
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync *
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync *
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * The contents of this file are subject to the terms
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * of the Common Development and Distribution License
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * (the License). You may not use this file except in
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * compliance with the License.
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync *
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * You can obtain a copy of the License at
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * https://opensso.dev.java.net/public/CDDLv1.0.html or
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * opensso/legal/CDDLv1.0.txt
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * See the License for the specific language governing
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * permission and limitations under the License.
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync *
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * When distributing Covered Code, include this CDDL
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * Header Notice in each file and include the License file
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * at opensso/legal/CDDLv1.0.txt.
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * If applicable, add the following below the CDDL Header,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * with the fields enclosed by brackets [] replaced by
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * your own identifying information:
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * "Portions Copyrighted [year] [name of copyright owner]"
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync *
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * $Id: Step4.java,v 1.20 2009/10/27 05:31:45 hengming Exp $
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync *
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync */
9040f019271f91b98e1320c0a8c38a42636e3979vboxsync
9040f019271f91b98e1320c0a8c38a42636e3979vboxsync/*
9040f019271f91b98e1320c0a8c38a42636e3979vboxsync * Portions Copyrighted 2011-2012 ForgeRock AS
9040f019271f91b98e1320c0a8c38a42636e3979vboxsync */
9040f019271f91b98e1320c0a8c38a42636e3979vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncpackage com.sun.identity.config.wizard;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport com.iplanet.am.util.SSLSocketFactoryManager;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport com.sun.identity.config.SessionAttributeNames;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport org.apache.click.control.ActionLink;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport com.sun.identity.config.util.AjaxPage;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport com.sun.identity.setup.SetupConstants;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport org.apache.click.Context;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport com.sun.identity.shared.ldap.LDAPConnection;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport com.sun.identity.shared.ldap.LDAPException;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport com.sun.identity.shared.ldap.util.DN;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
9040f019271f91b98e1320c0a8c38a42636e3979vboxsyncimport java.io.IOException;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport java.net.Socket;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport java.util.Hashtable;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport javax.naming.NamingException;
9040f019271f91b98e1320c0a8c38a42636e3979vboxsyncimport javax.naming.directory.Attribute;
9040f019271f91b98e1320c0a8c38a42636e3979vboxsyncimport javax.naming.directory.Attributes;
9040f019271f91b98e1320c0a8c38a42636e3979vboxsyncimport javax.naming.directory.DirContext;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncimport javax.naming.directory.InitialDirContext;
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync/**
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync * Step 4 is the input of the remote user data store properties.
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync */
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsyncpublic class Step4 extends AjaxPage {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public static final String LDAP_STORE_SESSION_KEY = "wizardCustomUserStore";
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink validateUMHostLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("validateUMHost", this, "validateUMHost");
9040f019271f91b98e1320c0a8c38a42636e3979vboxsync public ActionLink validateUMDomainNameLink =
9040f019271f91b98e1320c0a8c38a42636e3979vboxsync new ActionLink("validateUMDomainName", this,
9040f019271f91b98e1320c0a8c38a42636e3979vboxsync "validateUMDomainName");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink setSSLLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setSSL", this, "setSSL");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink setUMEmbedded =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setUMEmbedded", this, "setUMEmbedded");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink resetUMEmbedded =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("resetUMEmbedded", this, "resetUMEmbedded");
99be02f9e15a3ca61b6a7c207cc7eb68dbd04817vboxsync public ActionLink setHostLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setHost", this, "setHost");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink setDomainNameLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setDomainName", this, "setDomainName");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink setPortLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setPort", this, "setPort");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink setRootSuffixLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setRootSuffix", this, "setRootSuffix");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink setLoginIDLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setLoginID", this, "setLoginID");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink setPasswordLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setPassword", this, "setPassword");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public ActionLink setStoreTypeLink =
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync new ActionLink("setStoreType", this, "setStoreType");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync private String responseString = "ok";
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public Step4() {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync }
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public void onInit() {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync super.onInit();
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync Context ctx = getContext();
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync if (ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_HOST)
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync == null) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync String val = getAttribute(SetupConstants.CONFIG_VAR_DATA_STORE,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync SetupConstants.SMS_EMBED_DATASTORE);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync if (!val.equals(SetupConstants.SMS_EMBED_DATASTORE)) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute("configStoreSSL", "SIMPLE");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_SSL,
6c90795355c6e59ba82e8e5a58e10d686a6d6e65vboxsync val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute("configStoreHost", getHostName());
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_HOST,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute("configStorePort", "389");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_PORT,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute("configStoreLoginId",Wizard.defaultUserName);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync SessionAttributeNames.USER_STORE_LOGIN_ID, val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute("rootSuffix", Wizard.defaultRootSuffix);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync SessionAttributeNames.USER_STORE_ROOT_SUFFIX, val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync }
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.EXT_DATA_STORE,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync "true");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_TYPE,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync "LDAPv3ForSUNDS");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync }
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync String smsType = getAttribute(SetupConstants.CONFIG_VAR_DATA_STORE,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync "embedded");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync if (!smsType.equals("embedded")) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync SessionAttributeNames.EXT_DATA_STORE, "true");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("radioDataTypeDisabled", "disabled");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync } else {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("radioDataTypeDisabled", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync }
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync String val = getAttribute(SetupConstants.USER_STORE_HOST,getHostName());
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_HOST, val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("userStoreHost", val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute(SetupConstants.USER_STORE_SSL, "SIMPLE");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_SSL, val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync if (val.equals("SSL")) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectUserStoreSSL", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync } else {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectUserStoreSSL", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync }
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute(SetupConstants.USER_STORE_PORT, "389");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_PORT, val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("userStorePort", val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute(SetupConstants.USER_STORE_LOGIN_ID,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync Wizard.defaultUserName);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_LOGIN_ID, val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("userStoreLoginId", val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute(SetupConstants.USER_STORE_ROOT_SUFFIX,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync Wizard.defaultRootSuffix);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync ctx.setSessionAttribute(SessionAttributeNames.USER_STORE_ROOT_SUFFIX,
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("userStoreRootSuffix", val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute(SetupConstants.USER_STORE_TYPE, "LDAPv3ForSUNDS");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync if (val.equals("LDAPv3ForAD")) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3ad", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3addc", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3adam", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3sunds", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3opends", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3tivoli", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync } else if (val.equals("LDAPv3ForADDC")) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3addc", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3ad", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3adam", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3sunds", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3opends", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3tivoli", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync } else if (val.equals("LDAPv3ForADAM")) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3adam", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3ad", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3addc", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3sunds", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3opends", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3tivoli", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync } else if (val.equals("LDAPv3ForSUNDS")) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3sunds", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3ad", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3addc", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3adam", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3opends", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3tivoli", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync } else if (val.equals("LDAPv3ForOpenDS")) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3opends", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3ad", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3addc", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3adam", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3sunds", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3tivoli", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync } else {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3tivoli", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3ad", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3addc", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3adam", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3sunds", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectLDAPv3opends", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync }
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync val = getAttribute("EXT_DATA_STORE", "true");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("EXT_DATA_STORE", val);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync if (val.equals("true")) {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectEmbeddedUM", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectExternalUM", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync } else {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectEmbeddedUM", "checked=\"checked\"");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync addModel("selectExternalUM", "");
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync }
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync }
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync public boolean setAll() {
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync setPath(null);
c1f5ec452b23d55c71e6f07628b84ac5e97cf551vboxsync return false;
}
public boolean setSSL() {
String ssl = toString("ssl");
if ((ssl != null) && ssl.length() > 0) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_SSL, ssl);
} else {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_SSL, "SIMPLE");
}
writeToResponse(getLocalizedString(responseString));
setPath(null);
return false;
}
public boolean setDomainName() {
String domainname = toString("domainname");
if ((domainname != null) && domainname.length() > 0) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_DOMAINNAME,
domainname);
getContext().setSessionAttribute(
SessionAttributeNames.EXT_DATA_STORE, "true");
} else {
responseString = "missing.domain.name";
}
writeToResponse(getLocalizedString(responseString));
setPath(null);
return false;
}
public boolean setHost() {
String host = toString("host");
if ((host != null) && host.length() > 0) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_HOST, host);
} else {
responseString = "missing.host.name";
}
writeToResponse(getLocalizedString(responseString));
setPath(null);
return false;
}
public boolean setUMEmbedded() {
getContext().setSessionAttribute(SessionAttributeNames.EXT_DATA_STORE,
"false");
setPath(null);
return false;
}
public boolean resetUMEmbedded() {
getContext().setSessionAttribute(SessionAttributeNames.EXT_DATA_STORE,
"true");
setPath(null);
return false;
}
public boolean setPort() {
String port = toString("port");
if ((port != null) && port.length() > 0) {
int intValue = Integer.parseInt(port);
if ((intValue > 0) && (intValue < 65535)) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_PORT, port);
} else {
responseString = "invalid.port.number";
}
} else {
responseString = "missing.host.port";
}
writeToResponse(getLocalizedString(responseString));
setPath(null);
return false;
}
public boolean setLoginID() {
String dn = toString("dn");
if ((dn != null) && dn.length() > 0) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_LOGIN_ID, dn);
} else {
responseString = "missing.login.id";
}
writeToResponse(getLocalizedString(responseString));
setPath(null);
return false;
}
public boolean setPassword() {
String pwd = toString("password");
if ((pwd != null) && pwd.length() > 0) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_LOGIN_PWD, pwd);
} else {
responseString = "missing.password";
}
writeToResponse(getLocalizedString(responseString));
setPath(null);
return false;
}
public boolean setRootSuffix() {
String rootsuffix = toString("rootsuffix");
if ((rootsuffix != null) && rootsuffix.length() > 0) {
if (DN.isDN(rootsuffix)) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_ROOT_SUFFIX, rootsuffix);
} else {
responseString = "invalid.dn";
}
} else {
responseString = "missing.root.suffix";
}
writeToResponse(getLocalizedString(responseString));
setPath(null);
return false;
}
public boolean setStoreType() {
String type = toString("type");
if ((type != null) && type.length() > 0) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_TYPE, type);
}
writeToResponse(responseString);
setPath(null);
return false;
}
public boolean validateUMHost() {
Context ctx = getContext();
String strSSL = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_SSL);
boolean ssl = (strSSL != null) && (strSSL.equals("SSL"));
String host = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_HOST);
String strPort = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_PORT);
int port = Integer.parseInt(strPort);
String bindDN = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_LOGIN_ID);
String rootSuffix = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_ROOT_SUFFIX);
String bindPwd = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_LOGIN_PWD);
LDAPConnection ld = null;
try {
ld = (ssl) ? new LDAPConnection(
SSLSocketFactoryManager.getSSLSocketFactory()) :
new LDAPConnection();
ld.setConnectTimeout(5);
ld.connect(3, host, port, bindDN, bindPwd);
String filter = "cn=" + "\"" + rootSuffix + "\"";
String[] attrs = {""};
ld.search(rootSuffix, LDAPConnection.SCOPE_BASE, filter,
attrs, false);
writeToResponse("ok");
} catch (LDAPException lex) {
switch (lex.getLDAPResultCode()) {
case LDAPException.CONNECT_ERROR:
writeToResponse(getLocalizedString("ldap.connect.error"));
break;
case LDAPException.SERVER_DOWN:
writeToResponse(getLocalizedString("ldap.server.down"));
break;
case LDAPException.INVALID_DN_SYNTAX:
writeToResponse(getLocalizedString("ldap.invalid.dn"));
break;
case LDAPException.NO_SUCH_OBJECT:
writeToResponse(getLocalizedString("ldap.nosuch.object"));
break;
case LDAPException.INVALID_CREDENTIALS:
writeToResponse(
getLocalizedString("ldap.invalid.credentials"));
break;
case LDAPException.UNWILLING_TO_PERFORM:
writeToResponse(getLocalizedString("ldap.unwilling"));
break;
case LDAPException.INAPPROPRIATE_AUTHENTICATION:
writeToResponse(getLocalizedString("ldap.inappropriate"));
break;
case LDAPException.CONSTRAINT_VIOLATION:
writeToResponse(getLocalizedString("ldap.constraint"));
break;
default:
writeToResponse(
getLocalizedString("cannot.connect.to.SM.datastore"));
}
} catch (Exception e) {
writeToResponse(
getLocalizedString("cannot.connect.to.SM.datastore"));
} finally {
if (ld != null) {
try {
ld.disconnect();
} catch (LDAPException ex) {
//ignore
}
}
}
setPath(null);
return false;
}
public boolean validateUMDomainName() {
setPath(null);
Context ctx = getContext();
String strSSL = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_SSL);
boolean ssl = (strSSL != null) && (strSSL.equals("SSL"));
String domainName = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_DOMAINNAME);
String rootSuffixAD = dnsDomainToDN(domainName);
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_ROOT_SUFFIX,
rootSuffixAD);
String[] hostAndPort = {""};
try {
hostAndPort = getLdapHostAndPort(domainName);
} catch (NamingException nex) {
writeToResponse(
getLocalizedString("cannot.connect.to.UM.datastore"));
return false;
} catch (IOException ioex) {
writeToResponse(
getLocalizedString("cannot.connect.to.UM.datastore"));
return false;
}
String host = hostAndPort[0];
int port = Integer.parseInt(hostAndPort[1]);
String bindDN = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_LOGIN_ID);
String rootSuffix = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_ROOT_SUFFIX);
String bindPwd = (String)ctx.getSessionAttribute(
SessionAttributeNames.USER_STORE_LOGIN_PWD);
LDAPConnection ld = null;
try {
ld = (ssl) ? new LDAPConnection(
SSLSocketFactoryManager.getSSLSocketFactory()) :
new LDAPConnection();
ld.setConnectTimeout(5);
ld.connect(3, host, port, bindDN, bindPwd);
String filter = "cn=" + "\"" + rootSuffix + "\"";
String[] attrs = {""};
ld.search(rootSuffix, LDAPConnection.SCOPE_BASE, filter,
attrs, false);
writeToResponse("ok");
} catch (LDAPException lex) {
switch (lex.getLDAPResultCode()) {
case LDAPException.CONNECT_ERROR:
writeToResponse(getLocalizedString(
"ldap.connect.error"));
break;
case LDAPException.SERVER_DOWN:
writeToResponse(getLocalizedString(
"ldap.server.down"));
break;
case LDAPException.INVALID_DN_SYNTAX:
writeToResponse(getLocalizedString(
"ldap.invalid.dn"));
break;
case LDAPException.NO_SUCH_OBJECT:
writeToResponse(getLocalizedString(
"ldap.nosuch.object"));
break;
case LDAPException.INVALID_CREDENTIALS:
writeToResponse(getLocalizedString(
"ldap.invalid.credentials"));
break;
case LDAPException.UNWILLING_TO_PERFORM:
writeToResponse(getLocalizedString(
"ldap.unwilling"));
break;
case LDAPException.INAPPROPRIATE_AUTHENTICATION:
writeToResponse(getLocalizedString(
"ldap.inappropriate"));
break;
case LDAPException.CONSTRAINT_VIOLATION:
writeToResponse(getLocalizedString(
"ldap.constraint"));
break;
default:
writeToResponse(getLocalizedString(
"cannot.connect.to.UM.datastore"));
}
} catch (Exception e) {
writeToResponse(getLocalizedString(
"cannot.connect.to.UM.datastore"));
} finally {
if (ld != null) {
try {
ld.disconnect();
} catch (LDAPException ex) {
//ignore
}
}
}
return false;
}
// Method to get hostname and port number with the
// provided Domain Name for Active Directory user data store.
private String[] getLdapHostAndPort(String domainName)
throws NamingException, IOException {
if (!domainName.endsWith(".")) {
domainName+='.';
}
DirContext ictx = null;
// Check if domain name is a valid one.
// The resource record type A is defined in RFC 1035.
try {
Hashtable env = new Hashtable();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.dns.DnsContextFactory");
ictx = new InitialDirContext(env);
Attributes attributes =
ictx.getAttributes(domainName, new String[]{"A"});
Attribute attrib = attributes.get("A");
if (attrib == null) {
throw new NamingException();
}
} catch (NamingException e) {
// Failed to resolve domainName to A record.
// throw exception.
throw e;
}
// then look for the LDAP server
String serverHostName = null;
String serverPortStr = null;
final String ldapServer = "_ldap._tcp." + domainName;
try {
// Attempting to resolve ldapServer to SRV record.
// This is a mechanism defined in MSDN, querying
// SRV records for _ldap._tcp.DOMAINNAME.
// and get host and port from domain.
Attributes attributes =
ictx.getAttributes(ldapServer, new String[]{"SRV"});
Attribute attr = attributes.get("SRV");
if (attr == null) {
throw new NamingException();
}
String[] srv = attr.get().toString().split(" ");
String hostNam = srv[3];
serverHostName =
hostNam.substring(0, hostNam.length() -1);
if ((serverHostName != null) &&
serverHostName.length() > 0) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_HOST,
serverHostName);
}
serverPortStr = srv[2];
} catch (NamingException e) {
// Failed to resolve ldapServer to SRV record.
// throw exception.
throw e;
}
// try to connect to LDAP port to make sure this machine
// has LDAP service
int serverPort = Integer.parseInt(serverPortStr);
if ((serverPort > 0) && (serverPort < 65535)) {
getContext().setSessionAttribute(
SessionAttributeNames.USER_STORE_PORT, serverPortStr);
}
try {
new Socket(serverHostName, serverPort).close();
} catch (IOException e) {
throw e;
}
String[] hostAndPort = new String[2];
hostAndPort[0] = serverHostName;
hostAndPort[1] = serverPortStr;
return hostAndPort;
}
// Method to convert the domain name to the root suffix.
// eg., Domain Name amqa.test.com is converted to root suffix
// DC=amqa,DC=test,DC=com
static String dnsDomainToDN(String domainName) {
StringBuilder buf = new StringBuilder();
for (String token : domainName.split("\\.")) {
if(token.length()==0) continue;
if(buf.length()>0) buf.append(",");
buf.append("DC=").append(token);
}
return buf.toString();
}
}