use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class AuthPolicyValidatingInterceptorTest method testNoUsername.
@Test
public void testNoUsername() throws Exception {
AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor();
TestSTSTokenValidator validator = new TestSTSTokenValidator();
in.setValidator(validator);
AuthorizationPolicy policy = new AuthorizationPolicy();
policy.setPassword("pswd");
Message message = new MessageImpl();
message.put(AuthorizationPolicy.class, policy);
try {
in.handleMessage(message);
fail("Failure expected with no username");
} catch (SecurityException ex) {
// expected
}
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class AuthPolicyValidatingInterceptorTest method testInvalidUsernamePassword.
@Test
public void testInvalidUsernamePassword() throws Exception {
AuthPolicyValidatingInterceptor in = new AuthPolicyValidatingInterceptor();
TestSTSTokenValidator validator = new TestSTSTokenValidator();
in.setValidator(validator);
AuthorizationPolicy policy = new AuthorizationPolicy();
policy.setUserName("bob");
policy.setPassword("pswd2");
Message message = new MessageImpl();
message.put(AuthorizationPolicy.class, policy);
in.handleMessage(message);
assertFalse(validator.isValidated());
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class JAXRSJaasSecurityTest method testJaasFilterAuthenticationFailure.
@Test
public void testJaasFilterAuthenticationFailure() throws Exception {
String endpointAddress = "http://localhost:" + PORT + "/service/jaas2/bookstorestorage/thosebooks/123";
WebClient wc = WebClient.create(endpointAddress);
AuthorizationPolicy pol = new AuthorizationPolicy();
pol.setUserName("foo");
pol.setPassword("bar1");
WebClient.getConfig(wc).getHttpConduit().setAuthorization(pol);
wc.accept("application/xml");
// wc.header(HttpHeaders.AUTHORIZATION,
// "Basic " + base64Encode("foo" + ":" + "bar1"));
Response r = wc.get();
assertEquals(401, r.getStatus());
Object wwwAuthHeader = r.getMetadata().getFirst(HttpHeaders.WWW_AUTHENTICATE);
assertNotNull(wwwAuthHeader);
assertEquals("Basic", wwwAuthHeader.toString());
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class JAXRSJaasSecurityTest method testJaasFilterWebClientAuthorizationPolicy.
@Test
public void testJaasFilterWebClientAuthorizationPolicy() throws Exception {
String endpointAddress = "http://localhost:" + PORT + "/service/jaas2/bookstorestorage/thosebooks/123";
WebClient wc = WebClient.create(endpointAddress);
AuthorizationPolicy pol = new AuthorizationPolicy();
pol.setUserName("bob");
pol.setPassword("bobspassword");
WebClient.getConfig(wc).getHttpConduit().setAuthorization(pol);
wc.accept("application/xml");
Book book = wc.get(Book.class);
assertEquals(123L, book.getId());
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class ClientServerTest method testBasicAuth.
@Test
public void testBasicAuth() throws Exception {
Service service = Service.create(serviceName);
service.addPort(fakePortName, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + PORT + "/SoapContext/SoapPort");
Greeter greeter = service.getPort(fakePortName, Greeter.class);
try {
// try the jaxws way
BindingProvider bp = (BindingProvider) greeter;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
String s = greeter.greetMe("secure");
assertEquals("Hello BJ", s);
bp.getRequestContext().remove(BindingProvider.USERNAME_PROPERTY);
bp.getRequestContext().remove(BindingProvider.PASSWORD_PROPERTY);
// try setting on the conduit directly
Client client = ClientProxy.getClient(greeter);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
AuthorizationPolicy policy = new AuthorizationPolicy();
policy.setUserName("BJ2");
policy.setPassword("pswd");
httpConduit.setAuthorization(policy);
s = greeter.greetMe("secure");
assertEquals("Hello BJ2", s);
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
}
}
Aggregations