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