Search in sources :

Example 11 with AuthorizationPolicy

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);
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) KerberosAuthOutInterceptor(org.apache.cxf.jaxrs.security.KerberosAuthOutInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 12 with AuthorizationPolicy

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);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Greeter(org.apache.hello_world.Greeter) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) Test(org.junit.Test)

Example 13 with AuthorizationPolicy

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;
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 14 with AuthorizationPolicy

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());
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) List(java.util.List) ArrayList(java.util.ArrayList)

Example 15 with AuthorizationPolicy

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);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Bus(org.apache.cxf.Bus) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL)

Aggregations

AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)85 Message (org.apache.cxf.message.Message)25 Test (org.junit.Test)22 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)16 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)11 Client (org.apache.cxf.endpoint.Client)11 List (java.util.List)9 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)9 URL (java.net.URL)7 HashMap (java.util.HashMap)7 ProxyAuthorizationPolicy (org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)7 Map (java.util.Map)6 SecurityContext (org.apache.cxf.security.SecurityContext)6 Bus (org.apache.cxf.Bus)5 WebClient (org.apache.cxf.jaxrs.client.WebClient)5 MessageImpl (org.apache.cxf.message.MessageImpl)5 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)5 Principal (java.security.Principal)4 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)4