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 org.apache.cxf.binding.soap.SoapMessage;
20 import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
21 import org.apache.log4j.Logger;
22 import org.apache.ws.security.components.crypto.Crypto;
23 import org.apache.ws.security.components.crypto.Merlin;
24 import org.apache.ws.security.handler.RequestData;
25 import org.apache.ws.security.handler.WSHandlerConstants;
26 import org.kuali.rice.core.api.config.property.ConfigContext;
27 import org.kuali.rice.core.api.exception.RiceRuntimeException;
28 import org.kuali.rice.core.api.util.ClassLoaderUtils;
29 import org.kuali.rice.ksb.config.wss4j.CryptoPasswordCallbackHandler;
30
31 import java.util.Properties;
32
33
34
35
36
37
38
39 public class CXFWSS4JOutInterceptor extends WSS4JOutInterceptor {
40
41 private static final Logger LOG = Logger.getLogger(CXFWSS4JOutInterceptor.class);
42
43 private final boolean busSecurity;
44
45 public CXFWSS4JOutInterceptor(boolean busSecurity) {
46 this.busSecurity = busSecurity;
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 }
52
53 @Override
54 public Crypto loadSignatureCrypto(RequestData reqData) {
55 try {
56 return new Merlin(getMerlinProperties(), ClassLoaderUtils.getDefaultClassLoader());
57 } catch (Exception e) {
58 throw new RiceRuntimeException(e);
59 }
60 }
61
62 @Override
63 public Crypto loadDecryptionCrypto(RequestData reqData) {
64 return loadSignatureCrypto(reqData);
65 }
66
67 protected Properties getMerlinProperties() {
68 Properties props = new Properties();
69 props.put("org.apache.ws.security.crypto.merlin.keystore.type", "jks");
70 props.put("org.apache.ws.security.crypto.merlin.keystore.password", ConfigContext.getCurrentContextConfig().getKeystorePassword());
71 props.put("org.apache.ws.security.crypto.merlin.alias.password", ConfigContext.getCurrentContextConfig().getKeystorePassword());
72 props.put("org.apache.ws.security.crypto.merlin.keystore.alias", ConfigContext.getCurrentContextConfig().getKeystoreAlias());
73 props.put("org.apache.ws.security.crypto.merlin.file", ConfigContext.getCurrentContextConfig().getKeystoreFile());
74
75 if (LOG.isDebugEnabled()) {
76 LOG.debug("Using keystore location " + ConfigContext.getCurrentContextConfig().getKeystoreFile());
77 }
78
79 return props;
80 }
81
82
83
84
85
86
87 @Override
88 public void handleMessage(SoapMessage mc) {
89 if (busSecurity) {
90 super.handleMessage(mc);
91 }
92 }
93
94 }