1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.internet2.middleware.shibboleth.idp.profile.saml1;
18
19 import org.joda.time.DateTime;
20 import org.joda.time.chrono.ISOChronology;
21 import org.opensaml.common.SAMLObject;
22 import org.opensaml.common.binding.SAMLMessageContext;
23 import org.opensaml.common.binding.decoding.SAMLMessageDecoder;
24 import org.opensaml.saml1.binding.decoding.BaseSAML1MessageDecoder;
25 import org.opensaml.ws.message.MessageContext;
26 import org.opensaml.ws.message.decoder.MessageDecodingException;
27 import org.opensaml.ws.transport.http.HTTPInTransport;
28 import org.opensaml.xml.util.DatatypeHelper;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import edu.internet2.middleware.shibboleth.idp.profile.saml1.ShibbolethSSOProfileHandler.ShibbolethSSORequestContext;
33
34
35
36
37 public class ShibbolethSSODecoder extends BaseSAML1MessageDecoder implements SAMLMessageDecoder {
38
39
40 private final Logger log = LoggerFactory.getLogger(ShibbolethSSODecoder.class);
41
42
43 public ShibbolethSSODecoder(){
44 super(null);
45 }
46
47
48 public String getBindingURI() {
49 return "urn:mace:shibboleth:1.0:profiles:AuthnRequest";
50 }
51
52
53 protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
54 if (!(messageContext instanceof ShibbolethSSORequestContext)) {
55 log.error("Invalid message context type, this decoder only support ShibbolethSSORequestContext");
56 throw new MessageDecodingException(
57 "Invalid message context type, this decoder only support ShibbolethSSORequestContext");
58 }
59
60 if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
61 log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
62 throw new MessageDecodingException(
63 "Invalid inbound message transport type, this decoder only support HTTPInTransport");
64 }
65
66 ShibbolethSSORequestContext requestContext = (ShibbolethSSORequestContext) messageContext;
67 HTTPInTransport transport = (HTTPInTransport) messageContext.getInboundMessageTransport();
68
69 String providerId = DatatypeHelper.safeTrimOrNullString(transport.getParameterValue("providerId"));
70 if (providerId == null) {
71 log.error("No providerId parameter given in Shibboleth SSO authentication request.");
72 throw new MessageDecodingException(
73 "No providerId parameter given in Shibboleth SSO authentication request.");
74 }
75 requestContext.setInboundMessageIssuer(providerId);
76
77 String shire = DatatypeHelper.safeTrimOrNullString(transport.getParameterValue("shire"));
78 if (shire == null) {
79 log.error("No shire parameter given in Shibboleth SSO authentication request.");
80 throw new MessageDecodingException("No shire parameter given in Shibboleth SSO authentication request.");
81 }
82 requestContext.setSpAssertionConsumerService(shire);
83
84 String target = DatatypeHelper.safeTrimOrNullString(transport.getParameterValue("target"));
85 if (target == null) {
86 log.error("No target parameter given in Shibboleth SSO authentication request.");
87 throw new MessageDecodingException("No target parameter given in Shibboleth SSO authentication request.");
88 }
89 requestContext.setRelayState(target);
90
91 String timeStr = DatatypeHelper.safeTrimOrNullString(transport.getParameterValue("time"));
92 if (timeStr != null) {
93 long time = Long.parseLong(timeStr) * 1000;
94 requestContext.setInboundSAMLMessageIssueInstant(new DateTime(time, ISOChronology.getInstanceUTC()));
95 }
96
97 populateRelyingPartyMetadata(requestContext);
98 }
99
100
101 protected boolean isIntendedDestinationEndpointURIRequired(SAMLMessageContext samlMsgCtx) {
102 return false;
103 }
104
105
106 protected String getIntendedDestinationEndpointURI(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
107
108
109 return null;
110 }
111
112 }