Search in sources :

Example 11 with SecurePart

use of org.apache.xml.security.stax.ext.SecurePart in project cxf by apache.

the class StaxRoundTripActionTest method testSignatureTimestamp.

@Test
public void testSignatureTimestamp() throws Exception {
    // Create + configure service
    Service service = createService();
    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setCallbackHandler(new TestPwdCallback());
    List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
    actions.add(WSSConstants.TIMESTAMP);
    actions.add(XMLSecurityConstants.SIGNATURE);
    inProperties.setActions(actions);
    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());
    WSSSecurityProperties properties = new WSSSecurityProperties();
    actions = new ArrayList<WSSConstants.Action>();
    actions.add(WSSConstants.TIMESTAMP);
    actions.add(XMLSecurityConstants.SIGNATURE);
    properties.setActions(actions);
    properties.addSignaturePart(new SecurePart(new QName(WSSConstants.NS_WSU10, "Timestamp"), SecurePart.Modifier.Element));
    properties.addSignaturePart(new SecurePart(new QName(WSSConstants.NS_SOAP11, "Body"), SecurePart.Modifier.Element));
    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"));
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) SecurePart(org.apache.xml.security.stax.ext.SecurePart) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 12 with SecurePart

use of org.apache.xml.security.stax.ext.SecurePart in project cxf by apache.

the class StaxRoundTripTest 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);
    // 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);
    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);
    assertEquals("test", echo.echo("test"));
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) SecurePart(org.apache.xml.security.stax.ext.SecurePart) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 13 with SecurePart

use of org.apache.xml.security.stax.ext.SecurePart in project cxf by apache.

the class StaxRoundTripTest 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());
    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
    actions.add(WSSConstants.USERNAMETOKEN);
    actions.add(XMLSecurityConstants.ENCRYPT);
    properties.setActions(actions);
    properties.addEncryptionPart(new SecurePart(new QName(WSSConstants.NS_WSSE10, "UsernameToken"), SecurePart.Modifier.Element));
    properties.setEncryptionUser("myalias");
    properties.setTokenUser("username");
    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);
    assertEquals("test", echo.echo("test"));
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) SecurePart(org.apache.xml.security.stax.ext.SecurePart) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 14 with SecurePart

use of org.apache.xml.security.stax.ext.SecurePart in project cxf by apache.

the class StaxToDOMRoundTripTest method testSignatureTimestampWrongNamespace.

@Test
public void testSignatureTimestampWrongNamespace() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.TIMESTAMP);
    inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    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(XMLSecurityConstants.SIGNATURE);
    actions.add(WSSConstants.TIMESTAMP);
    properties.setActions(actions);
    properties.addSignaturePart(new SecurePart(new QName(WSSConstants.NS_WSSE10, "Timestamp"), SecurePart.Modifier.Element));
    properties.addSignaturePart(new SecurePart(new QName(WSSConstants.NS_SOAP11, "Body"), SecurePart.Modifier.Element));
    properties.setSignatureUser("myalias");
    Properties cryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
    properties.setSignatureCryptoProperties(cryptoProperties);
    properties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);
    try {
        echo.echo("test");
        fail("Failure expected on a wrong namespace");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
    // expected
    }
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) SecurePart(org.apache.xml.security.stax.ext.SecurePart) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 15 with SecurePart

use of org.apache.xml.security.stax.ext.SecurePart in project cxf by apache.

the class StaxToDOMRoundTripTest method testSignedUsernameToken.

@Test
public void testSignedUsernameToken() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.USERNAME_TOKEN);
    inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    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.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 cryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
    properties.setSignatureCryptoProperties(cryptoProperties);
    properties.setTokenUser("username");
    properties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);
    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) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) SecurePart(org.apache.xml.security.stax.ext.SecurePart) 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

SecurePart (org.apache.xml.security.stax.ext.SecurePart)30 QName (javax.xml.namespace.QName)26 WSSSecurityProperties (org.apache.wss4j.stax.ext.WSSSecurityProperties)19 WSSConstants (org.apache.wss4j.stax.ext.WSSConstants)18 ArrayList (java.util.ArrayList)17 Properties (java.util.Properties)12 Client (org.apache.cxf.endpoint.Client)12 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)12 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)12 Service (org.apache.cxf.service.Service)12 Test (org.junit.Test)12 AbstractToken (org.apache.wss4j.policy.model.AbstractToken)8 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)7 HashMap (java.util.HashMap)6 IssuedToken (org.apache.wss4j.policy.model.IssuedToken)6 SOAPException (javax.xml.soap.SOAPException)5 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)5 Fault (org.apache.cxf.interceptor.Fault)4 AbstractTokenWrapper (org.apache.wss4j.policy.model.AbstractTokenWrapper)4 SecureConversationToken (org.apache.wss4j.policy.model.SecureConversationToken)4