View Javadoc

1   /*
2    * Copyright 2008 Members of the EGEE Collaboration.
3    * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.opensaml.ws.wssecurity.impl;
19  
20  import java.util.ArrayList;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import javax.xml.namespace.QName;
25  
26  import org.opensaml.ws.wssecurity.IdBearing;
27  import org.opensaml.ws.wssecurity.Username;
28  import org.opensaml.ws.wssecurity.UsernameToken;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.util.AttributeMap;
31  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
32  
33  /**
34   * Implementation of {@link UsernameToken}.
35   */
36  public class UsernameTokenImpl extends AbstractWSSecurityObject implements UsernameToken {
37  
38      /** The <wsu:Id> attribute value. */
39      private String id;
40  
41      /** The <wsse:Username> child element. */
42      private Username username;
43      
44      /** Wildcard attributes. */
45      private AttributeMap unknownAttributes;
46      
47      /** Wildcard child elements. */
48      private IndexedXMLObjectChildrenList<XMLObject> unknownChildren;
49  
50      /**
51       * Constructor.
52       * 
53       * @param namespaceURI namespace of the element
54       * @param elementLocalName name of the element
55       * @param namespacePrefix namespace prefix of the element
56       */
57      public UsernameTokenImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
58          super(namespaceURI, elementLocalName, namespacePrefix);
59          unknownAttributes = new AttributeMap(this);
60          unknownChildren = new IndexedXMLObjectChildrenList<XMLObject>(this);
61      }
62   
63      /** {@inheritDoc} */
64      public Username getUsername() {
65          return username;
66      }
67  
68      /** {@inheritDoc} */
69      public void setUsername(Username newUsername) {
70          username = prepareForAssignment(username, newUsername);
71      }
72  
73      /** {@inheritDoc} */
74      public String getWSUId() {
75          return id;
76      }
77  
78      /** {@inheritDoc} */
79      public void setWSUId(String newId) {
80          String oldId = id;
81          id = prepareForAssignment(id, newId);
82          registerOwnID(oldId, id);
83          manageQualifiedAttributeNamespace(IdBearing.WSU_ID_ATTR_NAME, id != null);
84      }
85      
86      /** {@inheritDoc} */
87      public AttributeMap getUnknownAttributes() {
88          return unknownAttributes;
89      }
90  
91      /** {@inheritDoc} */
92      public List<XMLObject> getUnknownXMLObjects() {
93          return unknownChildren;
94      }
95  
96      /** {@inheritDoc} */
97      public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
98          return (List<XMLObject>) unknownChildren.subList(typeOrName);
99      }
100     
101     /** {@inheritDoc} */
102     public List<XMLObject> getOrderedChildren() {
103         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
104         if (username != null) {
105             children.add(username);
106         }
107         
108         if (!getUnknownXMLObjects().isEmpty()) {
109             children.addAll(getUnknownXMLObjects());
110         }
111         return Collections.unmodifiableList(children);
112     }
113 
114 }