001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: Parameter.java,v 1.2 2008/06/25 05:47:08 qcheng Exp $
026 * Portions Copyrighted 2014 ForgeRock AS.
027 */
028
029
030package com.sun.identity.liberty.ws.authnsvc.protocol;
031
032import org.w3c.dom.Document;
033import org.w3c.dom.Element;
034
035import com.sun.identity.shared.xml.XMLUtils;
036import com.sun.identity.liberty.ws.authnsvc.AuthnSvcConstants;
037import com.sun.identity.liberty.ws.authnsvc.AuthnSvcException;
038
039/**
040 * The <code>Parameter</code> class represents 'Parameter' element in
041 * 'Transform' element in 'PasswordTransforms' element defined in
042 * Authentication Service schema.
043 * @supported.all.api
044 * @deprecated since 12.0.0
045 */
046@Deprecated
047public class Parameter {
048
049    /**
050     * Parameter name 'length'
051     */
052    public static final String NAME_LENGTH = "length";
053
054    /**
055     * Parameter name 'allowed'
056     */
057    public static final String NAME_ALLOWED = "allowed";
058
059    private String name = null;
060    private String value = null;
061
062    /**
063     * Constructor takes the value of 'name' attribute and value
064     * of 'Transform' element.
065     * @param name value of 'name' attribute
066     * @param value value of 'Transform' element
067     */
068    public Parameter(String name, String value) {
069        this.name = name;
070        this.value = value;
071    }
072
073    /**
074     * Constructor takes a <code>org.w3c.dom.Element</code>.
075     * @param element a Parameter element
076     * @exception AuthnSvcException if an error occurs while parsing
077     *                      the Parameter element
078     */
079    Parameter(Element element) throws AuthnSvcException
080    {
081        name = XMLUtils.getNodeAttributeValue(element,
082                                              AuthnSvcConstants.ATTR_NAME);
083        if (name == null || name.length() == 0) {
084            throw new AuthnSvcException("missingNamePM");
085        }
086
087        value = XMLUtils.getElementValue(element);
088    }
089
090    /**
091     * Returns value of 'name' attribute.
092     * @return value of 'name' attribute
093     * @see #setName(String)
094     */
095    public String getName()
096    {
097        return name;
098    }
099
100    /**
101     * Returns value of 'Parameter' element.
102     * @return value of 'Parameter' element
103     * @see #setValue(String)
104     */
105    public String getValue()
106    {
107        return value;
108    }
109
110    /**
111     * Sets value of 'name' attribute.
112     * @param name value of 'name' attribute
113     * @see #getName()
114     */
115    public void setName(String name)
116    {
117        this.name = name;
118    }
119
120    /**
121     * Sets value of 'Parameter' element.
122     * @param value value of 'Parameter' element
123     * @see #getValue()
124     */
125    public void setValue(String value)
126    {
127        this.value = value;
128    }
129
130    /**
131     * Converts this to <code>org.w3c.dom.Element</code> and add to
132     * parent Transform Element.
133     * @param tfE parent Transform Element
134     */
135    void addToParent(Element tfE) throws AuthnSvcException
136    {
137        if (name == null || name.length() == 0) {
138            throw new AuthnSvcException("missingNamePM");
139        }
140
141        Document doc = tfE.getOwnerDocument();
142        Element pmE = doc.createElementNS(AuthnSvcConstants.NS_AUTHN_SVC,
143                                          AuthnSvcConstants.PTAG_PARAMETER);
144        tfE.appendChild(pmE);
145
146        pmE.setAttributeNS(null, AuthnSvcConstants.ATTR_NAME, name);
147
148        if (value != null) {
149            pmE.appendChild(doc.createTextNode(value));
150        }
151    }
152}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.