getServerInfo.jsp revision eedaf7500ed5a81829f1b04c3a6092360e190000
18727N/A<%--
18277N/A DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
18277N/A
18277N/A Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
18277N/A
18277N/A The contents of this file are subject to the terms
18277N/A of the Common Development and Distribution License
18277N/A (the License). You may not use this file except in
18277N/A compliance with the License.
18277N/A
18277N/A You can obtain a copy of the License at
18277N/A https://opensso.dev.java.net/public/CDDLv1.0.html or
18277N/A opensso/legal/CDDLv1.0.txt
18277N/A See the License for the specific language governing
18277N/A permission and limitations under the License.
18277N/A
18277N/A When distributing Covered Code, include this CDDL
18277N/A Header Notice in each file and include the License file
18277N/A at opensso/legal/CDDLv1.0.txt.
18277N/A If applicable, add the following below the CDDL Header,
18277N/A with the fields enclosed by brackets [] replaced by
18277N/A your own identifying information:
18277N/A "Portions Copyrighted [year] [name of copyright owner]"
$Id: getServerInfo.jsp,v 1.6 2008/09/04 00:34:01 rajeevangal Exp $
--%>
<%-- Portions Copyrighted 2010-2013 ForgeRock Inc --%>
<%@ page
import="com.iplanet.am.util.SystemProperties,
com.iplanet.services.naming.WebtopNaming,
com.iplanet.sso.SSOException,
com.iplanet.sso.SSOToken,
com.iplanet.sso.SSOTokenManager,
com.sun.identity.authentication.AuthContext,
com.sun.identity.setup.AMSetupServlet,
com.sun.identity.setup.BootstrapData,
com.sun.identity.setup.EmbeddedOpenDS,
com.sun.identity.setup.JCECrypt,
com.sun.identity.setup.SetupConstants,
java.io.File,
java.net.URLDecoder,
java.net.URLEncoder,
java.util.ArrayList,
java.util.Map,
javax.security.auth.callback.Callback,
javax.security.auth.callback.NameCallback,
javax.security.auth.callback.PasswordCallback"
%>
<%
String method = request.getMethod();
if ("POST".equals(request.getMethod()) != true) {
response.sendError(405);
return;
}
String username = request.getParameter("IDToken1");
String password = request.getParameter("IDToken2");
if ( username == null && password == null) {
response.sendError(400);
return;
}
username = URLDecoder.decode(username, "UTF-8");
password = URLDecoder.decode(password, "UTF-8");
if ("amadmin".equals(username) == false) {
response.sendError(401);
return;
}
AuthContext lc = new AuthContext("/");
lc.login(AuthContext.IndexType.SERVICE, "adminconsoleservice");
while (lc.hasMoreRequirements()) {
Callback[] callbacks = lc.getRequirements();
ArrayList missing = new ArrayList();
// loop through the requires setting the needs..
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback nc = (NameCallback) callbacks[i];
nc.setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) callbacks[i];
pc.setPassword(password.toCharArray());
} else {
missing.add(callbacks[i]);
}
}
// there's missing requirements not filled by this
if (missing.size() > 0) {
// need add the missing later..
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 = ""+ AMSetupServlet.getUnusedPort("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());
%>