1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.security.wss4j;
18
19 import java.util.List;
20 import java.util.Properties;
21
22 import org.springframework.ws.context.MessageContext;
23
24 import org.apache.ws.security.WSSecurityEngineResult;
25 import org.apache.ws.security.WSSecurityException;
26 import org.apache.ws.security.components.crypto.Crypto;
27 import org.apache.ws.security.handler.RequestData;
28 import org.apache.ws.security.handler.WSHandler;
29 import org.apache.ws.security.handler.WSHandlerConstants;
30 import org.w3c.dom.Document;
31
32
33
34
35
36
37 class Wss4jHandler extends WSHandler {
38
39
40 private Properties options = new Properties();
41
42 private String securementPassword;
43
44 private Crypto securementEncryptionCrypto;
45
46 private Crypto securementSignatureCrypto;
47
48 Wss4jHandler() {
49
50 options.setProperty(WSHandlerConstants.MUST_UNDERSTAND, Boolean.toString(true));
51 options.setProperty(WSHandlerConstants.ENABLE_SIGNATURE_CONFIRMATION, Boolean.toString(true));
52 }
53
54 @Override
55 protected boolean checkReceiverResultsAnyOrder(List<WSSecurityEngineResult> wsResult, List<Integer> actions) {
56 return super.checkReceiverResultsAnyOrder(wsResult, actions);
57 }
58
59 void setOption(String key, String value) {
60 options.setProperty(key, value);
61 }
62
63 void setOption(String key, boolean value) {
64 options.setProperty(key, Boolean.toString(value));
65 }
66
67 @Override
68 public Object getOption(String key) {
69 return options.getProperty(key);
70 }
71
72 void setSecurementPassword(String securementPassword) {
73 this.securementPassword = securementPassword;
74 }
75
76 void setSecurementEncryptionCrypto(Crypto securementEncryptionCrypto) {
77 this.securementEncryptionCrypto = securementEncryptionCrypto;
78 }
79
80 void setSecurementSignatureCrypto(Crypto securementSignatureCrypto) {
81 this.securementSignatureCrypto = securementSignatureCrypto;
82 }
83
84 @Override
85 public String getPassword(Object msgContext) {
86 return securementPassword;
87 }
88
89 @Override
90 public Object getProperty(Object msgContext, String key) {
91 return ((MessageContext) msgContext).getProperty(key);
92 }
93
94 @Override
95 protected Crypto loadEncryptionCrypto(RequestData reqData) throws WSSecurityException {
96 return securementEncryptionCrypto;
97 }
98
99 @Override
100 public Crypto loadSignatureCrypto(RequestData reqData) throws WSSecurityException {
101 return securementSignatureCrypto;
102 }
103
104 @Override
105 public void setPassword(Object msgContext, String password) {
106 securementPassword = password;
107 }
108
109 @Override
110 public void setProperty(Object msgContext, String key, Object value) {
111 ((MessageContext) msgContext).setProperty(key, value);
112 }
113
114 @Override
115 protected void doSenderAction(int doAction,
116 Document doc,
117 RequestData reqData,
118 List<Integer> actions,
119 boolean isRequest) throws WSSecurityException {
120 super.doSenderAction(doAction, doc, reqData, actions, isRequest);
121 }
122 }