Clean up AuthN state better in the event of a failure
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / idp / profile / saml2 / SSOProfileHandler.java
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 edu.internet2.middleware.shibboleth.idp.profile.saml2;
18
19 import java.io.IOException;
20 import java.util.ArrayList;
21
22 import javax.servlet.RequestDispatcher;
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpSession;
26
27 import org.opensaml.common.SAMLObjectBuilder;
28 import org.opensaml.common.binding.decoding.SAMLMessageDecoder;
29 import org.opensaml.common.xml.SAMLConstants;
30 import org.opensaml.saml2.binding.AuthnResponseEndpointSelector;
31 import org.opensaml.saml2.core.AuthnContext;
32 import org.opensaml.saml2.core.AuthnContextClassRef;
33 import org.opensaml.saml2.core.AuthnContextDeclRef;
34 import org.opensaml.saml2.core.AuthnRequest;
35 import org.opensaml.saml2.core.AuthnStatement;
36 import org.opensaml.saml2.core.RequestedAuthnContext;
37 import org.opensaml.saml2.core.Response;
38 import org.opensaml.saml2.core.Statement;
39 import org.opensaml.saml2.core.StatusCode;
40 import org.opensaml.saml2.core.SubjectLocality;
41 import org.opensaml.saml2.metadata.AssertionConsumerService;
42 import org.opensaml.saml2.metadata.Endpoint;
43 import org.opensaml.saml2.metadata.EntityDescriptor;
44 import org.opensaml.saml2.metadata.IDPSSODescriptor;
45 import org.opensaml.saml2.metadata.SPSSODescriptor;
46 import org.opensaml.saml2.metadata.provider.MetadataProvider;
47 import org.opensaml.saml2.metadata.provider.MetadataProviderException;
48 import org.opensaml.ws.message.decoder.MessageDecodingException;
49 import org.opensaml.ws.transport.http.HTTPInTransport;
50 import org.opensaml.ws.transport.http.HTTPOutTransport;
51 import org.opensaml.ws.transport.http.HttpServletRequestAdapter;
52 import org.opensaml.ws.transport.http.HttpServletResponseAdapter;
53 import org.opensaml.xml.io.MarshallingException;
54 import org.opensaml.xml.io.UnmarshallingException;
55 import org.opensaml.xml.security.SecurityException;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58
59 import edu.internet2.middleware.shibboleth.common.profile.ProfileException;
60 import edu.internet2.middleware.shibboleth.common.relyingparty.ProfileConfiguration;
61 import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration;
62 import edu.internet2.middleware.shibboleth.common.relyingparty.provider.saml2.SSOConfiguration;
63 import edu.internet2.middleware.shibboleth.common.util.HttpHelper;
64 import edu.internet2.middleware.shibboleth.idp.authn.LoginContext;
65 import edu.internet2.middleware.shibboleth.idp.authn.Saml2LoginContext;
66
67 /** SAML 2.0 SSO request profile handler. */
68 public class SSOProfileHandler extends AbstractSAML2ProfileHandler {
69
70     /** Class logger. */
71     private final Logger log = LoggerFactory.getLogger(SSOProfileHandler.class);
72
73     /** Builder of AuthnStatement objects. */
74     private SAMLObjectBuilder<AuthnStatement> authnStatementBuilder;
75
76     /** Builder of AuthnContext objects. */
77     private SAMLObjectBuilder<AuthnContext> authnContextBuilder;
78
79     /** Builder of AuthnContextClassRef objects. */
80     private SAMLObjectBuilder<AuthnContextClassRef> authnContextClassRefBuilder;
81
82     /** Builder of AuthnContextDeclRef objects. */
83     private SAMLObjectBuilder<AuthnContextDeclRef> authnContextDeclRefBuilder;
84
85     /** Builder of SubjectLocality objects. */
86     private SAMLObjectBuilder<SubjectLocality> subjectLocalityBuilder;
87
88     /** URL of the authentication manager servlet. */
89     private String authenticationManagerPath;
90
91     /** URI of request decoder. */
92     private String decodingBinding;
93
94     /**
95      * Constructor.
96      * 
97      * @param authnManagerPath path to the authentication manager servlet
98      */
99     @SuppressWarnings("unchecked")
100     public SSOProfileHandler(String authnManagerPath) {
101         super();
102
103         authenticationManagerPath = authnManagerPath;
104
105         authnStatementBuilder = (SAMLObjectBuilder<AuthnStatement>) getBuilderFactory().getBuilder(
106                 AuthnStatement.DEFAULT_ELEMENT_NAME);
107         authnContextBuilder = (SAMLObjectBuilder<AuthnContext>) getBuilderFactory().getBuilder(
108                 AuthnContext.DEFAULT_ELEMENT_NAME);
109         authnContextClassRefBuilder = (SAMLObjectBuilder<AuthnContextClassRef>) getBuilderFactory().getBuilder(
110                 AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
111         authnContextDeclRefBuilder = (SAMLObjectBuilder<AuthnContextDeclRef>) getBuilderFactory().getBuilder(
112                 AuthnContextDeclRef.DEFAULT_ELEMENT_NAME);
113         subjectLocalityBuilder = (SAMLObjectBuilder<SubjectLocality>) getBuilderFactory().getBuilder(
114                 SubjectLocality.DEFAULT_ELEMENT_NAME);
115     }
116
117     /** {@inheritDoc} */
118     public String getProfileId() {
119         return "urn:mace:shibboleth:2.0:idp:profiles:saml2:request:sso";
120     }
121
122     /** {@inheritDoc} */
123     public void processRequest(HTTPInTransport inTransport, HTTPOutTransport outTransport) throws ProfileException {
124         HttpServletRequest servletRequest = ((HttpServletRequestAdapter) inTransport).getWrappedRequest();
125         HttpSession httpSession = servletRequest.getSession(true);
126         LoginContext loginContext = (LoginContext) httpSession.getAttribute(LoginContext.LOGIN_CONTEXT_KEY);
127
128         if (loginContext == null) {
129             log.debug("User session does not contain a login context, processing as first leg of request");
130             performAuthentication(inTransport, outTransport);
131         }else if (!loginContext.isPrincipalAuthenticated()){
132             log.debug("User session contained a login context but user was not authenticated, processing as first leg of request");
133             performAuthentication(inTransport, outTransport);
134         } else {
135             log.debug("User session contains a login context, processing as second leg of request");
136             completeAuthenticationRequest(inTransport, outTransport);
137         }
138     }
139
140     /**
141      * Creates a {@link Saml2LoginContext} an sends the request off to the AuthenticationManager to begin the process of
142      * authenticating the user.
143      * 
144      * @param inTransport inbound request transport
145      * @param outTransport outbound response transport
146      * 
147      * @throws ProfileException thrown if there is a problem creating the login context and transferring control to the
148      *             authentication manager
149      */
150     protected void performAuthentication(HTTPInTransport inTransport, HTTPOutTransport outTransport)
151             throws ProfileException {
152         HttpServletRequest servletRequest = ((HttpServletRequestAdapter) inTransport).getWrappedRequest();
153         HttpSession httpSession = servletRequest.getSession();
154
155         try {
156             SSORequestContext requestContext = decodeRequest(inTransport, outTransport);
157
158             String relyingPartyId = requestContext.getInboundMessageIssuer();
159             RelyingPartyConfiguration rpConfig = getRelyingPartyConfiguration(relyingPartyId);
160             ProfileConfiguration ssoConfig = rpConfig.getProfileConfiguration(SSOConfiguration.PROFILE_ID);
161             if (ssoConfig == null) {
162                 log.error("SAML 2 SSO profile is not configured for relying party "
163                         + requestContext.getInboundMessageIssuer());
164                 throw new ProfileException("SAML 2 SSO profile is not configured for relying party "
165                         + requestContext.getInboundMessageIssuer());
166             }
167
168             log.debug("Creating login context and transferring control to authentication engine");
169             Saml2LoginContext loginContext = new Saml2LoginContext(relyingPartyId, requestContext.getRelayState(),
170                     requestContext.getInboundSAMLMessage());
171             loginContext.setAuthenticationEngineURL(authenticationManagerPath);
172             loginContext.setProfileHandlerURL(HttpHelper.getRequestUriWithoutContext(servletRequest));
173             if (loginContext.getRequestedAuthenticationMethods().size() == 0) {
174                 loginContext.getRequestedAuthenticationMethods().add(rpConfig.getDefaultAuthenticationMethod());
175             }
176             
177             httpSession.setAttribute(Saml2LoginContext.LOGIN_CONTEXT_KEY, loginContext);
178             RequestDispatcher dispatcher = servletRequest.getRequestDispatcher(authenticationManagerPath);
179             dispatcher.forward(servletRequest, ((HttpServletResponseAdapter) outTransport).getWrappedResponse());
180         } catch (MarshallingException e) {
181             httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
182             log.error("Unable to marshall authentication request context");
183             throw new ProfileException("Unable to marshall authentication request context", e);
184         } catch (IOException ex) {
185             httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
186             log.error("Error forwarding SAML 2 AuthnRequest to AuthenticationManager", ex);
187             throw new ProfileException("Error forwarding SAML 2 AuthnRequest to AuthenticationManager", ex);
188         } catch (ServletException ex) {
189             httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
190             log.error("Error forwarding SAML 2 AuthnRequest to AuthenticationManager", ex);
191             throw new ProfileException("Error forwarding SAML 2 AuthnRequest to AuthenticationManager", ex);
192         }
193     }
194
195     /**
196      * Creates a response to the {@link AuthnRequest} and sends the user, with response in tow, back to the relying
197      * party after they've been authenticated.
198      * 
199      * @param inTransport inbound message transport
200      * @param outTransport outbound message transport
201      * 
202      * @throws ProfileException thrown if the response can not be created and sent back to the relying party
203      */
204     protected void completeAuthenticationRequest(HTTPInTransport inTransport, HTTPOutTransport outTransport)
205             throws ProfileException {
206         HttpServletRequest servletRequest = ((HttpServletRequestAdapter) inTransport).getWrappedRequest();
207         HttpSession httpSession = servletRequest.getSession();
208
209         Saml2LoginContext loginContext = (Saml2LoginContext) httpSession.getAttribute(LoginContext.LOGIN_CONTEXT_KEY);
210         httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
211
212         SSORequestContext requestContext = buildRequestContext(loginContext, inTransport, outTransport);
213
214         checkSamlVersion(requestContext);
215
216         Response samlResponse;
217         try {
218             if (loginContext.getPrincipalName() == null) {
219                 log.error("User's login context did not contain a principal, user considered unauthenticiated.");
220                 requestContext
221                         .setFailureStatus(buildStatus(StatusCode.RESPONDER_URI, StatusCode.AUTHN_FAILED_URI, null));
222                 throw new ProfileException("User failed authentication");
223             }
224
225             resolveAttributes(requestContext);
226
227             ArrayList<Statement> statements = new ArrayList<Statement>();
228             statements.add(buildAuthnStatement(requestContext));
229             if (requestContext.getProfileConfiguration().includeAttributeStatement()
230                     && !requestContext.getPrincipalAttributes().isEmpty()) {
231                 requestContext.setRequestedAttributes(requestContext.getPrincipalAttributes().keySet());
232                 statements.add(buildAttributeStatement(requestContext));
233             }
234
235             samlResponse = buildResponse(requestContext, "urn:oasis:names:tc:SAML:2.0:cm:bearer", statements);
236         } catch (ProfileException e) {
237             samlResponse = buildErrorResponse(requestContext);
238         }
239
240         requestContext.setOutboundSAMLMessage(samlResponse);
241         requestContext.setOutboundSAMLMessageId(samlResponse.getID());
242         requestContext.setOutboundSAMLMessageIssueInstant(samlResponse.getIssueInstant());
243         encodeResponse(requestContext);
244         writeAuditLogEntry(requestContext);
245     }
246
247     /**
248      * Decodes an incoming request and stores the information in a created request context.
249      * 
250      * @param inTransport inbound transport
251      * @param outTransport outbound transport
252      * 
253      * @return request context with decoded information
254      * 
255      * @throws ProfileException thrown if the incomming message failed decoding
256      */
257     protected SSORequestContext decodeRequest(HTTPInTransport inTransport, HTTPOutTransport outTransport)
258             throws ProfileException {
259         log.debug("Decoding message with decoder binding {}", decodingBinding);
260
261         SSORequestContext requestContext = new SSORequestContext();
262         requestContext.setMetadataProvider(getMetadataProvider());
263         requestContext.setSecurityPolicyResolver(getSecurityPolicyResolver());
264
265         requestContext.setCommunicationProfileId(SSOConfiguration.PROFILE_ID);
266         requestContext.setInboundMessageTransport(inTransport);
267         requestContext.setInboundSAMLProtocol(SAMLConstants.SAML20P_NS);
268         requestContext.setPeerEntityRole(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
269
270         requestContext.setOutboundMessageTransport(outTransport);
271         requestContext.setOutboundSAMLProtocol(SAMLConstants.SAML20P_NS);
272
273         try {
274             SAMLMessageDecoder decoder = getMessageDecoders().get(getInboundBinding());
275             requestContext.setMessageDecoder(decoder);
276             decoder.decode(requestContext);
277             return requestContext;
278         } catch (MessageDecodingException e) {
279             log.error("Error decoding authentication request message", e);
280             throw new ProfileException("Error decoding authentication request message", e);
281         } catch (SecurityException e) {
282             log.error("Message did not meet security requirements", e);
283             throw new ProfileException("Message did not meet security requirements", e);
284         }
285     }
286
287     /**
288      * Creates an authentication request context from the current environmental information.
289      * 
290      * @param loginContext current login context
291      * @param in inbound transport
292      * @param out outbount transport
293      * 
294      * @return created authentication request context
295      * 
296      * @throws ProfileException thrown if there is a problem creating the context
297      */
298     protected SSORequestContext buildRequestContext(Saml2LoginContext loginContext, HTTPInTransport in,
299             HTTPOutTransport out) throws ProfileException {
300         SSORequestContext requestContext = new SSORequestContext();
301
302         requestContext.setMessageDecoder(getMessageDecoders().get(getInboundBinding()));
303
304         requestContext.setLoginContext(loginContext);
305         requestContext.setPrincipalName(loginContext.getPrincipalName());
306         requestContext.setPrincipalAuthenticationMethod(loginContext.getAuthenticationMethod());
307         requestContext.setUserSession(getUserSession(in));
308         requestContext.setRelayState(loginContext.getRelayState());
309
310         requestContext.setInboundMessageTransport(in);
311         requestContext.setInboundSAMLProtocol(SAMLConstants.SAML20P_NS);
312
313         try {
314             requestContext.setInboundMessage(loginContext.getAuthenticationRequest());
315             requestContext.setInboundSAMLMessage(loginContext.getAuthenticationRequest());
316             requestContext.setInboundSAMLMessageId(loginContext.getAuthenticationRequest().getID());
317         } catch (UnmarshallingException e) {
318             log.error("Unable to unmarshall authentication request context");
319             requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER_URI, null,
320                     "Error recovering request state"));
321             throw new ProfileException("Error recovering request state", e);
322         }
323
324         requestContext.setOutboundMessageTransport(out);
325         requestContext.setOutboundSAMLProtocol(SAMLConstants.SAML20P_NS);
326
327         MetadataProvider metadataProvider = getMetadataProvider();
328         requestContext.setMetadataProvider(metadataProvider);
329
330         String relyingPartyId = loginContext.getRelyingPartyId();
331         requestContext.setInboundMessageIssuer(relyingPartyId);
332         try {
333             EntityDescriptor relyingPartyMetadata = metadataProvider.getEntityDescriptor(relyingPartyId);
334             if (relyingPartyMetadata != null) {
335                 requestContext.setPeerEntityMetadata(relyingPartyMetadata);
336                 requestContext.setPeerEntityRole(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
337                 requestContext.setPeerEntityRoleMetadata(relyingPartyMetadata
338                         .getSPSSODescriptor(SAMLConstants.SAML20P_NS));
339             }
340         } catch (MetadataProviderException e) {
341             log.error("Unable to locate metadata for relying party");
342             requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER_URI, null,
343                     "Error locating relying party metadata"));
344             throw new ProfileException("Error locating relying party metadata");
345         }
346
347         RelyingPartyConfiguration rpConfig = getRelyingPartyConfiguration(relyingPartyId);
348         if (rpConfig == null) {
349             log.error("Unable to retrieve relying party configuration data for entity with ID {}", relyingPartyId);
350             throw new ProfileException("Unable to retrieve relying party configuration data for entity with ID "
351                     + relyingPartyId);
352         }
353         requestContext.setRelyingPartyConfiguration(rpConfig);
354
355         SSOConfiguration profileConfig = (SSOConfiguration) rpConfig
356                 .getProfileConfiguration(SSOConfiguration.PROFILE_ID);
357         requestContext.setProfileConfiguration(profileConfig);
358         requestContext.setOutboundMessageArtifactType(profileConfig.getOutboundArtifactType());
359         if (profileConfig.getSigningCredential() != null) {
360             requestContext.setOutboundSAMLMessageSigningCredential(profileConfig.getSigningCredential());
361         } else if (rpConfig.getDefaultSigningCredential() != null) {
362             requestContext.setOutboundSAMLMessageSigningCredential(rpConfig.getDefaultSigningCredential());
363         }
364         requestContext.setPeerEntityEndpoint(selectEndpoint(requestContext));
365
366         String assertingPartyId = rpConfig.getProviderId();
367         requestContext.setLocalEntityId(assertingPartyId);
368
369         try {
370             EntityDescriptor localEntityDescriptor = metadataProvider.getEntityDescriptor(assertingPartyId);
371             if (localEntityDescriptor != null) {
372                 requestContext.setLocalEntityMetadata(localEntityDescriptor);
373                 requestContext.setLocalEntityRole(IDPSSODescriptor.DEFAULT_ELEMENT_NAME);
374                 requestContext.setLocalEntityRoleMetadata(localEntityDescriptor
375                         .getIDPSSODescriptor(SAMLConstants.SAML20P_NS));
376             }
377         } catch (MetadataProviderException e) {
378             log.error("Unable to locate metadata for asserting party");
379             requestContext.setFailureStatus(buildStatus(StatusCode.RESPONDER_URI, null,
380                     "Error locating asserting party metadata"));
381             throw new ProfileException("Error locating asserting party metadata");
382         }
383
384         return requestContext;
385     }
386
387     /**
388      * Creates an authentication statement for the current request.
389      * 
390      * @param requestContext current request context
391      * 
392      * @return constructed authentication statement
393      */
394     protected AuthnStatement buildAuthnStatement(SSORequestContext requestContext) {
395         Saml2LoginContext loginContext = requestContext.getLoginContext();
396
397         AuthnContext authnContext = buildAuthnContext(requestContext);
398
399         AuthnStatement statement = authnStatementBuilder.buildObject();
400         statement.setAuthnContext(authnContext);
401         statement.setAuthnInstant(loginContext.getAuthenticationInstant());
402
403         // TODO
404         statement.setSessionIndex(null);
405
406         if (loginContext.getAuthenticationDuration() > 0) {
407             statement.setSessionNotOnOrAfter(loginContext.getAuthenticationInstant().plus(
408                     loginContext.getAuthenticationDuration()));
409         }
410
411         statement.setSubjectLocality(buildSubjectLocality(requestContext));
412
413         return statement;
414     }
415
416     /**
417      * Creates an {@link AuthnContext} for a succesful authentication request.
418      * 
419      * @param requestContext current request
420      * 
421      * @return the built authn context
422      */
423     protected AuthnContext buildAuthnContext(SSORequestContext requestContext) {
424         AuthnContext authnContext = authnContextBuilder.buildObject();
425
426         Saml2LoginContext loginContext = requestContext.getLoginContext();
427         AuthnRequest authnRequest = requestContext.getInboundSAMLMessage();
428         RequestedAuthnContext requestedAuthnContext = authnRequest.getRequestedAuthnContext();
429         if (requestedAuthnContext != null) {
430             if (requestedAuthnContext.getAuthnContextClassRefs() != null) {
431                 for (AuthnContextClassRef classRef : requestedAuthnContext.getAuthnContextClassRefs()) {
432                     if (classRef.getAuthnContextClassRef().equals(loginContext.getAuthenticationMethod())) {
433                         AuthnContextClassRef ref = authnContextClassRefBuilder.buildObject();
434                         ref.setAuthnContextClassRef(loginContext.getAuthenticationMethod());
435                         authnContext.setAuthnContextClassRef(ref);
436                     }
437                 }
438             } else if (requestedAuthnContext.getAuthnContextDeclRefs() != null) {
439                 for (AuthnContextDeclRef declRef : requestedAuthnContext.getAuthnContextDeclRefs()) {
440                     if (declRef.getAuthnContextDeclRef().equals(loginContext.getAuthenticationMethod())) {
441                         AuthnContextDeclRef ref = authnContextDeclRefBuilder.buildObject();
442                         ref.setAuthnContextDeclRef(loginContext.getAuthenticationMethod());
443                         authnContext.setAuthnContextDeclRef(ref);
444                     }
445                 }
446             }
447         } else {
448             AuthnContextDeclRef ref = authnContextDeclRefBuilder.buildObject();
449             ref.setAuthnContextDeclRef(loginContext.getAuthenticationMethod());
450             authnContext.setAuthnContextDeclRef(ref);
451         }
452
453         return authnContext;
454     }
455
456     /**
457      * Constructs the subject locality for the authentication statement.
458      * 
459      * @param requestContext curent request context
460      * 
461      * @return subject locality for the authentication statement
462      */
463     protected SubjectLocality buildSubjectLocality(SSORequestContext requestContext) {
464         HTTPInTransport transport = (HTTPInTransport) requestContext.getInboundMessageTransport();
465         SubjectLocality subjectLocality = subjectLocalityBuilder.buildObject();
466         subjectLocality.setAddress(transport.getPeerAddress());
467         subjectLocality.setDNSName(transport.getPeerDomainName());
468
469         return subjectLocality;
470     }
471
472     /**
473      * Selects the appropriate endpoint for the relying party and stores it in the request context.
474      * 
475      * @param requestContext current request context
476      * 
477      * @return Endpoint selected from the information provided in the request context
478      */
479     protected Endpoint selectEndpoint(SSORequestContext requestContext) {
480         AuthnResponseEndpointSelector endpointSelector = new AuthnResponseEndpointSelector();
481         endpointSelector.setEndpointType(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
482         endpointSelector.setMetadataProvider(getMetadataProvider());
483         endpointSelector.setEntityMetadata(requestContext.getPeerEntityMetadata());
484         endpointSelector.setEntityRoleMetadata(requestContext.getPeerEntityRoleMetadata());
485         endpointSelector.setSamlRequest(requestContext.getInboundSAMLMessage());
486         endpointSelector.getSupportedIssuerBindings().addAll(getSupportedOutboundBindings());
487         return endpointSelector.selectEndpoint();
488     }
489
490     /** Represents the internal state of a SAML 2.0 SSO Request while it's being processed by the IdP. */
491     protected class SSORequestContext extends BaseSAML2ProfileRequestContext<AuthnRequest, Response, SSOConfiguration> {
492
493         /** Current login context. */
494         private Saml2LoginContext loginContext;
495
496         /**
497          * Gets the current login context.
498          * 
499          * @return current login context
500          */
501         public Saml2LoginContext getLoginContext() {
502             return loginContext;
503         }
504
505         /**
506          * Sets the current login context.
507          * 
508          * @param context current login context
509          */
510         public void setLoginContext(Saml2LoginContext context) {
511             loginContext = context;
512         }
513     }
514 }