use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class DOMToStaxRoundTripTest method testEncryptionAlgorithms.
@Test
public void testEncryptionAlgorithms() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setDecryptionCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> properties = new HashMap<>();
properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPT);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.USER, "myalias");
properties.put(ConfigurationConstants.ENC_KEY_TRANSPORT, WSS4JConstants.KEYTRANSPORT_RSA15);
properties.put(ConfigurationConstants.ENC_SYM_ALGO, WSS4JConstants.TRIPLE_DES);
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
try {
echo.echo("test");
fail("Failure expected as RSA v1.5 is not allowed by default");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
inProperties.setAllowRSA15KeyTransportAlgorithm(true);
service.getInInterceptors().remove(inhandler);
inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class DOMToStaxRoundTripTest method testSignatureTimestamp.
@Test
public void testSignatureTimestamp() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> properties = new HashMap<>();
properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP + " " + ConfigurationConstants.SIGNATURE);
properties.put(ConfigurationConstants.SIGNATURE_PARTS, "{}{" + WSSConstants.NS_WSU10 + "}Timestamp;" + "{}{" + WSSConstants.NS_SOAP11 + "}Body;");
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.USER, "myalias");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class DOMToStaxRoundTripTest method testEncryptUsernameToken.
@Test
public void testEncryptUsernameToken() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setDecryptionCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> properties = new HashMap<>();
properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPT);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.USER, "username");
properties.put(ConfigurationConstants.ENCRYPTION_USER, "myalias");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class DOMToStaxRoundTripTest method testSignatureConfirmation.
@Test
public void testSignatureConfirmation() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
WSSSecurityProperties outProperties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(XMLSecurityConstants.SIGNATURE);
actions.add(WSSConstants.SIGNATURE_CONFIRMATION);
outProperties.setActions(actions);
outProperties.setSignatureUser("myalias");
Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
outProperties.setSignatureCryptoProperties(outCryptoProperties);
outProperties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor staxOhandler = new WSS4JStaxOutInterceptor(outProperties);
service.getOutInterceptors().add(staxOhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> properties = new HashMap<>();
properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.ENABLE_SIGNATURE_CONFIRMATION, "true");
properties.put(ConfigurationConstants.USER, "myalias");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
Map<String, Object> domInProperties = new HashMap<>();
domInProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
domInProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
domInProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
domInProperties.put(ConfigurationConstants.ENABLE_SIGNATURE_CONFIRMATION, "true");
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(domInProperties);
client.getInInterceptors().add(inInterceptor);
assertEquals("test", echo.echo("test"));
}
use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class DOMToStaxRoundTripTest method testEncrypt.
@Test
public void testEncrypt() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setDecryptionCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> properties = new HashMap<>();
properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPT);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.USER, "myalias");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
Aggregations