Search in sources :

Example 56 with WSS4JOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.

the class JavaFirstPolicyServiceTest method testOperationNoClientCertAlternativePolicy.

@Test
public void testOperationNoClientCertAlternativePolicy() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
    ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslnocertclient.xml" });
    OperationSimpleService simpleService = clientContext.getBean("OperationSimpleServiceClient", OperationSimpleService.class);
    // no security on ping!
    simpleService.ping();
    try {
        simpleService.doStuff();
        fail("Expected exception as no credentials");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    WSS4JOutInterceptor wssOut = addToClient(simpleService);
    wssOut.setProperties(getNoPasswordProperties("alice"));
    try {
        simpleService.doStuff();
        fail("Expected exception as no password and no client cert");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    // this is successful because the alternative policy allows a password to be specified.
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    simpleService.doStuff();
    clientContext.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) OperationSimpleService(org.apache.cxf.systest.ws.policy.javafirst.OperationSimpleService) NoAlternativesOperationSimpleService(org.apache.cxf.systest.ws.policy.javafirst.NoAlternativesOperationSimpleService) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Test(org.junit.Test)

Example 57 with WSS4JOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.

the class JavaFirstPolicyServiceTest method testNoAltOperationClientCertPolicy.

@Test
public void testNoAltOperationClientCertPolicy() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
    ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslcertclient.xml" });
    NoAlternativesOperationSimpleService simpleService = clientContext.getBean("NoAlternativesOperationSimpleServiceClient", NoAlternativesOperationSimpleService.class);
    try {
        simpleService.doStuff();
        fail("Expected exception as no credentials");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    WSS4JOutInterceptor wssOut = addToClient(simpleService);
    wssOut.setProperties(getNoPasswordProperties("alice"));
    simpleService.doStuff();
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    try {
        simpleService.doStuff();
        fail("Expected exception as password not allowed");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    wssOut.setProperties(getNoPasswordProperties("alice"));
    try {
        simpleService.ping();
        fail("Expected exception as no password");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    simpleService.ping();
    clientContext.close();
}
Also used : NoAlternativesOperationSimpleService(org.apache.cxf.systest.ws.policy.javafirst.NoAlternativesOperationSimpleService) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Test(org.junit.Test)

Example 58 with WSS4JOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.

the class JavaFirstPolicyServiceTest method testUsernameTokenPolicyValidatorNoPasswordValidation.

@org.junit.Test
public void testUsernameTokenPolicyValidatorNoPasswordValidation() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.2", PORT2);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/apache/cxf/systest/ws/policy/javafirstclient.xml");
    SslUsernamePasswordAttachmentService svc = ctx.getBean("SslUsernamePasswordAttachmentServiceClient", SslUsernamePasswordAttachmentService.class);
    WSS4JOutInterceptor wssOut = addToClient(svc);
    // just some basic sanity tests first to make sure that auth is working where password is provided.
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    svc.doSslAndUsernamePasswordPolicy();
    wssOut.setProperties(getPasswordProperties("alice", "passwordX"));
    try {
        svc.doSslAndUsernamePasswordPolicy();
        fail("Expected authentication failure");
    } catch (Exception e) {
        assertTrue(true);
    }
    wssOut.setProperties(getNoPasswordProperties("alice"));
    try {
        svc.doSslAndUsernamePasswordPolicy();
        fail("Expected authentication failure");
    } catch (Exception e) {
        assertTrue(true);
    }
    ctx.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 59 with WSS4JOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.

the class JavaFirstPolicyServiceTest method testBindingClientCertAlternativePolicy.

@Test
public void testBindingClientCertAlternativePolicy() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
    ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslcertclient.xml" });
    BindingSimpleService simpleService = clientContext.getBean("BindingSimpleServiceClient", BindingSimpleService.class);
    try {
        simpleService.doStuff();
        fail("Expected exception as no credentials");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    WSS4JOutInterceptor wssOut = addToClient(simpleService);
    wssOut.setProperties(getNoPasswordProperties("alice"));
    simpleService.doStuff();
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    // this is successful because the alternative policy allows a password to be specified.
    simpleService.doStuff();
    clientContext.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BindingSimpleService(org.apache.cxf.systest.ws.policy.javafirst.BindingSimpleService) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Test(org.junit.Test)

Example 60 with WSS4JOutInterceptor

use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project cxf by apache.

the class JavaFirstPolicyServiceTest method testNoAltOperationNoClientCertPolicy.

@Test
public void testNoAltOperationNoClientCertPolicy() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
    ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslnocertclient.xml" });
    NoAlternativesOperationSimpleService simpleService = clientContext.getBean("NoAlternativesOperationSimpleServiceClient", NoAlternativesOperationSimpleService.class);
    try {
        simpleService.doStuff();
        fail("Expected exception as no credentials");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    WSS4JOutInterceptor wssOut = addToClient(simpleService);
    wssOut.setProperties(getNoPasswordProperties("alice"));
    try {
        simpleService.doStuff();
        fail("Expected exception as no password and no client cert");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    try {
        simpleService.doStuff();
        fail("Expected exception as no client cert and password not allowed");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    wssOut.setProperties(getNoPasswordProperties("alice"));
    try {
        simpleService.ping();
        fail("Expected exception as no password");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    simpleService.ping();
    clientContext.close();
}
Also used : NoAlternativesOperationSimpleService(org.apache.cxf.systest.ws.policy.javafirst.NoAlternativesOperationSimpleService) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Test(org.junit.Test)

Aggregations

WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)63 HashMap (java.util.HashMap)48 QName (javax.xml.namespace.QName)31 URL (java.net.URL)30 Client (org.apache.cxf.endpoint.Client)27 Service (javax.xml.ws.Service)26 Test (org.junit.Test)23 Bus (org.apache.cxf.Bus)19 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)17 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)15 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)12 WSS4JStaxOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor)12 Endpoint (org.apache.cxf.endpoint.Endpoint)9 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 CallbackHandler (javax.security.auth.callback.CallbackHandler)7 BindingProvider (javax.xml.ws.BindingProvider)7 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)7 ModelPortType (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType)6 ModelService (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService)6