use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.
the class DOMToStaxSamlTest method testSaml2.
@Test
public void testSaml2() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setValidateSamlSubjectConfirmation(false);
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.SAML_TOKEN_UNSIGNED);
properties.put(ConfigurationConstants.SAML_CALLBACK_REF, new SAML2CallbackHandler());
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.
the class DOMToStaxSamlTest method testSaml2TokenHOK.
@Test
public void testSaml2TokenHOK() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
CustomStaxSamlValidator validator = new CustomStaxSamlValidator();
inProperties.addValidator(WSConstants.SAML_TOKEN, validator);
inProperties.addValidator(WSConstants.SAML2_TOKEN, validator);
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.SAML_TOKEN_SIGNED);
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
callbackHandler.setSignAssertion(true);
properties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler);
properties.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
properties.put(ConfigurationConstants.USER, "alice");
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new PasswordCallbackHandler());
properties.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
try {
echo.echo("test");
fail("Failure expected on receiving sender vouches instead of HOK");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
validator.setRequireSenderVouches(false);
try {
echo.echo("test");
fail("Failure expected on receiving a SAML 1.1 Token instead of SAML 2.0");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
validator.setRequireSAML1Assertion(false);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.
the class DOMToStaxSamlTest method testSaml1TokenHOK.
@Test
public void testSaml1TokenHOK() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
CustomStaxSamlValidator validator = new CustomStaxSamlValidator();
inProperties.addValidator(WSConstants.SAML_TOKEN, validator);
inProperties.addValidator(WSConstants.SAML2_TOKEN, validator);
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.SAML_TOKEN_SIGNED);
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
callbackHandler.setSignAssertion(true);
properties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler);
properties.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
properties.put(ConfigurationConstants.USER, "alice");
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new PasswordCallbackHandler());
properties.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
try {
echo.echo("test");
fail("Failure expected on receiving sender vouches instead of HOK");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
validator.setRequireSenderVouches(false);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.
the class DOMToStaxSamlTest method testSaml1.
@Test
public void testSaml1() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setValidateSamlSubjectConfirmation(false);
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.SAML_TOKEN_UNSIGNED);
properties.put(ConfigurationConstants.SAML_CALLBACK_REF, new SAML1CallbackHandler());
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.
the class ActionTest method testSignatureHandlerActions.
@org.junit.Test
public void testSignatureHandlerActions() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = ActionTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItSignatureConfigPort");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, PORT);
// Programmatic interceptor
Map<String, Object> props = new HashMap<>();
HandlerAction signatureAction = new HandlerAction();
signatureAction.setAction(WSConstants.SIGN);
SignatureActionToken actionToken = new SignatureActionToken();
actionToken.setUser("alice");
actionToken.setKeyIdentifierId(WSConstants.BST_DIRECT_REFERENCE);
Properties cryptoProperties = CryptoFactory.getProperties("alice.properties", this.getClass().getClassLoader());
Crypto crypto = CryptoFactory.getInstance(cryptoProperties, this.getClass().getClassLoader(), null);
actionToken.setCrypto(crypto);
signatureAction.setActionToken(actionToken);
List<HandlerAction> actions = Collections.singletonList(signatureAction);
props.put(WSHandlerConstants.HANDLER_ACTIONS, actions);
props.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(props);
Client client = ClientProxy.getClient(port);
client.getOutInterceptors().add(outInterceptor);
assertEquals(50, port.doubleIt(25));
((java.io.Closeable) port).close();
bus.shutdown(true);
}
Aggregations