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