View Javadoc

1   /*
2    * Copyright 2009 University Corporation for Advanced Internet Development, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.ws.wssecurity.impl;
18  
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.opensaml.ws.soap.soap11.ActorBearing;
23  import org.opensaml.ws.soap.soap11.MustUnderstandBearing;
24  import org.opensaml.ws.soap.soap12.RelayBearing;
25  import org.opensaml.ws.soap.soap12.RoleBearing;
26  import org.opensaml.ws.wssecurity.EncryptedHeader;
27  import org.opensaml.ws.wssecurity.IdBearing;
28  import org.opensaml.xml.XMLObject;
29  import org.opensaml.xml.encryption.EncryptedData;
30  import org.opensaml.xml.schema.XSBooleanValue;
31  import org.opensaml.xml.util.LazyList;
32  
33  /**
34   * Implementation of {@link EncryptedHeader}.
35   */
36  public class EncryptedHeaderImpl extends AbstractWSSecurityObject implements EncryptedHeader {
37      
38      /** EncryptedData child element. */
39      private EncryptedData encryptedData;
40      
41      /** The <code>@wsu:Id</code> atribute. */
42      private String wsuId;
43      
44      /** The <code>@soap11:mustUnderstand</code> atribute. */
45      private XSBooleanValue soap11MustUnderstand;
46      
47      /** The <code>@soap11:actor</code> atribute. */
48      private String soap11Actor;
49      
50      /** The <code>@soap12:mustUnderstand</code> atribute. */
51      private XSBooleanValue soap12MustUnderstand;
52      
53      /** The <code>@soap12:role</code> atribute. */
54      private String soap12Role;
55      
56      /** The <code>@soap12:relay</code> atribute. */
57      private XSBooleanValue soap12Relay;
58      
59      /**
60       * Constructor.
61       * 
62       * @param namespaceURI namespace of the element
63       * @param elementLocalName name of the element
64       * @param namespacePrefix namespace prefix of the element
65       */
66      public EncryptedHeaderImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
67          super(namespaceURI, elementLocalName, namespacePrefix);
68      }
69  
70      /** {@inheritDoc} */
71      public EncryptedData getEncryptedData() {
72          return encryptedData;
73      }
74  
75      /** {@inheritDoc} */
76      public void setEncryptedData(EncryptedData newEncryptedData) {
77          encryptedData = prepareForAssignment(encryptedData, newEncryptedData);
78      }
79  
80      /** {@inheritDoc} */
81      public String getWSUId() {
82          return wsuId;
83      }
84  
85      /** {@inheritDoc} */
86      public void setWSUId(String newId) {
87          String oldId = wsuId;
88          wsuId = prepareForAssignment(wsuId, newId);
89          registerOwnID(oldId, wsuId);
90          manageQualifiedAttributeNamespace(IdBearing.WSU_ID_ATTR_NAME, wsuId != null);
91      }
92  
93      /** {@inheritDoc} */
94      public Boolean isSOAP11MustUnderstand() {
95          if (soap11MustUnderstand != null) {
96              return soap11MustUnderstand.getValue();
97          }
98          return Boolean.FALSE;
99      }
100 
101     /** {@inheritDoc} */
102     public XSBooleanValue isSOAP11MustUnderstandXSBoolean() {
103         return soap11MustUnderstand;
104     }
105 
106     /** {@inheritDoc} */
107     public void setSOAP11MustUnderstand(Boolean newMustUnderstand) {
108         if (newMustUnderstand != null) {
109             soap11MustUnderstand = prepareForAssignment(soap11MustUnderstand, 
110                     new XSBooleanValue(newMustUnderstand, true));
111         } else {
112             soap11MustUnderstand = prepareForAssignment(soap11MustUnderstand, null);
113         }
114         manageQualifiedAttributeNamespace(MustUnderstandBearing.SOAP11_MUST_UNDERSTAND_ATTR_NAME, 
115                 soap11MustUnderstand != null);
116     }
117 
118     /** {@inheritDoc} */
119     public void setSOAP11MustUnderstand(XSBooleanValue newMustUnderstand) {
120             soap11MustUnderstand = prepareForAssignment(soap11MustUnderstand, newMustUnderstand);
121             manageQualifiedAttributeNamespace(MustUnderstandBearing.SOAP11_MUST_UNDERSTAND_ATTR_NAME, 
122                     soap11MustUnderstand != null);
123     }
124 
125     /** {@inheritDoc} */
126     public String getSOAP11Actor() {
127         return soap11Actor;
128     }
129 
130     /** {@inheritDoc} */
131     public void setSOAP11Actor(String newActor) {
132         soap11Actor = prepareForAssignment(soap11Actor, newActor);
133         manageQualifiedAttributeNamespace(ActorBearing.SOAP11_ACTOR_ATTR_NAME, soap11Actor != null);
134     }
135     
136     /** {@inheritDoc} */
137     public Boolean isSOAP12MustUnderstand() {
138         if (soap12MustUnderstand != null) {
139             return soap12MustUnderstand.getValue();
140         }
141         return Boolean.FALSE;
142     }
143 
144     /** {@inheritDoc} */
145     public XSBooleanValue isSOAP12MustUnderstandXSBoolean() {
146         return soap12MustUnderstand;
147     }
148 
149     /** {@inheritDoc} */
150     public void setSOAP12MustUnderstand(Boolean newMustUnderstand) {
151         if (newMustUnderstand != null) {
152             soap12MustUnderstand = prepareForAssignment(soap12MustUnderstand, 
153                     new XSBooleanValue(newMustUnderstand, false));
154         } else {
155             soap12MustUnderstand = prepareForAssignment(soap12MustUnderstand, null);
156         }
157         manageQualifiedAttributeNamespace(org.opensaml.ws.soap.soap12.MustUnderstandBearing.SOAP12_MUST_UNDERSTAND_ATTR_NAME, 
158                 soap12MustUnderstand != null);
159     }
160 
161     /** {@inheritDoc} */
162     public void setSOAP12MustUnderstand(XSBooleanValue newMustUnderstand) {
163             soap12MustUnderstand = prepareForAssignment(soap12MustUnderstand, newMustUnderstand);
164             manageQualifiedAttributeNamespace(org.opensaml.ws.soap.soap12.MustUnderstandBearing.SOAP12_MUST_UNDERSTAND_ATTR_NAME, 
165                     soap12MustUnderstand != null);
166     }
167 
168     /** {@inheritDoc} */
169     public String getSOAP12Role() {
170         return soap12Role;
171     }
172 
173     /** {@inheritDoc} */
174     public void setSOAP12Role(String newRole) {
175         soap12Role = prepareForAssignment(soap12Role, newRole);
176         manageQualifiedAttributeNamespace(RoleBearing.SOAP12_ROLE_ATTR_NAME, soap12Role != null);
177     }
178 
179     /** {@inheritDoc} */
180     public Boolean isSOAP12Relay() {
181         if (soap12Relay != null) {
182             return soap12Relay.getValue();
183         }
184         return Boolean.FALSE;
185     }
186 
187     /** {@inheritDoc} */
188     public XSBooleanValue isSOAP12RelayXSBoolean() {
189         return soap12Relay;
190     }
191 
192     /** {@inheritDoc} */
193     public void setSOAP12Relay(Boolean newRelay) {
194         if (newRelay != null) {
195             soap12Relay = prepareForAssignment(soap12Relay, 
196                     new XSBooleanValue(newRelay, false));
197         } else {
198             soap12Relay = prepareForAssignment(soap12Relay, null);
199         }
200         manageQualifiedAttributeNamespace(RelayBearing.SOAP12_RELAY_ATTR_NAME, soap12Relay != null);
201     }
202 
203     /** {@inheritDoc} */
204     public void setSOAP12Relay(XSBooleanValue newRelay) {
205             soap12Relay = prepareForAssignment(soap12Relay, newRelay);
206             manageQualifiedAttributeNamespace(RelayBearing.SOAP12_RELAY_ATTR_NAME, soap12Relay != null);
207     }
208 
209     /** {@inheritDoc} */
210     public List<XMLObject> getOrderedChildren() {
211         LazyList<XMLObject> children = new LazyList<XMLObject>();
212         if (encryptedData != null) {
213             children.add(encryptedData);
214         }
215         return Collections.unmodifiableList(children);
216     }
217 
218 }