View Javadoc

1   /*
2    * Copyright [2007] [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.common.binding;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.joda.time.DateTime;
22  import org.opensaml.common.SAMLObject;
23  import org.opensaml.saml2.metadata.Endpoint;
24  import org.opensaml.saml2.metadata.EntityDescriptor;
25  import org.opensaml.saml2.metadata.RoleDescriptor;
26  import org.opensaml.saml2.metadata.provider.MetadataProvider;
27  import org.opensaml.ws.message.BaseMessageContext;
28  import org.opensaml.xml.security.credential.Credential;
29  import org.opensaml.xml.util.DatatypeHelper;
30  
31  /**
32   * Base implemention of {@link SAMLMessageContext}.
33   * 
34   * @param <InboundMessageType> type of inbound SAML message
35   * @param <OutboundMessageType> type of outbound SAML message
36   * @param <NameIdentifierType> type of name identifier used for subjects
37   */
38  public class BasicSAMLMessageContext<InboundMessageType extends SAMLObject, OutboundMessageType extends SAMLObject, NameIdentifierType extends SAMLObject>
39          extends BaseMessageContext implements SAMLMessageContext<InboundMessageType, OutboundMessageType, NameIdentifierType> {
40  
41      /** Gets the artifact type used for outbound messages. */
42      private byte[] artifactType;
43      
44      /** Name identifier for the Subject of the message. */
45      private NameIdentifierType subjectNameIdentifer;
46      
47      /** Local entity's ID. */
48      private String localEntityId;
49  
50      /** Local entity's metadata. */
51      private EntityDescriptor localEntityMetadata;
52  
53      /** Asserting entity's role. */
54      private QName localEntityRole;
55  
56      /** Asserting entity's role metadata. */
57      private RoleDescriptor localEntityRoleMetadata;
58  
59      /** Inbound SAML message. */
60      private InboundMessageType inboundSAMLMessage;
61  
62      /** Whether the inbound SAML message has been authenticated. */
63      private boolean inboundSAMLMessageAuthenticated;
64  
65      /** Inbound SAML message's ID. */
66      private String inboundSAMLMessageId;
67  
68      /** Inbound SAML message's issue instant. */
69      private DateTime inboundSAMLMessageIssueInstant;
70  
71      /** Inbound SAML protocol. */
72      private String inboundSAMLProtocol;
73  
74      /** Metadata provider used to lookup entity information. */
75      private MetadataProvider metdataProvider;
76  
77      /** Outbound SAML message. */
78      private OutboundMessageType outboundSAMLMessage;
79  
80      /** Outbound SAML message's ID. */
81      private String outboundSAMLMessageId;
82  
83      /** Outbound SAML message's issue instant. */
84      private DateTime outboundSAMLMessageIssueInstant;
85  
86      /** Outboud SAML message signing credential. */
87      private Credential outboundSAMLMessageSigningCredential;
88  
89      /** Outbound SAML procotol. */
90      private String outboundSAMLProtocol;
91  
92      /** Message relay state. */
93      private String relayState;
94  
95      /** Peer entity's endpoint. */
96      private Endpoint peerEntityEndpoint;
97  
98      /**Peer entity's ID. */
99      private String peerEntityId;
100 
101     /** Peer entity's metadata. */
102     private EntityDescriptor peerEntityMetadata;
103 
104     /** Peer entity's role. */
105     private QName peerEntityRole;
106 
107     /** Peer entity's role metadata. */
108     private RoleDescriptor peerEntityRoleMetadata;
109 
110     /** {@inheritDoc} */
111     public InboundMessageType getInboundSAMLMessage() {
112         return inboundSAMLMessage;
113     }
114 
115     /** {@inheritDoc} */
116     public String getInboundSAMLMessageId() {
117         return inboundSAMLMessageId;
118     }
119 
120     /** {@inheritDoc} */
121     public DateTime getInboundSAMLMessageIssueInstant() {
122         return inboundSAMLMessageIssueInstant;
123     }
124 
125     /** {@inheritDoc} */
126     public String getInboundSAMLProtocol() {
127         return inboundSAMLProtocol;
128     }
129 
130     /** {@inheritDoc} */
131     public String getLocalEntityId() {
132         return localEntityId;
133     }
134 
135     /** {@inheritDoc} */
136     public EntityDescriptor getLocalEntityMetadata() {
137         return localEntityMetadata;
138     }
139 
140     /** {@inheritDoc} */
141     public QName getLocalEntityRole() {
142         return localEntityRole;
143     }
144 
145     /** {@inheritDoc} */
146     public RoleDescriptor getLocalEntityRoleMetadata() {
147         return localEntityRoleMetadata;
148     }
149 
150     /** {@inheritDoc} */
151     public MetadataProvider getMetadataProvider() {
152         return metdataProvider;
153     }
154 
155     /** {@inheritDoc} */
156     public Credential getOuboundSAMLMessageSigningCredential() {
157         return outboundSAMLMessageSigningCredential;
158     }
159 
160     /** {@inheritDoc} */
161     public OutboundMessageType getOutboundSAMLMessage() {
162         return outboundSAMLMessage;
163     }
164 
165     /** {@inheritDoc} */
166     public String getOutboundSAMLMessageId() {
167         return outboundSAMLMessageId;
168     }
169 
170     /** {@inheritDoc} */
171     public DateTime getOutboundSAMLMessageIssueInstant() {
172         return outboundSAMLMessageIssueInstant;
173     }
174 
175     /** {@inheritDoc} */
176     public String getOutboundSAMLProtocol() {
177         return outboundSAMLProtocol;
178     }
179 
180     /** {@inheritDoc} */
181     public Endpoint getPeerEntityEndpoint() {
182         return peerEntityEndpoint;
183     }
184 
185     /** {@inheritDoc} */
186     public String getPeerEntityId() {
187         return peerEntityId;
188     }
189 
190     /** {@inheritDoc} */
191     public EntityDescriptor getPeerEntityMetadata() {
192         return peerEntityMetadata;
193     }
194 
195     /** {@inheritDoc} */
196     public QName getPeerEntityRole() {
197         return peerEntityRole;
198     }
199 
200     /** {@inheritDoc} */
201     public RoleDescriptor getPeerEntityRoleMetadata() {
202         return peerEntityRoleMetadata;
203     }
204 
205     /** {@inheritDoc} */
206     public String getRelayState() {
207         return relayState;
208     }
209 
210     /** {@inheritDoc} */
211     public NameIdentifierType getSubjectNameIdentifier() {
212         return subjectNameIdentifer;
213     }
214 
215     /** {@inheritDoc} */
216     public boolean isInboundSAMLMessageAuthenticated() {
217         return inboundSAMLMessageAuthenticated;
218     }
219 
220     /** {@inheritDoc} */
221     public void setInboundSAMLMessage(InboundMessageType message) {
222         inboundSAMLMessage = message;
223     }
224 
225     /** {@inheritDoc} */
226     public void setInboundSAMLMessageAuthenticated(boolean isAuthenticated) {
227         inboundSAMLMessageAuthenticated = isAuthenticated;
228     }
229 
230     /** {@inheritDoc} */
231     public void setInboundSAMLMessageId(String id) {
232         inboundSAMLMessageId = DatatypeHelper.safeTrimOrNullString(id);
233     }
234 
235     /** {@inheritDoc} */
236     public void setInboundSAMLMessageIssueInstant(DateTime instant) {
237         inboundSAMLMessageIssueInstant = instant;
238     }
239 
240     /** {@inheritDoc} */
241     public void setInboundSAMLProtocol(String protocol) {
242         inboundSAMLProtocol = DatatypeHelper.safeTrimOrNullString(protocol);
243     }
244 
245     /** {@inheritDoc} */
246     public void setLocalEntityId(String id) {
247         localEntityId = DatatypeHelper.safeTrimOrNullString(id);
248     }
249 
250     /** {@inheritDoc} */
251     public void setLocalEntityMetadata(EntityDescriptor metadata) {
252         localEntityMetadata = metadata;
253     }
254 
255     /** {@inheritDoc} */
256     public void setLocalEntityRole(QName role) {
257         localEntityRole = role;
258     }
259 
260     /** {@inheritDoc} */
261     public void setLocalEntityRoleMetadata(RoleDescriptor role) {
262         localEntityRoleMetadata = role;
263     }
264 
265     /** {@inheritDoc} */
266     public void setMetadataProvider(MetadataProvider provider) {
267         metdataProvider = provider;
268     }
269 
270     /** {@inheritDoc} */
271     public void setOutboundSAMLMessage(OutboundMessageType message) {
272         outboundSAMLMessage = message;
273     }
274 
275     /** {@inheritDoc} */
276     public void setOutboundSAMLMessageId(String id) {
277         outboundSAMLMessageId = DatatypeHelper.safeTrimOrNullString(id);
278     }
279 
280     /** {@inheritDoc} */
281     public void setOutboundSAMLMessageIssueInstant(DateTime instant) {
282         outboundSAMLMessageIssueInstant = instant;
283     }
284 
285     /** {@inheritDoc} */
286     public void setOutboundSAMLMessageSigningCredential(Credential credential) {
287         outboundSAMLMessageSigningCredential = credential;
288     }
289 
290     /** {@inheritDoc} */
291     public void setOutboundSAMLProtocol(String protocol) {
292         outboundSAMLProtocol = DatatypeHelper.safeTrimOrNullString(protocol);
293     }
294 
295     /** {@inheritDoc} */
296     public void setPeerEntityEndpoint(Endpoint endpoint) {
297         peerEntityEndpoint = endpoint;
298     }
299 
300     /** {@inheritDoc} */
301     public void setPeerEntityId(String id) {
302         peerEntityId = DatatypeHelper.safeTrimOrNullString(id);
303     }
304 
305     /** {@inheritDoc} */
306     public void setPeerEntityMetadata(EntityDescriptor metadata) {
307         peerEntityMetadata = metadata;
308     }
309 
310     /** {@inheritDoc} */
311     public void setPeerEntityRole(QName role) {
312         peerEntityRole = role;
313     }
314 
315     /** {@inheritDoc} */
316     public void setPeerEntityRoleMetadata(RoleDescriptor role) {
317         peerEntityRoleMetadata = role;
318     }
319 
320     /** {@inheritDoc} */
321     public void setRelayState(String state) {
322         relayState = DatatypeHelper.safeTrimOrNullString(state);
323     }
324 
325     /** {@inheritDoc} */
326     public void setSubjectNameIdentifier(NameIdentifierType identifier) {
327         subjectNameIdentifer = identifier;
328     }
329     
330     /** {@inheritDoc} */
331     public byte[] getOutboundMessageArtifactType() {
332         return artifactType;
333     }
334     
335     /** {@inheritDoc} */
336     public void setOutboundMessageArtifactType(byte[] type) {
337         artifactType = type;
338     }
339 
340     /** {@inheritDoc} */
341     public boolean isIssuerAuthenticated() {
342         return isInboundSAMLMessageAuthenticated() || super.isIssuerAuthenticated();
343     }
344 }