Java Code Examples for org.glassfish.jersey.client.authentication.HttpAuthenticationFeature#digest()

The following examples show how to use org.glassfish.jersey.client.authentication.HttpAuthenticationFeature#digest() . 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: TestLDAPAuthentication.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void testAuthenticationAndRoleMapping(String baseURL, String  authType, String username, String password,
                                              String role) {
  String userInfoURI = baseURL  + "/rest/v1/system/info/currentUser";
  HttpAuthenticationFeature feature = null;

  switch(authType) {
    case "basic":
    case "form":
      feature = HttpAuthenticationFeature.basic(username, password);
      break;
    case "digest":
      feature = HttpAuthenticationFeature.digest(username, password);
      break;
  }

  Response response = ClientBuilder
      .newClient()
      .register(feature)
      .target(userInfoURI)
      .request()
      .get();
  Assert.assertEquals(200, response.getStatus());
  Map userInfo = response.readEntity(Map.class);
  Assert.assertTrue(userInfo.containsKey("user"));
  Assert.assertEquals(username, userInfo.get("user"));
  Assert.assertTrue(userInfo.containsKey("roles"));
  List<String> roles = (List<String>)userInfo.get("roles");
  Assert.assertEquals(1, roles.size());
  Assert.assertEquals(role, roles.get(0));
}
 
Example 2
Source File: JerseyClientHeaders.java    From tutorials with MIT License 5 votes vote down vote up
public static Response digestAuthenticationAtClientLevel(String username, String password) {
    HttpAuthenticationFeature feature = HttpAuthenticationFeature.digest(username, password);
    Client client = ClientBuilder.newBuilder().register(feature).build();
    return client.target(TARGET)
            .path(MAIN_RESOURCE)
            .path(RESOURCE_AUTH_DIGEST)
            .request()
            .get();
}
 
Example 3
Source File: JerseyClientHeaders.java    From tutorials with MIT License 5 votes vote down vote up
public static Response digestAuthenticationAtRequestLevel(String username, String password) {
    HttpAuthenticationFeature feature = HttpAuthenticationFeature.digest();

    Client client = ClientBuilder.newBuilder().register(feature).build();
    return client.target(TARGET)
            .path(MAIN_RESOURCE)
            .path(RESOURCE_AUTH_DIGEST)
            .request()
            .property(HTTP_AUTHENTICATION_DIGEST_USERNAME, username)
            .property(HTTP_AUTHENTICATION_DIGEST_PASSWORD, password)
            .get();
}
 
Example 4
Source File: HttpDigestAuth.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
public void setFilter(WebTarget webTarget) {
  HttpAuthenticationFeature feature = HttpAuthenticationFeature.digest(username, password);
  webTarget.register(feature);
}
 
Example 5
Source File: TestUserGroupManager.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Test
public void testDigestAuthentication() throws Exception {
  String usersListURI =  startServer("digest") + "/rest/v1/system/users";
  HttpAuthenticationFeature loginFeature = HttpAuthenticationFeature.digest("admin", "admin");
  testGetUsers(usersListURI, loginFeature);
}