1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.saml1.binding.decoding;
18
19 import java.util.List;
20
21 import org.opensaml.common.binding.SAMLMessageContext;
22 import org.opensaml.common.binding.artifact.SAMLArtifactMap;
23 import org.opensaml.common.xml.SAMLConstants;
24 import org.opensaml.ws.message.MessageContext;
25 import org.opensaml.ws.message.decoder.MessageDecodingException;
26 import org.opensaml.ws.transport.http.HTTPInTransport;
27 import org.opensaml.xml.parse.ParserPool;
28 import org.opensaml.xml.util.DatatypeHelper;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37 public class HTTPArtifactDecoder extends BaseSAML1MessageDecoder {
38
39
40 private final Logger log = LoggerFactory.getLogger(HTTPArtifactDecoder.class);
41
42
43
44
45
46
47
48 public HTTPArtifactDecoder(SAMLArtifactMap map, ParserPool pool) {
49 super(map, pool);
50 }
51
52
53 public String getBindingURI() {
54 return SAMLConstants.SAML1_ARTIFACT_BINDING_URI;
55 }
56
57
58 protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
59 if (!(messageContext instanceof SAMLMessageContext)) {
60 log.error("Invalid message context type, this decoder only support SAMLMessageContext");
61 throw new MessageDecodingException(
62 "Invalid message context type, this decoder only support SAMLMessageContext");
63 }
64
65 if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
66 log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
67 throw new MessageDecodingException(
68 "Invalid inbound message transport type, this decoder only support HTTPInTransport");
69 }
70
71 SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;
72
73 decodeTarget(samlMsgCtx);
74 processArtifacts(samlMsgCtx);
75
76 populateMessageContext(samlMsgCtx);
77 }
78
79
80
81
82
83
84
85
86 protected void decodeTarget(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
87 HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
88
89 String target = DatatypeHelper.safeTrim(inTransport.getParameterValue("TARGET"));
90 if (target == null) {
91 log.error("URL TARGET parameter was missing or did not contain a value.");
92 throw new MessageDecodingException("URL TARGET parameter was missing or did not contain a value.");
93 }
94 samlMsgCtx.setRelayState(target);
95 }
96
97
98
99
100
101
102
103
104
105 protected void processArtifacts(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
106 HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
107 List<String> encodedArtifacts = inTransport.getParameterValues("SAMLart");
108 if (encodedArtifacts == null || encodedArtifacts.size() == 0) {
109 log.error("URL SAMLart parameter was missing or did not contain a value.");
110 throw new MessageDecodingException("URL SAMLart parameter was missing or did not contain a value.");
111 }
112
113
114
115
116 }
117
118
119 protected boolean isIntendedDestinationEndpointURIRequired(SAMLMessageContext samlMsgCtx) {
120 return false;
121 }
122
123
124 protected String getIntendedDestinationEndpointURI(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
125
126
127 return null;
128 }
129 }