Search in sources :

Example 1 with KerberosAuthOutInterceptor

use of org.apache.cxf.jaxrs.security.KerberosAuthOutInterceptor 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)

Aggregations

AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)1 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 KerberosAuthOutInterceptor (org.apache.cxf.jaxrs.security.KerberosAuthOutInterceptor)1 Test (org.junit.Test)1