Search in sources :

Example 11 with WSSSecurityProperties

use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.

the class StaxToDOMSamlTest method testSaml2TokenHOK.

@Test
public void testSaml2TokenHOK() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED + " " + ConfigurationConstants.SIGNATURE);
    inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    // 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.SAML_TOKEN_SIGNED);
    properties.setActions(actions);
    SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
    callbackHandler.setSignAssertion(true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
    properties.setSamlCallbackHandler(callbackHandler);
    properties.setCallbackHandler(new PasswordCallbackHandler());
    properties.setSignatureUser("alice");
    Properties cryptoProperties = CryptoFactory.getProperties("alice.properties", this.getClass().getClassLoader());
    properties.setSignatureCryptoProperties(cryptoProperties);
    properties.setSignatureKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE);
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(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"));
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) Echo(org.apache.cxf.ws.security.wss4j.Echo) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) AbstractSecurityTest(org.apache.cxf.ws.security.wss4j.AbstractSecurityTest) Test(org.junit.Test)

Example 12 with WSSSecurityProperties

use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.

the class StaxToDOMSamlTest method testSaml2.

@Test
public void testSaml2() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    validator.setRequireSAML1Assertion(false);
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    inProperties.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    service.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");
    // 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.SAML_TOKEN_UNSIGNED);
    properties.setActions(actions);
    properties.setSamlCallbackHandler(new SAML2CallbackHandler());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);
    assertEquals("test", echo.echo("test"));
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) HashMap(java.util.HashMap) Echo(org.apache.cxf.ws.security.wss4j.Echo) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) AbstractSecurityTest(org.apache.cxf.ws.security.wss4j.AbstractSecurityTest) Test(org.junit.Test)

Example 13 with WSSSecurityProperties

use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.

the class StaxToDOMSamlTest method testSaml1TokenHOK.

@Test
public void testSaml1TokenHOK() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED + " " + ConfigurationConstants.SIGNATURE);
    inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    // 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.SAML_TOKEN_SIGNED);
    properties.setActions(actions);
    SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
    callbackHandler.setSignAssertion(true);
    callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
    properties.setSamlCallbackHandler(callbackHandler);
    properties.setSignatureUser("alice");
    Properties cryptoProperties = CryptoFactory.getProperties("alice.properties", this.getClass().getClassLoader());
    properties.setSignatureCryptoProperties(cryptoProperties);
    properties.setSignatureKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE);
    properties.setCallbackHandler(new PasswordCallbackHandler());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(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"));
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) Echo(org.apache.cxf.ws.security.wss4j.Echo) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) AbstractSecurityTest(org.apache.cxf.ws.security.wss4j.AbstractSecurityTest) Test(org.junit.Test)

Example 14 with WSSSecurityProperties

use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.

the class StaxToDOMSamlTest method testSaml2SignedSenderVouches.

@Test
public void testSaml2SignedSenderVouches() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED + " " + ConfigurationConstants.SIGNATURE);
    inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    validator.setRequireSAML1Assertion(false);
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    // 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.SAML_TOKEN_SIGNED);
    properties.setActions(actions);
    properties.setSamlCallbackHandler(new SAML2CallbackHandler());
    properties.setCallbackHandler(new PasswordCallbackHandler());
    properties.setSignatureKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE);
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);
    assertEquals("test", echo.echo("test"));
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) HashMap(java.util.HashMap) Echo(org.apache.cxf.ws.security.wss4j.Echo) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) AbstractSecurityTest(org.apache.cxf.ws.security.wss4j.AbstractSecurityTest) Test(org.junit.Test)

Example 15 with WSSSecurityProperties

use of org.apache.wss4j.stax.ext.WSSSecurityProperties in project cxf by apache.

the class DOMToStaxEncryptionIdentifierTest method testEncryptIssuerSerial.

@Test
public void testEncryptIssuerSerial() 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_ID, "IssuerSerial");
    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);
    assertEquals("test", echo.echo("test"));
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) HashMap(java.util.HashMap) Service(org.apache.cxf.service.Service) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Aggregations

WSSSecurityProperties (org.apache.wss4j.stax.ext.WSSSecurityProperties)107 Client (org.apache.cxf.endpoint.Client)90 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)89 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)89 Service (org.apache.cxf.service.Service)89 Test (org.junit.Test)89 WSSConstants (org.apache.wss4j.stax.ext.WSSConstants)68 Properties (java.util.Properties)67 ArrayList (java.util.ArrayList)63 HashMap (java.util.HashMap)59 QName (javax.xml.namespace.QName)27 SecurePart (org.apache.xml.security.stax.ext.SecurePart)19 AbstractSecurityTest (org.apache.cxf.ws.security.wss4j.AbstractSecurityTest)12 Echo (org.apache.cxf.ws.security.wss4j.Echo)12 IssuedToken (org.apache.wss4j.policy.model.IssuedToken)9 WSS4JStaxOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor)8 AbstractToken (org.apache.wss4j.policy.model.AbstractToken)8 WSS4JStaxInInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JStaxInInterceptor)7 X509Token (org.apache.wss4j.policy.model.X509Token)7 WSS4JInInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor)6