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: PasswordTransforms.java,v 1.2 2008/06/25 05:47:08 qcheng Exp $ 026 * Portions Copyrighted 2014 ForgeRock AS. 027 */ 028 029package com.sun.identity.liberty.ws.authnsvc.protocol; 030 031import java.util.ArrayList; 032import java.util.Iterator; 033import java.util.List; 034 035import org.w3c.dom.Document; 036import org.w3c.dom.Element; 037import org.w3c.dom.Node; 038import org.w3c.dom.NodeList; 039 040import com.sun.identity.liberty.ws.authnsvc.AuthnSvcConstants; 041import com.sun.identity.liberty.ws.authnsvc.AuthnSvcException; 042 043/** 044 * The <code>PasswordTransforms</code> class represents 'PasswordTransforms' 045 * element defined in Authentication Service schema. 046 * 047 * @supported.all.api 048 * @deprecated since 12.0.0 049 */ 050@Deprecated 051public class PasswordTransforms { 052 053 private List transforms = null; 054 055 /** 056 * This is the default constructor. 057 */ 058 public PasswordTransforms(List transforms) 059 { 060 this.transforms = transforms; 061 } 062 063 /** 064 * This constructor takes a <code>org.w3c.dom.Element</code>. 065 * @param element a PasswordTransforms element 066 * @exception AuthnSvcException if an error occurs while parsing the 067 * PasswordTransforms element 068 */ 069 PasswordTransforms(Element element) throws AuthnSvcException 070 { 071 NodeList nl = element.getChildNodes(); 072 int length = nl.getLength(); 073 074 for(int i = 0; i < length; i++) { 075 Node child = nl.item(i); 076 if (child.getNodeType() == Node.ELEMENT_NODE) { 077 Element childElement = (Element)child; 078 String localName = childElement.getLocalName(); 079 String namespaceURI = childElement.getNamespaceURI(); 080 081 if (AuthnSvcConstants.NS_AUTHN_SVC.equals(namespaceURI) && 082 AuthnSvcConstants.TAG_TRANSFORM.equals(localName)) { 083 084 Transform tf = Transform.getTransform(childElement); 085 if (transforms == null) { 086 transforms = new ArrayList(); 087 } 088 transforms.add(tf); 089 } else { 090 throw new AuthnSvcException("invalidChildPT"); 091 } 092 } 093 } 094 } 095 096 /** 097 * Returns a list of child 'Transforms' Elements 098 * @return a list of child 'Transforms' Elements 099 * @see #setTransforms(List) 100 */ 101 public List getTransforms() 102 { 103 return transforms; 104 } 105 106 /** 107 * Sets a list of child 'Transforms' Elements. 108 * @param transforms a list of child 'Transforms' Element 109 * @see #getTransforms() 110 */ 111 public void setTransforms(List transforms) 112 { 113 this.transforms = transforms; 114 } 115 116 /** 117 * Converts this to <code>org.w3c.dom.Element</code> and add to 118 * parent SASLResponse Element. 119 * @param respE parent SASLResponse Element 120 * @exception AuthnSvcException if there is no child 121 */ 122 void addToParent(Element respE) throws AuthnSvcException 123 { 124 if (transforms == null || transforms.isEmpty()) { 125 throw new AuthnSvcException("noChildPT"); 126 } 127 Document doc = respE.getOwnerDocument(); 128 Element ptE = doc.createElementNS( 129 AuthnSvcConstants.NS_AUTHN_SVC, 130 AuthnSvcConstants.PTAG_PASSWORD_TRANSFORMS); 131 respE.appendChild(ptE); 132 133 for(Iterator iter = transforms.iterator(); iter.hasNext(); ) { 134 Transform tf = (Transform)iter.next(); 135 tf.addToParent(ptE); 136 } 137 } 138}