getServerInfo.jsp revision 7c2b35fb4b3e07fac18cadded895cff744104de6
1051N/A<%--
1051N/A DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1051N/A
1051N/A Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
1051N/A
1051N/A The contents of this file are subject to the terms
1051N/A of the Common Development and Distribution License
1051N/A (the License). You may not use this file except in
1051N/A compliance with the License.
1051N/A
1051N/A You can obtain a copy of the License at
1051N/A https://opensso.dev.java.net/public/CDDLv1.0.html or
1051N/A opensso/legal/CDDLv1.0.txt
1051N/A See the License for the specific language governing
1051N/A permission and limitations under the License.
1051N/A
1051N/A When distributing Covered Code, include this CDDL
1051N/A Header Notice in each file and include the License file
1051N/A at opensso/legal/CDDLv1.0.txt.
1051N/A If applicable, add the following below the CDDL Header,
1051N/A with the fields enclosed by brackets [] replaced by
1051N/A your own identifying information:
1051N/A "Portions Copyrighted [year] [name of copyright owner]"
1051N/A
1051N/A $Id: getServerInfo.jsp,v 1.6 2008/09/04 00:34:01 rajeevangal Exp $
1051N/A
1051N/A Portions Copyrighted 2010-2015 ForgeRock AS.
1051N/A--%>
1920N/A
1051N/A<%@ page
1051N/Aimport="com.iplanet.am.util.SystemProperties,
1051N/A com.iplanet.services.naming.WebtopNaming,
1051N/A com.iplanet.sso.SSOException,
1051N/A com.iplanet.sso.SSOTokenManager,
1111N/A com.sun.identity.authentication.AuthContext,
1051N/A com.sun.identity.setup.AMSetupUtils,
1051N/A com.sun.identity.setup.BootstrapData,
1051N/A com.sun.identity.setup.EmbeddedOpenDS,
1051N/A com.sun.identity.setup.JCECrypt,
1051N/A com.sun.identity.setup.SetupConstants,
1111N/A java.io.File,
1051N/A java.net.URLEncoder,
1051N/A java.util.ArrayList,
1247N/A java.util.Map,
1247N/A javax.security.auth.callback.Callback,
1051N/A javax.security.auth.callback.NameCallback,
1111N/A javax.security.auth.callback.PasswordCallback"
1051N/A%>
1051N/A<%
1051N/A if ("POST".equals(request.getMethod()) != true) {
1186N/A response.sendError(405);
1304N/A return;
1186N/A }
1186N/A String username = request.getParameter("IDToken1");
1186N/A String password = request.getParameter("IDToken2");
1186N/A
1186N/A if ( username == null && password == null) {
1304N/A response.sendError(400);
1051N/A return;
1051N/A }
1051N/A
1051N/A if ("amadmin".equals(username) == false) {
1186N/A response.sendError(401);
1186N/A return;
1186N/A }
1186N/A
1111N/A AuthContext lc = new AuthContext("/");
1401N/A lc.login(AuthContext.IndexType.SERVICE, "adminconsoleservice");
1111N/A while (lc.hasMoreRequirements()) {
1247N/A Callback[] callbacks = lc.getRequirements();
1591N/A ArrayList missing = new ArrayList();
1111N/A // loop through the requires setting the needs..
1777N/A for (int i = 0; i < callbacks.length; i++) {
1516N/A if (callbacks[i] instanceof NameCallback) {
1516N/A NameCallback nc = (NameCallback) callbacks[i];
1111N/A nc.setName(username);
1516N/A } else if (callbacks[i] instanceof PasswordCallback) {
1111N/A PasswordCallback pc = (PasswordCallback) callbacks[i];
1247N/A pc.setPassword(password.toCharArray());
1111N/A } else {
1051N/A missing.add(callbacks[i]);
1051N/A }
1777N/A }
1777N/A // there's missing requirements not filled by this
1777N/A if (missing.size() > 0) {
1777N/A // need add the missing later..
1051N/A response.sendError(401);
return;
}
lc.submitRequirements(callbacks);
}
// validate the password..
if (lc.getStatus() != AuthContext.Status.SUCCESS) {
response.sendError(401);
return;
} else {
try {
SSOTokenManager mgr = SSOTokenManager.getInstance();
mgr.destroyToken(lc.getSSOToken());
} catch (SSOException e) {
// ignore
}
}
String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
String encKey = SystemProperties.get("am.encryption.pwd");
String defAgentPwd = SystemProperties.get("com.iplanet.am.service.secret");
BootstrapData bootstrapData = new BootstrapData(baseDir);
boolean isEmbeddedDS = (new File(baseDir + "/opends")).exists();
// Assumption : opends entry is the 1st
Map bMap = bootstrapData.getDataAsMap(0);
String dsbasedn = (String) bMap.get(BootstrapData.DS_BASE_DN);
String dsport = (String) bMap.get(BootstrapData.DS_PORT);
String dsprotocol = (String) bMap.get(BootstrapData.DS_PROTOCOL);
String dsrelport = (String) bMap.get(BootstrapData.DS_REPLICATIONPORT);
String dshost = (String) bMap.get(BootstrapData.DS_HOST);
String dsmgr = (String) bMap.get(BootstrapData.DS_MGR);
String dspwd = (String) bMap.get(BootstrapData.DS_PWD);
String serverid = WebtopNaming.getLocalServer();
// if embedded get replication port status. Two cases :
// i) No replication port -> generate a new one
// ii) replication port available -> retrieve it
String replPort = null;
String replPortAvailable = null;
String adminPort = null;
if (isEmbeddedDS) {
replPort = EmbeddedOpenDS.getReplicationPort(dsmgr, JCECrypt.decode(dspwd),
"localhost", dsport);
replPortAvailable = "true";
if (replPort == null) {
replPortAvailable = "false";
replPort = ""+ AMSetupUtils.getFirstUnusedPort("localhost", 50889, 1000);
}
adminPort = EmbeddedOpenDS.getAdminPort(dsmgr, JCECrypt.decode(dspwd),
"localhost", dsport);
if (adminPort == null) {
adminPort = "4444";
}
}
// We have collected all the data - return a response
StringBuffer buf = new StringBuffer();
buf.append(BootstrapData.DS_ISEMBEDDED).append("=").append(isEmbeddedDS).
append("&");
if (dsprotocol != null) {
buf.append(BootstrapData.DS_PROTOCOL).append("=").
append(URLEncoder.encode(dsprotocol, "UTF-8")).append("&");
}
if (dshost != null) {
buf.append(BootstrapData.DS_HOST).append("=").
append(URLEncoder.encode(dshost, "UTF-8")).append("&");
}
if (dsport != null) {
buf.append(BootstrapData.DS_PORT).append("=").append(dsport).
append("&");
}
if (dsbasedn != null) {
buf.append(BootstrapData.DS_BASE_DN).append("=").
append(URLEncoder.encode(dsbasedn, "UTF-8")).append("&");
}
if (replPort != null) {
buf.append(BootstrapData.DS_REPLICATIONPORT).append("=").
append(replPort).append("&");
}
if (adminPort != null) {
buf.append(SetupConstants.DS_EMB_REPL_ADMINPORT2).append("=").
append(adminPort).append("&");
}
if (replPortAvailable != null) {
buf.append(BootstrapData.DS_REPLICATIONPORT_AVAILABLE).append("=").
append(replPortAvailable).append("&");
}
if (dsmgr != null) {
buf.append(BootstrapData.DS_MGR).append("=").
append(URLEncoder.encode(dsmgr, "UTF-8")).append("&");
}
if (dspwd != null) {
buf.append(BootstrapData.DS_PWD).append("=").
append(URLEncoder.encode(dspwd, "UTF-8")).append("&");
}
if (encKey != null) {
buf.append(BootstrapData.ENCKEY).append("=").
append(URLEncoder.encode(encKey, "UTF-8"));
}
if (defAgentPwd != null) {
buf.append("&ENCLDAPUSERPASSWD=").append(
URLEncoder.encode(defAgentPwd, "UTF-8"));
}
if (serverid != null) {
buf.append("&existingserverid=").append(
URLEncoder.encode(serverid, "UTF-8"));
}
out.println(buf.toString());
%>