Search in sources :

Example 1 with HttpAuthenticationFeature

use of org.glassfish.jersey.client.authentication.HttpAuthenticationFeature in project jersey by jersey.

the class SslConnectorConfigurationTest method testSSLWithNonPreemptiveAuth.

/**
     * Test that a response to an authentication challenge has the same SSL configuration as the original request.
     */
@Test
public void testSSLWithNonPreemptiveAuth() throws Exception {
    final SSLContext sslContext = getSslContext();
    final ClientConfig cc = new ClientConfig().connectorProvider(connectorProvider);
    final Client client = ClientBuilder.newBuilder().withConfig(cc).sslContext(sslContext).build();
    // client basic auth demonstration
    HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basicBuilder().nonPreemptive().credentials("user", "password").build();
    client.register(authFeature);
    final WebTarget target = client.target(Server.BASE_URI).register(LoggingFeature.class);
    final Response response = target.path("/").request().get(Response.class);
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) HttpAuthenticationFeature(org.glassfish.jersey.client.authentication.HttpAuthenticationFeature) SSLContext(javax.net.ssl.SSLContext) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Aggregations

SSLContext (javax.net.ssl.SSLContext)1 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 ClientConfig (org.glassfish.jersey.client.ClientConfig)1 HttpAuthenticationFeature (org.glassfish.jersey.client.authentication.HttpAuthenticationFeature)1 Test (org.junit.Test)1