use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class DOMToStaxRoundTripTest method testTimestamp.
@Test
public void testTimestamp() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
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);
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 DOMToStaxSignatureIdentifierTest method testSignatureX509.
@Test
public void testSignatureX509() 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.SIGNATURE);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.USER, "myalias");
properties.put(ConfigurationConstants.SIG_KEY_ID, "X509KeyIdentifier");
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 DOMToStaxSignatureIdentifierTest method testSignatureThumbprint.
@Test
public void testSignatureThumbprint() 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.SIGNATURE);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.USER, "myalias");
properties.put(ConfigurationConstants.SIG_KEY_ID, "Thumbprint");
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 StaxCryptoCoverageCheckerTest method testUsernameToken.
@Test
public void testUsernameToken() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
principalInterceptor.setPrincipalName("username");
service.getInInterceptors().add(inhandler);
service.getInInterceptors().add(principalInterceptor);
StaxCryptoCoverageChecker checker = new StaxCryptoCoverageChecker();
checker.setSignBody(false);
checker.setEncryptUsernameToken(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);
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);
try {
echo.echo("test");
fail("Failure expected as UsernameToken isn't encrypted");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
checker.setEncryptUsernameToken(false);
assertEquals("test", echo.echo("test"));
}
use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.
the class StaxCryptoCoverageCheckerTest 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());
inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
principalInterceptor.setPrincipalName("CN=myAlias");
service.getInInterceptors().add(inhandler);
service.getInInterceptors().add(principalInterceptor);
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.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"));
checker.setEncryptBody(true);
try {
echo.echo("test");
fail("Failure expected as SOAP Body isn't encrypted");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
}
Aggregations