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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations