Search in sources :

Example 56 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor 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"));
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) ArrayList(java.util.ArrayList) 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)

Example 57 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor 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));
    }
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) 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 58 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.

the class StaxRoundTripActionTest method testTimestampConfig.

@Test
public void testTimestampConfig() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inConfig = new HashMap<>();
    inConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
    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> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
    client.getOutInterceptors().add(ohandler);
    assertEquals("test", echo.echo("test"));
}
Also used : HashMap(java.util.HashMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Service(org.apache.cxf.service.Service) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 59 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.

the class StaxRoundTripActionTest method testEncryptUsernameTokenConfig.

@Test
public void testEncryptUsernameTokenConfig() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inConfig = new HashMap<>();
    inConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPT + " " + ConfigurationConstants.USERNAME_TOKEN);
    inConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    inConfig.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
    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> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPT);
    outConfig.put(ConfigurationConstants.ENCRYPTION_PARTS, "{Element}{" + WSSConstants.NS_WSSE10 + "}UsernameToken");
    outConfig.put(ConfigurationConstants.USER, "username");
    outConfig.put(ConfigurationConstants.ENCRYPTION_USER, "myalias");
    outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    outConfig.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
    outConfig.put(ConfigurationConstants.ENC_SYM_ALGO, XMLSecurityConstants.NS_XENC_AES128);
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
    client.getOutInterceptors().add(ohandler);
    assertEquals("test", echo.echo("test"));
}
Also used : HashMap(java.util.HashMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Service(org.apache.cxf.service.Service) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 60 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.

the class StaxRoundTripActionTest method testEncryptSignatureConfig.

@Test
public void testEncryptSignatureConfig() throws Exception {
    // Create + configure service
    Service service = createService();
    Map<String, Object> inConfig = new HashMap<>();
    inConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPT + " " + ConfigurationConstants.SIGNATURE);
    inConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    inConfig.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    inConfig.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
    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> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPT + " " + ConfigurationConstants.SIGNATURE);
    outConfig.put(ConfigurationConstants.SIGNATURE_USER, "myalias");
    outConfig.put(ConfigurationConstants.ENCRYPTION_USER, "myalias");
    outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    outConfig.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
    outConfig.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
    outConfig.put(ConfigurationConstants.ENC_SYM_ALGO, XMLSecurityConstants.NS_XENC_AES128);
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
    client.getOutInterceptors().add(ohandler);
    assertEquals("test", echo.echo("test"));
}
Also used : HashMap(java.util.HashMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Service(org.apache.cxf.service.Service) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Aggregations

LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)224 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)207 Test (org.junit.Test)175 Service (org.apache.cxf.service.Service)138 Client (org.apache.cxf.endpoint.Client)135 HashMap (java.util.HashMap)101 WSSSecurityProperties (org.apache.wss4j.stax.ext.WSSSecurityProperties)89 ArrayList (java.util.ArrayList)68 Properties (java.util.Properties)65 WSSConstants (org.apache.wss4j.stax.ext.WSSConstants)61 QName (javax.xml.namespace.QName)35 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)22 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)21 AbstractSecurityTest (org.apache.cxf.ws.security.wss4j.AbstractSecurityTest)18 Echo (org.apache.cxf.ws.security.wss4j.Echo)18 Bus (org.apache.cxf.Bus)16 URL (java.net.URL)15 Server (org.apache.cxf.endpoint.Server)14 Greeter (org.apache.cxf.greeter_control.Greeter)14 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)13