use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class StaxCryptoCoverageCheckerTest method testSignedUsernameToken.
@Test
public void testSignedUsernameToken() 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);
StaxCryptoCoverageChecker checker = new StaxCryptoCoverageChecker();
checker.setSignBody(false);
checker.setSignUsernameToken(true);
service.getInInterceptors().add(checker);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(WSSConstants.USERNAMETOKEN);
actions.add(XMLSecurityConstants.SIGNATURE);
properties.setActions(actions);
properties.setSignatureUser("myalias");
properties.addSignaturePart(new SecurePart(new QName(WSSConstants.NS_WSSE10, "UsernameToken"), SecurePart.Modifier.Element));
properties.addSignaturePart(new SecurePart(new QName(WSSConstants.NS_SOAP11, "Body"), SecurePart.Modifier.Element));
Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setSignatureCryptoProperties(outCryptoProperties);
properties.setTokenUser("username");
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
checker.setEncryptUsernameToken(false);
assertEquals("test", echo.echo("test"));
checker.setEncryptUsernameToken(true);
try {
echo.echo("test");
fail("Failure expected as UsernameToken isn't encrypted");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
}
use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class StaxCryptoCoverageCheckerTest method testEncryptSignature.
@Test
public void testEncryptSignature() 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);
inProperties.setDecryptionCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
StaxCryptoCoverageChecker checker = new StaxCryptoCoverageChecker();
service.getInInterceptors().add(checker);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(XMLSecurityConstants.ENCRYPT);
actions.add(XMLSecurityConstants.SIGNATURE);
properties.setActions(actions);
properties.setEncryptionUser("myalias");
properties.setSignatureUser("myalias");
properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128);
Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setSignatureCryptoProperties(outCryptoProperties);
properties.setEncryptionCryptoProperties(outCryptoProperties);
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(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 StaxCryptoCoverageCheckerTest method testEncryptedBody.
@Test
public void testEncryptedBody() 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);
StaxCryptoCoverageChecker checker = new StaxCryptoCoverageChecker();
service.getInInterceptors().add(checker);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(XMLSecurityConstants.ENCRYPT);
properties.setActions(actions);
properties.setEncryptionUser("myalias");
properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128);
Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setEncryptionCryptoProperties(outCryptoProperties);
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
try {
echo.echo("test");
fail("Failure expected as SOAP Body isn't signed");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
checker.setSignBody(false);
assertEquals("test", echo.echo("test"));
}
use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class StaxRoundTripActionTest method testUsernameTokenConfig.
@Test
public void testUsernameTokenConfig() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inConfig = new HashMap<>();
inConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
inConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
inConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordText");
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
principalInterceptor.setPrincipalName("username");
service.getInInterceptors().add(inhandler);
service.getInInterceptors().add(principalInterceptor);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(WSSConstants.USERNAMETOKEN);
properties.setActions(actions);
properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
properties.setTokenUser("username");
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
service.getInInterceptors().remove(inhandler);
inConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPT);
inhandler = new WSS4JStaxInInterceptor(inConfig);
service.getInInterceptors().add(inhandler);
try {
echo.echo("test");
fail("Failure expected on the wrong action");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
assertTrue(ex.getMessage().contains(WSSecurityException.UNIFIED_SECURITY_ERR));
}
}
use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class StaxRoundTripActionTest method testSignature.
@Test
public void testSignature() 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());
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(XMLSecurityConstants.SIGNATURE);
inProperties.setActions(actions);
inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
principalInterceptor.setPrincipalName("CN=myAlias");
service.getInInterceptors().add(inhandler);
service.getInInterceptors().add(principalInterceptor);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
actions = new ArrayList<WSSConstants.Action>();
actions.add(XMLSecurityConstants.SIGNATURE);
properties.setActions(actions);
properties.setSignatureUser("myalias");
Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setSignatureCryptoProperties(outCryptoProperties);
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
actions = new ArrayList<WSSConstants.Action>();
actions.add(XMLSecurityConstants.SIGNATURE);
actions.add(XMLSecurityConstants.ENCRYPT);
inProperties.setActions(actions);
try {
echo.echo("test");
fail("Failure expected on the wrong action");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
assertTrue(ex.getMessage().contains(WSSecurityException.UNIFIED_SECURITY_ERR));
}
}
Aggregations