1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.ws.message.handler;
18
19 import org.opensaml.ws.message.MessageContext;
20 import org.opensaml.ws.message.decoder.BaseMessageDecoder;
21 import org.opensaml.ws.message.decoder.MessageDecodingException;
22 import org.opensaml.xml.parse.ParserPool;
23 import org.opensaml.xml.security.SecurityException;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27
28
29
30 public abstract class BaseHandlerChainAwareMessageDecoder extends BaseMessageDecoder implements HandlerChainAware {
31
32
33 private final Logger log = LoggerFactory.getLogger(BaseHandlerChainAwareMessageDecoder.class);
34
35
36
37
38
39 public BaseHandlerChainAwareMessageDecoder() {
40 super();
41 }
42
43
44
45
46
47
48 public BaseHandlerChainAwareMessageDecoder(ParserPool pool) {
49 super(pool);
50 }
51
52
53 public void decode(MessageContext messageContext) throws MessageDecodingException, SecurityException {
54 log.debug("Beginning to decode message from inbound transport of type: {}", messageContext
55 .getInboundMessageTransport().getClass().getName());
56
57 doDecode(messageContext);
58
59 logDecodedMessage(messageContext);
60
61 processPreSecurityInboundHandlerChain(messageContext);
62 log.debug("Successfully processed pre-SecurityPolicy inbound handler chain.");
63
64 processSecurityPolicy(messageContext);
65
66 processPostSecurityInboundHandlerChain(messageContext);
67 log.debug("Successfully processed post-SecurityPolicy inbound handler chain.");
68
69 log.debug("Successfully decoded message.");
70 }
71
72
73
74
75
76
77
78 protected void processPreSecurityInboundHandlerChain(MessageContext messageContext)
79 throws MessageDecodingException {
80 HandlerChainResolver inboundHandlerChainResolver = messageContext.getPreSecurityInboundHandlerChainResolver();
81 if (inboundHandlerChainResolver != null) {
82 log.debug("Invoking pre-SecurityPolicy inbound handler chain on message context");
83 try {
84 for (HandlerChain inboundHandlerChain : inboundHandlerChainResolver.resolve(messageContext)) {
85 if (inboundHandlerChain != null) {
86 invokeHandlerChain(inboundHandlerChain, messageContext);
87 }
88 }
89 } catch (HandlerException e) {
90 log.error("Encountered pre-SecurityPolicy HandlerException when decoding message: {}", e.getMessage());
91 throw new MessageDecodingException("Pre-SecurityPolicy Handler exception while decoding message", e);
92 }
93 }
94 }
95
96
97
98
99
100
101
102 protected void processPostSecurityInboundHandlerChain(MessageContext messageContext)
103 throws MessageDecodingException {
104 HandlerChainResolver inboundHandlerChainResolver = messageContext.getPostSecurityInboundHandlerChainResolver();
105 if (inboundHandlerChainResolver != null) {
106 log.debug("Invoking post-SecurityPolicy inbound handler chain on message context");
107 try {
108 for (HandlerChain inboundHandlerChain : inboundHandlerChainResolver.resolve(messageContext)) {
109 if (inboundHandlerChain != null) {
110 invokeHandlerChain(inboundHandlerChain, messageContext);
111 }
112 }
113 } catch (HandlerException e) {
114 log.error("Encountered post-SecurityPolicy HandlerException when decoding message: {}", e.getMessage());
115 throw new MessageDecodingException("Handler exception while decoding message", e);
116 }
117 }
118 }
119
120
121
122
123
124
125
126
127
128 protected void invokeHandlerChain(HandlerChain handlerChain, MessageContext messageContext)
129 throws HandlerException {
130 if (handlerChain != null && messageContext != null) {
131 handlerChain.invoke(messageContext);
132 }
133 }
134
135 }