a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The contents of this file are subject to the terms
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * of the Common Development and Distribution License
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * (the License). You may not use this file except in
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * compliance with the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * You can obtain a copy of the License at
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * See the License for the specific language governing
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * permission and limitations under the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * When distributing Covered Code, include this CDDL
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Header Notice in each file and include the License file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * If applicable, add the following below the CDDL Header,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * with the fields enclosed by brackets [] replaced by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * your own identifying information:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * $Id: Extension.java,v 1.2 2008/06/25 05:46:46 qcheng Exp $
f948ca04a28ccfeed9633bf4b0fb0d2c59c37478David Luna * Portions Copyrighted 2014 ForgeRock AS
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpackage com.sun.identity.federation.message.common;
f948ca04a28ccfeed9633bf4b0fb0d2c59c37478David Lunaimport com.sun.identity.federation.common.FSUtils;
f948ca04a28ccfeed9633bf4b0fb0d2c59c37478David Lunaimport com.sun.identity.federation.common.IFSConstants;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The class <code>Extension</code> is used to create , parse
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>Extension</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @supported.all.api
f948ca04a28ccfeed9633bf4b0fb0d2c59c37478David Luna * @deprecated since 12.0.0
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor to create <code>Extension</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param children a list of XML <code>String</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws FSMsgException on error.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public Extension(List children) throws FSMsgException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor to create <code>Extension</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param element the <code>Extension</code> Element object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws FSMsgException on error.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public Extension(Element element) throws FSMsgException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FSUtils.debug.error("Extension.Extension: null input.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (!IFSConstants.EXTENSION.equals(nodeName)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FSUtils.debug.error("Extension.Extension: wrong input");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (child.getNodeType() == Node.ELEMENT_NODE) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor to create <code>Extension</code> object. Each attribute
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * value pair will be converted to a XML string. The converted XML string
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * has only one element. The local name of the element will be the key of
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the map entry and the value of the element will be the value of the map
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * entry. Both key and value of the map entry should be a
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>String</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param avpairs attribute value pairs.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws FSMsgException on error.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public Extension(Map avpairs) throws FSMsgException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns a list of XML <code>String</code> objects.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return a list of XML <code>String</code> objects.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @see #setChildren(List)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Sets a list of XML <code>String</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param children a list of XML <code>String</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @see #getChildren()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public void setChildren(List children) throws FSMsgException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Gets attribute value pairs. Each attribute value pair is converted from
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * a XML string. The XML string can have only one element. The element
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * element can't have namespace and must have a simple content. The local
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * name of the element will be the key of the map entry and the value of
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the element will be the value of the map entry. Both key and value of
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the map entry will be a <code>String</code> object. If a XML string
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * can't be converted, it will not be added to the map.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return an attribute value pairs.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((children == null) || (children.isEmpty())) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for(Iterator iter = children.iterator(); iter.hasNext(); ) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Converts attribute value pairs to a list of XML <code>String</code>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * objects. Each attribute value pair will be converted to a XML string.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The converted XML string has only one element. The local name of the
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * element will be the key of the map entry and the value of the element
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * will be the value of the map entry. Both key and value of the map entry
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * should be a <code>String</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param avpairs attribute value pairs.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws FSMsgException on error.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public void setAttributeMap(Map avpairs) throws FSMsgException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((avpairs != null) && (!avpairs.isEmpty())) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for(Iterator iter = avpairs.keySet().iterator(); iter.hasNext();) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns the <code>MinorVersion</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return the <code>MinorVersion</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @see #setMinorVersion(int)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Sets the <code>MinorVersion</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param minorVersion the <code>MinorVersion</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @see #getMinorVersion()
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public void setMinorVersion(int minorVersion) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns a String representation of the <Code>Extension</Code> element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return a string containing the valid XML for this element
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws FSMsgException if there is an error converting this object to
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public String toXMLString() throws FSMsgException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return this.toXMLString(true, false);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Creates a String representation of the <Code>Extension</Code> element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param includeNS : Determines whether or not the namespace qualifier
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * is prepended to the Element when converted
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param declareNS : Determines whether or not the namespace is declared
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * within the Element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return string containing the valid XML for this element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws FSMsgException if there is an error.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public String toXMLString(boolean includeNS, boolean declareNS)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if(minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((children != null) && (!children.isEmpty())) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for(Iterator iter = children.iterator(); iter.hasNext();) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns <code>Extension</code> object. The object is creating by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * parsing the <code>HttpServletRequest</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param request the <code>HttpServletRequest</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param prefix the string that is prepended to the key of query
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param minorVersion the <code>MinorVersion</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return <code><Extension/code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws FSMsgException if there is an error creating
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>Extension</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public static Extension parseURLEncodedRequest(HttpServletRequest request,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster String prefix, int minorVersion) throws FSMsgException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for(Enumeration e=request.getParameterNames(); e.hasMoreElements();) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster String key = paraName.substring(prefix.length());
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns an URL Encoded String.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param prefix the string that will be prepended to the key of query
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return a url encoded query string.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws FSMsgException if there is an error.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public String toURLEncodedQueryString(String prefix)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((attrMap == null) || (attrMap.isEmpty())) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for(Iterator iter = attrMap.keySet().iterator();iter.hasNext();) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster String value = URLEncDec.encode((String)attrMap.get(key));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster queryString.append(key).append(IFSConstants.EQUAL_TO)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((ns == null) && (!XMLUtils.hasElementChild(element))) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster String value = XMLUtils.getElementValue(element);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster private static void validateChildren(List children) throws FSMsgException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((children != null) && (!children.isEmpty())) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for(Iterator iter = children.iterator(); iter.hasNext(); ) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster FSUtils.debug.error("Extension.validateChildren: Error "
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster + "while parsing input xml string");