8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
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 * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
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 * $Id: AMModuleProperties.java,v 1.8 2009/05/02 22:11:28 kevinserwin Exp $
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings * Portions Copyrighted 2011-16 ForgeRock AS
8d703e778adaffe0f9319b3e84f9fe9741466b33Brian Baileyimport com.sun.identity.authentication.callbacks.HiddenValueCallback;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottimport com.sun.identity.authentication.callbacks.ScriptTextOutputCallback;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottimport com.sun.identity.authentication.service.AuthD;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshottimport com.sun.identity.authentication.share.AuthXMLTags;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.ChoiceCallback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.ConfirmationCallback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.LanguageCallback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.NameCallback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.PasswordCallback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.TextInputCallback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.TextOutputCallback;
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbingsimport org.forgerock.openam.authentication.callbacks.PollingWaitCallback;
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbingsimport org.forgerock.openam.utils.CollectionUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private int p = 0; // callback of the specific pages
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private List attribute; // Attribute for each page
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private List require; // isRequire for each page
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Map moduleProps = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = Debug.getInstance(amAuth);
23e304384f98fca4ab2e6f9f07a53465c1bfc645Peter Major DocumentBuilder builder = XMLUtils.getSafeDocumentBuilder(false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster in = servletContext.getResourceAsStream(fileName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster in = Thread.currentThread().getContextClassLoader()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // remove leading '/' from fileName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Callback[] cb = (Callback[]) rtable.get(Integer.toString(i));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("AMModuleProperties, parse file :" +fileName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("AMModuleProperties, parser error :" , e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AuthLoginException(amAuth, "getModulePropertiesError",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Return the list of page
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>List</code> of page
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Return the list of authentication module property
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param fileName that has module properties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>List</code> of module property
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception AuthLoginException if fails to get properties from the file.
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings public static List getModuleProperties(String fileName) throws AuthLoginException {
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings List propertiesList = (List) moduleProps.get(fileName);
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings ServletContext servletContext = AuthD.getAuth().getServletContext();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster resStream = servletContext.getResourceAsStream(fileName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // remove leading '/' from fileName
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings resStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName.substring(1));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // file might be empty for modules like Cert,Anonymous etc.
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings if (resStream != null && resStream.read() == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized(moduleProps) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("getModuleProperties: Error: " ,e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMModuleProperties prop = new AMModuleProperties(fileName,
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings if (CollectionUtils.isEmpty(propertiesList)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized(moduleProps) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //walk the DOM tree and create the callback array
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String timeout = getAttribute(node, "timeout");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String template = getAttribute(node, "template");
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings int size = Integer.parseInt(getAttribute(node, "length")) + 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster callbacks[p] = new PagePropertiesCallback(moduleName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String prompt = sub.getFirstChild().getNodeValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster callbacks[p] = new NameCallback(prompt, dftName);
8d703e778adaffe0f9319b3e84f9fe9741466b33Brian Bailey } else if (nodeName.equals("HiddenValueCallback")) {
8d703e778adaffe0f9319b3e84f9fe9741466b33Brian Bailey String id = sub.getFirstChild().getNodeValue();
8d703e778adaffe0f9319b3e84f9fe9741466b33Brian Bailey callbacks[p] = new HiddenValueCallback(id, dftName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals("PasswordCallback")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String echo = getAttribute(node, "echoPassword");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean b = Boolean.valueOf(echo).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster callbacks[p] = new PasswordCallback(prompt, b);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals("ChoiceCallback")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean mch = Boolean.valueOf(multiple).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (sub.getNodeName().equals("ChoiceValues")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Node ss = sub.getFirstChild().getNextSibling();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals("ConfirmationCallback")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int messageType = ConfirmationCallback.INFORMATION;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (sub.getNodeName().equals("OptionValues")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Node ss = sub.getFirstChild().getNextSibling();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals("TextInputCallback")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals("TextOutputCallback")) {
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott String value = node.getFirstChild().getNodeValue();
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott callbacks[p] = new ScriptTextOutputCallback(value);
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott } else { //default to information
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott messageType = TextOutputCallback.INFORMATION;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott callbacks[p] = new TextOutputCallback(messageType, value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals("LanguageCallback")) {
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings for (sub = node.getFirstChild(); sub != null; sub = sub.getNextSibling()) {
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings if (sub.getNodeName().equals("ChoiceValue")) {
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings } else if (PollingWaitCallback.NODE_NAME.equals(nodeName)) {
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings callbacks[p++] = PollingWaitCallback.makeCallback()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals(AuthXMLTags.HTTP_CALLBACK)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (tmpStr.equals(AuthXMLTags.HTTP_NEGO)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster negotiation= sub.getFirstChild().getNodeValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (tmpStr.equals(AuthXMLTags.HTTP_CODE)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster callbacks[p]= new HttpCallback(header,negotiation,code);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals(AuthXMLTags.REDIRECT_CALLBACK)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster getAttribute(node, AuthXMLTags.REDIRECT_METHOD);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Node ss = sub.getFirstChild().getNextSibling();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("redirectData : " + redirectData);
eaee930f8fb0c2d7d86d0ca299530cfff8b1feb8Ken Stubbings callbacks[p]= new RedirectCallback(redirectUrl, redirectData, method);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }//end of element
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }//end of switch
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Node child = node.getFirstChild(); child != null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //without this the ending tags will miss
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ((PagePropertiesCallback) callbacks[0]).setAttribute(attribute);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ((PagePropertiesCallback) callbacks[0]).setRequire(require);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ((PagePropertiesCallback) callbacks[0]).setInfoText(infoText);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //attrtable.put(order, subAttr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //requiretable.put(order, subRequire);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }//end of walk