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.Username;
27  import org.opensaml.ws.wssecurity.UsernameToken;
28  import org.opensaml.xml.XMLObject;
29  import org.opensaml.xml.util.AttributeMap;
30  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
31  
32  /**
33   * Implementation of {@link UsernameToken}.
34   */
35  public class UsernameTokenImpl extends AbstractWSSecurityObject implements UsernameToken {
36  
37      /** The <wsu:Id> attribute value. */
38      private String id;
39  
40      /** The <wsse:Username> child element. */
41      private Username username;
42      
43      /** Wildcard attributes. */
44      private AttributeMap unknownAttributes;
45      
46      /** Wildcard child elements. */
47      private IndexedXMLObjectChildrenList<XMLObject> unknownChildren;
48  
49      /**
50       * Constructor.
51       * 
52       * @param namespaceURI namespace of the element
53       * @param elementLocalName name of the element
54       * @param namespacePrefix namespace prefix of the element
55       */
56      public UsernameTokenImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
57          super(namespaceURI, elementLocalName, namespacePrefix);
58          unknownAttributes = new AttributeMap(this);
59          unknownChildren = new IndexedXMLObjectChildrenList<XMLObject>(this);
60      }
61   
62      /** {@inheritDoc} */
63      public Username getUsername() {
64          return username;
65      }
66  
67      /** {@inheritDoc} */
68      public void setUsername(Username newUsername) {
69          username = prepareForAssignment(username, newUsername);
70      }
71  
72      /** {@inheritDoc} */
73      public String getWSUId() {
74          return id;
75      }
76  
77      /** {@inheritDoc} */
78      public void setWSUId(String newId) {
79          String oldId = id;
80          id = prepareForAssignment(id, newId);
81          registerOwnID(oldId, id);
82      }
83      
84      /** {@inheritDoc} */
85      public AttributeMap getUnknownAttributes() {
86          return unknownAttributes;
87      }
88  
89      /** {@inheritDoc} */
90      public List<XMLObject> getUnknownXMLObjects() {
91          return unknownChildren;
92      }
93  
94      /** {@inheritDoc} */
95      public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
96          return (List<XMLObject>) unknownChildren.subList(typeOrName);
97      }
98      
99      /** {@inheritDoc} */
100     public List<XMLObject> getOrderedChildren() {
101         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
102         if (username != null) {
103             children.add(username);
104         }
105         
106         if (!getUnknownXMLObjects().isEmpty()) {
107             children.addAll(getUnknownXMLObjects());
108         }
109         return Collections.unmodifiableList(children);
110     }
111 
112 }