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