getServerInfo.jsp revision e8721886dbfd32e88cc7077cbee4b6bb1b44b443
8bb95fe13ab4a36335f43c5633243b777d4ddbadjohanengelen<%--
8bb95fe13ab4a36335f43c5633243b777d4ddbadjohanengelen DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
dcc400ef5bae04887b791ab8bb365c09db81eaf2johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm The contents of this file are subject to the terms
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm of the Common Development and Distribution License
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm (the License). You may not use this file except in
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm compliance with the License.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm You can obtain a copy of the License at
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm https://opensso.dev.java.net/public/CDDLv1.0.html or
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm opensso/legal/CDDLv1.0.txt
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm See the License for the specific language governing
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm permission and limitations under the License.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm When distributing Covered Code, include this CDDL
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Header Notice in each file and include the License file
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm at opensso/legal/CDDLv1.0.txt.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm If applicable, add the following below the CDDL Header,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm with the fields enclosed by brackets [] replaced by
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm your own identifying information:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm "Portions Copyrighted [year] [name of copyright owner]"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm $Id: getServerInfo.jsp,v 1.6 2008/09/04 00:34:01 rajeevangal Exp $
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm--%>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
62d835b4bbb0f1f046e30d9b67f8e9517cc6175cjohanengelen<%-- Portions Copyrighted [2010] [ForgeRock AS] --%>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
76addc201c409e81eaaa73fe27cc0f79c4db097cKrzysztof Kosiński<%@ page
8bb95fe13ab4a36335f43c5633243b777d4ddbadjohanengelenimport="com.iplanet.am.util.SystemProperties,
a39c187369a59e887255e3f704a3ababf2b10678Johan B. C. Engelen com.iplanet.services.naming.WebtopNaming,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm com.iplanet.sso.SSOException,
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen com.iplanet.sso.SSOToken,
80c9473a95dd9a83020a247201452e45ec9750c3johanengelen com.iplanet.sso.SSOTokenManager,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm com.sun.identity.authentication.AuthContext,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm com.sun.identity.setup.AMSetupServlet,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm com.sun.identity.setup.BootstrapData,
f358fb039ddd7cb6716a4120d93071ac62283a00johanengelen com.sun.identity.setup.EmbeddedOpenDS,
f358fb039ddd7cb6716a4120d93071ac62283a00johanengelen com.sun.identity.setup.JCECrypt,
f358fb039ddd7cb6716a4120d93071ac62283a00johanengelen com.sun.identity.setup.SetupConstants,
f358fb039ddd7cb6716a4120d93071ac62283a00johanengelen java.io.File,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm java.net.URLDecoder,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm java.net.URLEncoder,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm java.util.ArrayList,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm java.util.Map,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm javax.security.auth.callback.Callback,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm javax.security.auth.callback.NameCallback,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm javax.security.auth.callback.PasswordCallback"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm%>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm<%
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm String method = request.getMethod();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm 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();
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());
%>