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.wssecurity.EncryptedHeader;
23  import org.opensaml.xml.XMLObject;
24  import org.opensaml.xml.encryption.EncryptedData;
25  import org.opensaml.xml.schema.XSBooleanValue;
26  import org.opensaml.xml.util.LazyList;
27  
28  /**
29   * Implementation of {@link EncryptedHeader}.
30   */
31  public class EncryptedHeaderImpl extends AbstractWSSecurityObject implements EncryptedHeader {
32      
33      /** EncryptedData child element. */
34      private EncryptedData encryptedData;
35      
36      /** The <code>@wsu:Id</code> atribute. */
37      private String wsuId;
38      
39      /** The <code>@soap11:mustUnderstand</code> atribute. */
40      private XSBooleanValue soap11MustUnderstand;
41      
42      /** The <code>@soap11:actor</code> atribute. */
43      private String soap11Actor;
44      
45      /** The <code>@soap12:mustUnderstand</code> atribute. */
46      private XSBooleanValue soap12MustUnderstand;
47      
48      /** The <code>@soap12:role</code> atribute. */
49      private String soap12Role;
50      
51      /** The <code>@soap12:relay</code> atribute. */
52      private XSBooleanValue soap12Relay;
53      
54      /**
55       * Constructor.
56       * 
57       * @param namespaceURI namespace of the element
58       * @param elementLocalName name of the element
59       * @param namespacePrefix namespace prefix of the element
60       */
61      public EncryptedHeaderImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
62          super(namespaceURI, elementLocalName, namespacePrefix);
63      }
64  
65      /** {@inheritDoc} */
66      public EncryptedData getEncryptedData() {
67          return encryptedData;
68      }
69  
70      /** {@inheritDoc} */
71      public void setEncryptedData(EncryptedData newEncryptedData) {
72          encryptedData = prepareForAssignment(encryptedData, newEncryptedData);
73      }
74  
75      /** {@inheritDoc} */
76      public String getWSUId() {
77          return wsuId;
78      }
79  
80      /** {@inheritDoc} */
81      public void setWSUId(String newId) {
82          String oldId = wsuId;
83          wsuId = prepareForAssignment(wsuId, newId);
84          registerOwnID(oldId, wsuId);
85      }
86  
87      /** {@inheritDoc} */
88      public Boolean isSOAP11MustUnderstand() {
89          if (soap11MustUnderstand != null) {
90              return soap11MustUnderstand.getValue();
91          }
92          return Boolean.FALSE;
93      }
94  
95      /** {@inheritDoc} */
96      public XSBooleanValue isSOAP11MustUnderstandXSBoolean() {
97          return soap11MustUnderstand;
98      }
99  
100     /** {@inheritDoc} */
101     public void setSOAP11MustUnderstand(Boolean newMustUnderstand) {
102         if (newMustUnderstand != null) {
103             soap11MustUnderstand = prepareForAssignment(soap11MustUnderstand, 
104                     new XSBooleanValue(newMustUnderstand, true));
105         } else {
106             soap11MustUnderstand = prepareForAssignment(soap11MustUnderstand, null);
107         }
108     }
109 
110     /** {@inheritDoc} */
111     public void setSOAP11MustUnderstand(XSBooleanValue newMustUnderstand) {
112             soap11MustUnderstand = prepareForAssignment(soap11MustUnderstand, newMustUnderstand);
113     }
114 
115     /** {@inheritDoc} */
116     public String getSOAP11Actor() {
117         return soap11Actor;
118     }
119 
120     /** {@inheritDoc} */
121     public void setSOAP11Actor(String newActor) {
122         soap11Actor = prepareForAssignment(soap11Actor, newActor);
123     }
124     
125     /** {@inheritDoc} */
126     public Boolean isSOAP12MustUnderstand() {
127         if (soap12MustUnderstand != null) {
128             return soap12MustUnderstand.getValue();
129         }
130         return Boolean.FALSE;
131     }
132 
133     /** {@inheritDoc} */
134     public XSBooleanValue isSOAP12MustUnderstandXSBoolean() {
135         return soap12MustUnderstand;
136     }
137 
138     /** {@inheritDoc} */
139     public void setSOAP12MustUnderstand(Boolean newMustUnderstand) {
140         if (newMustUnderstand != null) {
141             soap12MustUnderstand = prepareForAssignment(soap12MustUnderstand, 
142                     new XSBooleanValue(newMustUnderstand, false));
143         } else {
144             soap12MustUnderstand = prepareForAssignment(soap12MustUnderstand, null);
145         }
146     }
147 
148     /** {@inheritDoc} */
149     public void setSOAP12MustUnderstand(XSBooleanValue newMustUnderstand) {
150             soap12MustUnderstand = prepareForAssignment(soap12MustUnderstand, newMustUnderstand);
151     }
152 
153     /** {@inheritDoc} */
154     public String getSOAP12Role() {
155         return soap12Role;
156     }
157 
158     /** {@inheritDoc} */
159     public void setSOAP12Role(String newRole) {
160         soap12Role = prepareForAssignment(soap12Role, newRole);
161     }
162 
163     /** {@inheritDoc} */
164     public Boolean isSOAP12Relay() {
165         if (soap12Relay != null) {
166             return soap12Relay.getValue();
167         }
168         return Boolean.FALSE;
169     }
170 
171     /** {@inheritDoc} */
172     public XSBooleanValue isSOAP12RelayXSBoolean() {
173         return soap12Relay;
174     }
175 
176     /** {@inheritDoc} */
177     public void setSOAP12Relay(Boolean newRelay) {
178         if (newRelay != null) {
179             soap12Relay = prepareForAssignment(soap12Relay, 
180                     new XSBooleanValue(newRelay, false));
181         } else {
182             soap12Relay = prepareForAssignment(soap12Relay, null);
183         }
184     }
185 
186     /** {@inheritDoc} */
187     public void setSOAP12Relay(XSBooleanValue newRelay) {
188             soap12Relay = prepareForAssignment(soap12Relay, newRelay);
189     }
190 
191     /** {@inheritDoc} */
192     public List<XMLObject> getOrderedChildren() {
193         LazyList<XMLObject> children = new LazyList<XMLObject>();
194         if (encryptedData != null) {
195             children.add(encryptedData);
196         }
197         return Collections.unmodifiableList(children);
198     }
199 
200 }