1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.wss4j.stax.impl;
20
21 import org.apache.wss4j.common.WSSPolicyException;
22 import org.apache.wss4j.common.ext.WSSecurityException;
23 import org.apache.xml.security.stax.ext.InputProcessorChain;
24 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
25 import org.apache.xml.security.stax.impl.XMLSecurityStreamReader;
26
27 import javax.xml.stream.XMLStreamException;
28
29 public class WSSecurityStreamReader extends XMLSecurityStreamReader {
30
31 private final boolean initiator;
32 private final boolean returnSecurityError;
33
34 public WSSecurityStreamReader(InputProcessorChain inputProcessorChain,
35 XMLSecurityProperties securityProperties, boolean initiator,
36 boolean returnSecurityError) {
37 super(inputProcessorChain, securityProperties);
38 this.initiator = initiator;
39 this.returnSecurityError = returnSecurityError;
40 }
41
42 @Override
43 public int next() throws XMLStreamException {
44 try {
45 return super.next();
46 } catch (XMLStreamException e) {
47 Throwable cause = e.getCause();
48
49
50 if (returnSecurityError || initiator
51 || cause != null && cause.getCause() instanceof WSSPolicyException) {
52 throw e;
53 }
54
55
56 throw new XMLStreamException(
57 new WSSecurityException(WSSecurityException.ErrorCode.SECURITY_ERROR));
58 }
59 }
60
61 }