Java Code Examples for org.apache.cxf.configuration.security.AuthorizationPolicy#setAuthorizationType()

The following examples show how to use org.apache.cxf.configuration.security.AuthorizationPolicy#setAuthorizationType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientConfig.java    From cxf-jaxws with MIT License 5 votes vote down vote up
@Bean
public AuthorizationPolicy basicAuthorization() {
  AuthorizationPolicy authorizationPolicy =
      new AuthorizationPolicy();
  authorizationPolicy.setUserName(userName);
  authorizationPolicy.setPassword(password);
  authorizationPolicy.setAuthorizationType("Basic");

  return authorizationPolicy;
}
 
Example 2
Source File: BasicAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: UndertowDigestAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void configure(String name, String address, HTTPConduit c) {

            AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();

            authorizationPolicy.setUserName("ffang");
            authorizationPolicy.setPassword("pswd");
            authorizationPolicy.setAuthorizationType("Digest");
            c.setAuthorization(authorizationPolicy);
        }
 
Example 4
Source File: UndertowBasicAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void configure(String name, String address, HTTPConduit c) {

            AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();

            authorizationPolicy.setUserName("ffang");
            authorizationPolicy.setPassword("pswd");
            authorizationPolicy.setAuthorizationType("Basic");
            c.setAuthorization(authorizationPolicy);
        }
 
Example 5
Source File: JAXRSKerberosBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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("[email protected]");
    kbInterceptor.setServiceNameType(GSSName.NT_HOSTBASED_SERVICE);

    Book b = wc.get(Book.class);
    Assert.assertEquals(b.getId(), 123);
}
 
Example 6
Source File: JettyDigestAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void configure(String name, String address, HTTPConduit c) {

            AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();

            authorizationPolicy.setUserName("ffang");
            authorizationPolicy.setPassword("pswd");
            authorizationPolicy.setAuthorizationType("Digest");
            c.setAuthorization(authorizationPolicy);
        }
 
Example 7
Source File: JettyBasicAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void configure(String name, String address, HTTPConduit c) {

            AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();

            authorizationPolicy.setUserName("ffang");
            authorizationPolicy.setPassword("pswd");
            authorizationPolicy.setAuthorizationType("Basic");
            c.setAuthorization(authorizationPolicy);
        }
 
Example 8
Source File: DigestAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);

}
 
Example 9
Source File: HTTPConduitTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * This test verifies the precedence of Authorization Information.
 * Setting authorization information on the Message takes precedence
 * over a Basic Auth Supplier with preemptive UserPass, and that
 * followed by setting it directly on the Conduit.
 */
@Test
public void testAuthPolicyPrecedence() throws Exception {
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    conduit.finalizeConfig();

    conduit.getAuthorization().setUserName("Satan");
    conduit.getAuthorization().setPassword("hell");
    Message message = getNewMessage();

    // Test call
    conduit.prepare(message);

    Map<String, List<String>> headers =
        CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));

    assertNotNull("Authorization Header should exist",
            headers.get("Authorization"));

    assertEquals("Unexpected Authorization Token",
        DefaultBasicAuthSupplier.getBasicAuthHeader("Satan", "hell"),
            headers.get("Authorization").get(0));

    // Setting a Basic Auth User Pass should override
    conduit.setAuthSupplier(new TestAuthSupplier());
    message = getNewMessage();

    // Test Call
    conduit.prepare(message);

    headers =
        CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
    List<String> authorization = headers.get("Authorization");
    assertNotNull("Authorization Token must be set", authorization);
    assertEquals("Wrong Authorization Token", "myauth", authorization.get(0));

    conduit.setAuthSupplier(null);
    // Setting authorization policy on the message should override
    // conduit setting
    AuthorizationPolicy authPolicy = new AuthorizationPolicy();
    authPolicy.setUserName("Hello");
    authPolicy.setPassword("world");
    authPolicy.setAuthorizationType("Basic");
    message = getNewMessage();
    message.put(AuthorizationPolicy.class, authPolicy);

    conduit.prepare(message);

    headers =
        CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));

    assertEquals("Unexpected Authorization Token",
        DefaultBasicAuthSupplier.getBasicAuthHeader("Hello", "world"),
            headers.get("Authorization").get(0));
}