當前位置: 首頁>>代碼示例>>Java>>正文


Java AuthenticationException類代碼示例

本文整理匯總了Java中io.dropwizard.auth.AuthenticationException的典型用法代碼示例。如果您正苦於以下問題:Java AuthenticationException類的具體用法?Java AuthenticationException怎麽用?Java AuthenticationException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AuthenticationException類屬於io.dropwizard.auth包,在下文中一共展示了AuthenticationException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getByKey

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@GET
@Path("/{group}")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
@Timed(name = "getByKey")
public Response getByKey(
    @Auth AuthPrincipal authPrincipal,
    @PathParam("group") String group
) throws AuthenticationException {

  final long start = System.currentTimeMillis();
  final Optional<Group> maybe = findGroup(group);

  if (maybe.isPresent()) {
    accessControlSupport.throwUnlessGrantedFor(authPrincipal, maybe.get());
    return headers.enrich(Response.ok(maybe.get()), start).build();
  }

  return headers.enrich(Response.status(404).entity(
      Problem.clientProblem(GroupResource.TITLE_NOT_FOUND, "", 404)), start).build();
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:22,代碼來源:GroupResource.java

示例2: removeService

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@DELETE
@Path("/{group}/access/services/{service_key}")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
@Timed(name = "removeService")
public Response removeService(
    @Auth AuthPrincipal authPrincipal,
    @PathParam("group") String groupKey,
    @PathParam("service_key") String serviceKey
) throws AuthenticationException {
  final long start = System.currentTimeMillis();

  final Optional<Group> maybe = findGroup(groupKey);

  if (maybe.isPresent()) {
    final Group group = maybe.get();
    accessControlSupport.throwUnlessGrantedFor(authPrincipal, group);
    final Group updated = groupService.removeServiceAccess(group, serviceKey);

    return headers.enrich(Response.ok(updated), start).build();
  }

  return headers.enrich(Response.status(404).entity(
      Problem.clientProblem(TITLE_NOT_FOUND, "", 404)), start).build();
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:26,代碼來源:GroupResource.java

示例3: removeMember

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@DELETE
@Path("/{group}/access/members/{member_key}")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
@Timed(name = "removeMember")
public Response removeMember(
    @Auth AuthPrincipal authPrincipal,
    @PathParam("group") String groupKey,
    @PathParam("member_key") String memberKey
) throws AuthenticationException {
  final long start = System.currentTimeMillis();

  final Optional<Group> maybe = findGroup(groupKey);

  if (maybe.isPresent()) {
    final Group group = maybe.get();
    accessControlSupport.throwUnlessGrantedFor(authPrincipal, group);
    final Group updated = groupService.removeMemberAccess(group, memberKey);

    return headers.enrich(Response.ok(updated), start).build();
  }

  return headers.enrich(Response.status(404).entity(
      Problem.clientProblem(TITLE_NOT_FOUND, "", 404)), start).build();
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:26,代碼來源:GroupResource.java

示例4: postUpdate

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
private Response postUpdate(
    AuthPrincipal authPrincipal,
    String groupKey,
    Function<Group, Group> updater
) throws AuthenticationException {

  final long start = System.currentTimeMillis();
  final Optional<Group> maybe = findGroup(groupKey);

  if (maybe.isPresent()) {
    final Group group = maybe.get();
    accessControlSupport.throwUnlessGrantedFor(authPrincipal, group);
    final Group updated = updater.apply(group);
    return headers.enrich(Response.ok(updated), start).build();
  }

  return headers.enrich(Response.status(404).entity(
      Problem.clientProblem(TITLE_NOT_FOUND, "", 404)), start).build();
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:20,代碼來源:GroupResource.java

示例5: updateFeature

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@POST
@Path("/{group}/{feature_key}")
@PermitAll
@Timed(name = "updateFeature")
public Response updateFeature(
    @Auth AuthPrincipal principal,
    @PathParam("group") String group,
    @PathParam("feature_key") String featureKey,
    Feature feature,
    @Context HttpHeaders httpHeaders
) throws AuthenticationException {

  final long start = System.currentTimeMillis();

  grantedGuard(principal, group);
  groupValidGuard(group, featureKey, feature);

  final Optional<String> maybeSeen = idempotencyChecker.extractKey(httpHeaders);
  if (maybeSeen.isPresent() && idempotencyChecker.seen(maybeSeen.get())) {
    return alreadyUpdated(feature, start, maybeSeen);
  }

  return headers.enrich(Response.ok(update(group, feature)), start).build();
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:25,代碼來源:FeatureResource.java

示例6: getFeatureByKey

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@GET
@Path("/{group}/{feature_key}")
@PermitAll
@Timed(name = "getFeatureByKey")
public Response getFeatureByKey(
    @Auth AuthPrincipal principal,
    @PathParam("group") String group,
    @PathParam("feature_key") String featureKey
) throws AuthenticationException {

  final long start = System.currentTimeMillis();
  grantedGuard(principal, group);
  return headers.enrich(
      featureService.loadFeatureByKey(group, featureKey)
          .map(Response::ok)
          .orElseGet(this::featureNotFound), start).build();
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:18,代碼來源:FeatureResource.java

示例7: throwUnlessGrantedFor

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
public void throwUnlessGrantedFor(AuthPrincipal authPrincipal, Group group)
    throws AuthenticationException {

  if (multipleGroupAccessList.contains(authPrincipal.identifier())) {
    logger.info(kvp("op", "member_access_check",
        "multiple_group_access_granted", authPrincipal.identifier()));
    return;
  }

  if (!GroupService.MEMBER.equals(authPrincipal.type()) && !GroupService.SERVICE.equals(
      authPrincipal.type())) {
    throw new AuthenticationException("Unknown type " + authPrincipal.type());
  }

  if (GroupService.MEMBER.equals(authPrincipal.type()) && !memberHasGrant(authPrincipal, group)) {
    throw new AuthenticationException("Member not authenticated");
  }

  if (GroupService.SERVICE.equals(authPrincipal.type()) && !serviceHasGrant(authPrincipal,
      group)) {
    throw new AuthenticationException("Service not authenticated");
  }
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:24,代碼來源:AccessControlSupport.java

示例8: postNewTodoItem

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@Test
public void postNewTodoItem() throws UnsupportedEncodingException, AuthenticationException {
   final String newTodoItem = fixture("fixtures/todoItem_new.json");
   final TodoItem expectedTodoItem = new TodoItem(1, "make new todo items", true);
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.createItem(eq(oacc), any(TodoItem.class)))
         .thenReturn(expectedTodoItem);

   final Response response = resources.getJerseyTest()
         .target("/todos")
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .post(Entity.entity(newTodoItem, MediaType.APPLICATION_JSON));

   assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());   // 200 OK
   assertThat(response.readEntity(TodoItem.class)).isEqualTo(expectedTodoItem);
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:20,代碼來源:TodoItemResourceTest.java

示例9: postNewTodoItemThatFailsValidation

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@Test
public void postNewTodoItemThatFailsValidation() throws AuthenticationException, UnsupportedEncodingException {
   final String blankTodoItem = fixture("fixtures/todoItem_blank.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.createItem(eq(oacc), any(TodoItem.class)))
         .thenThrow(new IllegalArgumentException("Either title or completed (or both) is required"));

   final Response response = resources.getJerseyTest()
         .target("/todos")
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .post(Entity.entity(blankTodoItem, MediaType.APPLICATION_JSON));

   assertThat(response.getStatus()).isEqualTo(422);   // 422 Unprocessable Entity
   verifyZeroInteractions(oacc);
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:19,代碼來源:TodoItemResourceTest.java

示例10: getTodoItems

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@Test
public void getTodoItems() throws AuthenticationException, UnsupportedEncodingException {
   final List<TodoItem> expectedTodoItems
         = Collections.singletonList(new TodoItem(1, "list all items", true));

   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.findByAuthenticatedUser(eq(oacc)))
         .thenReturn(expectedTodoItems);

   final Response response = resources.getJerseyTest()
         .target("/todos")
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .get();

   assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());   // 200 OK
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:20,代碼來源:TodoItemResourceTest.java

示例11: patchTodoItem

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@Test
public void patchTodoItem() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   final TodoItem expectedTodoItem = new TodoItem(1, "update titles", false);
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenReturn(expectedTodoItem);

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());   // 200 OK
   assertThat(response.readEntity(TodoItem.class)).isEqualTo(expectedTodoItem);
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:23,代碼來源:TodoItemResourceTest.java

示例12: patchTodoItemWithoutAuthorization

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@Test
public void patchTodoItemWithoutAuthorization() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new NotAuthorizedException("not authorized"));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.FORBIDDEN.getStatusCode());   // 403 Forbidden
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:21,代碼來源:TodoItemResourceTest.java

示例13: patchTodoItemThatDoesNotExist

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@Test
public void patchTodoItemThatDoesNotExist() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String todoItem = fixture("fixtures/todoItem_new.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new IllegalArgumentException("Resource " + todoItemId + " not found!"));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(todoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());   // 404 Not Found
   verifyZeroInteractions(oacc);
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:22,代碼來源:TodoItemResourceTest.java

示例14: patchTodoItemThatFailsValidation

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@Test
public void patchTodoItemThatFailsValidation() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String blankTodoItem = fixture("fixtures/todoItem_blank.json");
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);
   when(todoItemService.updateItem(eq(oacc), any(Long.class), any(TodoItem.class)))
         .thenThrow(new IllegalArgumentException("Either title or completed (or both) is required."));

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // to support PATCH
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .build("PATCH", Entity.entity(blankTodoItem, MediaType.APPLICATION_JSON))
         .invoke();

   assertThat(response.getStatus()).isEqualTo(422);   // 422 Unprocessable Entity
   verifyZeroInteractions(oacc);
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:22,代碼來源:TodoItemResourceTest.java

示例15: putShareAssociationOnTodoItem

import io.dropwizard.auth.AuthenticationException; //導入依賴的package包/類
@Test
public void putShareAssociationOnTodoItem() throws AuthenticationException, UnsupportedEncodingException {
   final long todoItemId = 1;
   final String targetEmail = "[email protected]";
   when(oaccBasicAuthenticator.authenticate(any(BasicCredentials.class)))
         .thenReturn(java.util.Optional.ofNullable(oaccPrincipal));
   when(oaccPrincipal.getAccessControlContext()).thenReturn(oacc);

   final Response response = resources.getJerseyTest()
         .target("/todos/" + todoItemId)
         .queryParam("share_with", targetEmail)
         .request()
         .header(Header.Authorization.name(), getBasicAuthHeader(EMAIL, PASSWORD))
         .put(Entity.json(""));

   assertThat(response.getStatus()).isEqualTo(Response.Status.NO_CONTENT.getStatusCode());   // 204 No Content
   assertThat(response.readEntity(Object.class)).isNull();
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:19,代碼來源:TodoItemResourceTest.java


注:本文中的io.dropwizard.auth.AuthenticationException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。