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