Search in sources :

Example 1 with OperationSimpleService

use of org.apache.cxf.systest.ws.policy.javafirst.OperationSimpleService in project cxf by apache.

the class JavaFirstPolicyServiceTest method testOperationClientCertAlternativePolicy.

@Test
public void testOperationClientCertAlternativePolicy() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
    ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslcertclient.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"));
    simpleService.doStuff();
    // 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 2 with OperationSimpleService

use of org.apache.cxf.systest.ws.policy.javafirst.OperationSimpleService 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)

Aggregations

SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 NoAlternativesOperationSimpleService (org.apache.cxf.systest.ws.policy.javafirst.NoAlternativesOperationSimpleService)2 OperationSimpleService (org.apache.cxf.systest.ws.policy.javafirst.OperationSimpleService)2 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)2 Test (org.junit.Test)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2