AMModuleProperties.java revision 8af80418ba1ec431c8027fa9668e5678658d3611
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 $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted 2011 ForgeRock AS
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;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.parsers.DocumentBuilderFactory;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.service.AuthD;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.share.AuthXMLTags;
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);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DocumentBuilder builder = factory.newDocumentBuilder();
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.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static List getModuleProperties(String fileName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster resStream = servletContext.getResourceAsStream(fileName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster resStream = Thread.currentThread().getContextClassLoader()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // remove leading '/' from fileName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // file might be empty for modules like Cert,Anonymous etc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (resStream !=null && resStream.read() == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized(moduleProps) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("getModuleProperties: Error: " ,e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMModuleProperties prop = new AMModuleProperties(fileName,
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");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int size = Integer.parseInt(getAttribute(node, "length"))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster callbacks[p] = new PagePropertiesCallback(moduleName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String prompt = sub.getFirstChild().getNodeValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster callbacks[p] = new NameCallback(prompt, 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")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (nodeName.equals("LanguageCallback")) {
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);
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