1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.ksb.security.soap;
18
19 import java.util.Properties;
20
21 import org.apache.cxf.binding.soap.SoapMessage;
22 import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
23 import org.apache.log4j.Logger;
24 import org.apache.ws.security.components.crypto.Crypto;
25 import org.apache.ws.security.components.crypto.Merlin;
26 import org.apache.ws.security.handler.RequestData;
27 import org.apache.ws.security.handler.WSHandlerConstants;
28 import org.kuali.rice.core.config.ConfigContext;
29 import org.kuali.rice.core.exception.RiceRuntimeException;
30 import org.kuali.rice.core.util.ClassLoaderUtils;
31 import org.kuali.rice.ksb.config.wss4j.CryptoPasswordCallbackHandler;
32 import org.kuali.rice.ksb.messaging.ServiceInfo;
33
34
35
36
37
38
39
40 public class CXFWSS4JOutInterceptor extends WSS4JOutInterceptor {
41
42 private static final Logger LOG = Logger.getLogger(CXFWSS4JOutInterceptor.class);
43
44 private ServiceInfo serviceInfo;
45
46 public CXFWSS4JOutInterceptor(ServiceInfo serviceInfo) {
47 this.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
48 this.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, CryptoPasswordCallbackHandler.class.getName());
49 this.setProperty(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");
50 this.setProperty(WSHandlerConstants.USER, ConfigContext.getCurrentContextConfig().getKeystoreAlias());
51 this.serviceInfo = serviceInfo;
52 }
53
54 @Override
55 public Crypto loadSignatureCrypto(RequestData reqData) {
56 try {
57 return new Merlin(getMerlinProperties(), ClassLoaderUtils.getDefaultClassLoader());
58 } catch (Exception e) {
59 throw new RiceRuntimeException(e);
60 }
61 }
62
63 @Override
64 public Crypto loadDecryptionCrypto(RequestData reqData) {
65 return loadSignatureCrypto(reqData);
66 }
67
68 protected Properties getMerlinProperties() {
69 Properties props = new Properties();
70 props.put("org.apache.ws.security.crypto.merlin.keystore.type", "jks");
71 props.put("org.apache.ws.security.crypto.merlin.keystore.password", ConfigContext.getCurrentContextConfig().getKeystorePassword());
72 props.put("org.apache.ws.security.crypto.merlin.alias.password", ConfigContext.getCurrentContextConfig().getKeystorePassword());
73 props.put("org.apache.ws.security.crypto.merlin.keystore.alias", ConfigContext.getCurrentContextConfig().getKeystoreAlias());
74 props.put("org.apache.ws.security.crypto.merlin.file", ConfigContext.getCurrentContextConfig().getKeystoreFile());
75
76 if (LOG.isDebugEnabled()) {
77 LOG.debug("Using keystore location " + ConfigContext.getCurrentContextConfig().getKeystoreFile());
78 }
79
80 return props;
81 }
82
83
84
85
86
87
88 @Override
89 public void handleMessage(SoapMessage mc) {
90 if (getServiceInfo().getServiceDefinition().getBusSecurity()) {
91 super.handleMessage(mc);
92 }
93 }
94
95 public ServiceInfo getServiceInfo() {
96 return serviceInfo;
97 }
98
99 public void setServiceInfo(ServiceInfo serviceInfo) {
100 this.serviceInfo = serviceInfo;
101 }
102
103 }