use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class JAXRSKerberosBookTest method testGetBookWithInterceptor.
@Test
public void testGetBookWithInterceptor() throws Exception {
if (!runTests) {
return;
}
WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/123");
KerberosAuthOutInterceptor kbInterceptor = new KerberosAuthOutInterceptor();
AuthorizationPolicy policy = new AuthorizationPolicy();
policy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_NEGOTIATE);
policy.setAuthorization("alice");
policy.setUserName("alice");
policy.setPassword("alice");
kbInterceptor.setPolicy(policy);
kbInterceptor.setCredDelegation(true);
WebClient.getConfig(wc).getOutInterceptors().add(new LoggingOutInterceptor());
WebClient.getConfig(wc).getOutInterceptors().add(kbInterceptor);
// Required so as to get it working with our KDC
kbInterceptor.setServicePrincipalName("bob@service.ws.apache.org");
kbInterceptor.setServiceNameType(GSSName.NT_HOSTBASED_SERVICE);
Book b = wc.get(Book.class);
Assert.assertEquals(b.getId(), 123);
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class DigestAuthTest method testDigestAuth.
@Test
public void testDigestAuth() throws Exception {
URL wsdl = getClass().getResource("../greeting.wsdl");
assertNotNull("WSDL is null", wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull("Service is null", service);
Greeter mortimer = service.getPort(mortimerQ, Greeter.class);
assertNotNull("Port is null", mortimer);
TestUtil.setAddress(mortimer, "http://localhost:" + PORT + "/digestauth/greeter");
Client client = ClientProxy.getClient(mortimer);
HTTPConduit http = (HTTPConduit) client.getConduit();
AuthorizationPolicy authPolicy = new AuthorizationPolicy();
authPolicy.setAuthorizationType("Digest");
authPolicy.setUserName("foo");
authPolicy.setPassword("bar");
http.setAuthorization(authPolicy);
String answer = mortimer.sayHi();
assertEquals("Unexpected answer: " + answer, "Hi", answer);
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class JAASResourceOwnerLoginHandler method setupMessage.
private Message setupMessage(String name, String password) {
AuthorizationPolicy policy = new AuthorizationPolicy();
policy.setUserName(name);
policy.setPassword(password);
Message message = new MessageImpl();
message.put(AuthorizationPolicy.class, policy);
return message;
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class JettyHTTPDestinationTest method verifyRequestHeaders.
private void verifyRequestHeaders() throws Exception {
Map<String, List<String>> requestHeaders = CastUtils.cast((Map<?, ?>) inMessage.get(Message.PROTOCOL_HEADERS));
assertNotNull("expected request headers", requestHeaders);
List<String> values = requestHeaders.get("content-type");
assertNotNull("expected field", values);
assertEquals("unexpected values", 2, values.size());
assertTrue("expected value", values.contains("text/xml"));
assertTrue("expected value", values.contains("charset=utf8"));
values = requestHeaders.get(AUTH_HEADER);
assertNotNull("expected field", values);
assertEquals("unexpected values", 1, values.size());
assertTrue("expected value", values.contains(BASIC_AUTH));
AuthorizationPolicy authpolicy = inMessage.get(AuthorizationPolicy.class);
assertNotNull("Expected some auth tokens", policy);
assertEquals("expected user", USER, authpolicy.getUserName());
assertEquals("expected passwd", PASSWD, authpolicy.getPassword());
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project cxf by apache.
the class BasicAuthTest method testBasicAuthViaAuthorizationPolicy.
@org.junit.Test
public void testBasicAuthViaAuthorizationPolicy() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = BasicAuthTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = BasicAuthTest.class.getResource("DoubleItBasicAuth.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItBasicAuthPort2");
DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(utPort, PORT);
Client client = ClientProxy.getClient(utPort);
HTTPConduit http = (HTTPConduit) client.getConduit();
AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName("Alice");
authorizationPolicy.setPassword("ecilA");
authorizationPolicy.setAuthorizationType("Basic");
http.setAuthorization(authorizationPolicy);
assertEquals(50, utPort.doubleIt(25));
((java.io.Closeable) utPort).close();
bus.shutdown(true);
}
Aggregations