| | 5 | |
|---|
| | 6 | <%@ page import="org.joda.time.DateTime" %> |
|---|
| | 7 | |
|---|
| | 8 | <%@ page import="org.opensaml.*" %> |
|---|
| | 9 | <%@ page import="org.opensaml.common.binding.BindingException" %> |
|---|
| | 10 | <%@ page import="org.opensaml.common.xml.SAMLConstants" %> |
|---|
| | 11 | <%@ page import="org.opensaml.saml2.binding.*" %> |
|---|
| | 12 | <%@ page import="org.opensaml.saml2.core.*" %> |
|---|
| | 13 | <%@ page import="org.opensaml.saml2.core.impl.*" %> |
|---|
| | 14 | <%@ page import="org.opensaml.xml.*" %> |
|---|
| | 15 | <%@ page import="org.opensaml.xml.parse.ParserPool" %> |
|---|
| | 16 | <%@ page import="org.opensaml.xml.io.*" %> |
|---|
| | 17 | <%@ page import="org.opensaml.xml.util.Base64" %> |
|---|
| | 18 | <%@ page import="org.opensaml.xml.util.XMLHelper" %> |
|---|
| | 19 | |
|---|
| | 20 | <%@ page import="org.w3c.dom.Element" %> |
|---|
| | 40 | // Ok, if we are here, they have successfully authenticated, now check and |
|---|
| | 41 | // see if we redirect them back to a SP |
|---|
| | 42 | String relayState; |
|---|
| | 43 | |
|---|
| | 44 | relayState = (String) session.getAttribute(_relaystate); |
|---|
| | 45 | if (relayState != null) { // Ok, we have one |
|---|
| | 46 | // first bootstrap the entire opensaml library |
|---|
| | 47 | org.opensaml.DefaultBootstrap.bootstrap(); |
|---|
| | 48 | // Use the OpenSAML Configuration singleton to get a builder factory object |
|---|
| | 49 | XMLObjectBuilderFactory builderFactory = org.opensaml.Configuration.getBuilderFactory(); |
|---|
| | 50 | |
|---|
| | 51 | |
|---|
| | 52 | AuthnRequestImpl auth = (AuthnRequestImpl) session.getAttribute(_authnrequest); |
|---|
| | 53 | // we must now build the Response object to redirect the user back to the SP with |
|---|
| | 54 | ResponseBuilder rspBldr = (ResponseBuilder) builderFactory.getBuilder(Response.DEFAULT_ELEMENT_NAME); |
|---|
| | 55 | Response rsp = rspBldr.buildObject(); |
|---|
| | 56 | |
|---|
| | 57 | rsp.setDestination( auth.getAssertionConsumerServiceURL() ); |
|---|
| | 58 | rsp.setID("some_unique_id_value_here"); |
|---|
| | 59 | rsp.setInResponseTo( auth.getID() ); |
|---|
| | 60 | rsp.setVersion(org.opensaml.common.SAMLVersion.VERSION_20); |
|---|
| | 61 | |
|---|
| | 62 | IssuerBuilder ib = (IssuerBuilder) builderFactory.getBuilder(Issuer.DEFAULT_ELEMENT_NAME); |
|---|
| | 63 | // Build the Issuer object |
|---|
| | 64 | Issuer isr = ib.buildObject(); |
|---|
| | 65 | isr.setValue("AcmeIdp"); |
|---|
| | 66 | rsp.setIssuer(isr); |
|---|
| | 67 | |
|---|
| | 68 | DateTime dt = new DateTime(); |
|---|
| | 69 | rsp.setIssueInstant(dt); |
|---|
| | 70 | |
|---|
| | 71 | // Now we must build our representation to put into the html form to be submitted to the idp |
|---|
| | 72 | HTTPPostEncoder encoder = new HTTPPostEncoder(); |
|---|
| | 73 | encoder.setSAMLMessage(rsp); |
|---|
| | 74 | |
|---|
| | 75 | encoder.setRelayState( (String) session.getAttribute(_relaystate) ); |
|---|
| | 76 | encoder.setResponse(response); |
|---|
| | 77 | encoder.setActionURL( auth.getAssertionConsumerServiceURL() ); |
|---|
| | 78 | |
|---|
| | 79 | encoder.encode(); |
|---|
| | 80 | return; |
|---|
| | 81 | } |
|---|