@Test public void testAuthorizeSuccess() { context.checking(new Expectations() { { allowing(actionContext).getParams(); will(returnValue(commentId)); allowing(actionContext).getPrincipal(); will(returnValue(principal)); allowing(principal).getAccountId(); will(returnValue(userAcctId)); oneOf(comment).getActivityId(); will(returnValue(parentActivityId)); oneOf(activityDAO).execute(activityIds); will(returnValue(activities)); oneOf(commentDAO).execute(commentIds); will(returnValue(comments)); oneOf(commentDeletableSetter).execute(userAcctId, parentActivity, comments); oneOf(comment).isDeletable(); will(returnValue(true)); } }); sut.authorize(actionContext); context.assertIsSatisfied(); }
@SuppressWarnings("serial") @Override public void authorize(final PrincipalActionContext inActionContext) { final long commentId = (Long) inActionContext.getParams(); String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); final CommentDTO comment = getCommentById(commentId); commentDeletableSetter.execute(currentUserAccountId, getParentActivity(comment, currentUserAccountId), new ArrayList<CommentDTO>() { { add(comment); } }); if (!comment.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify comment id: " + commentId); } }
CommentModificationAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @SuppressWarnings("serial") @Override public void authorize(final PrincipalActionContext inActionContext) { final long commentId = (Long) inActionContext.getParams(); String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); final CommentDTO comment = getCommentById(commentId); commentDeletableSetter.execute(currentUserAccountId, getParentActivity(comment, currentUserAccountId), new ArrayList<CommentDTO>() { { add(comment); } }); if (!comment.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify comment id: " + commentId); } } }
CommentModificationAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @SuppressWarnings("serial") @Override public void authorize(final PrincipalActionContext inActionContext) { final long commentId = (Long) inActionContext.getParams(); String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); final CommentDTO comment = getCommentById(commentId); commentDeletableSetter.execute(currentUserAccountId, getParentActivity(comment, currentUserAccountId), new ArrayList<CommentDTO>() { { add(comment); } }); if (!comment.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify comment id: " + commentId); } } CommentModificationAuthorization(final DomainMapper<List<Long>, List<CommentDTO>> inCommentDAO,
            final DomainMapper<List<Long>, List<ActivityDTO>> inActivityDAO,
            final CommentDeletePropertyStrategy inCommentDeletableSetter); }
CommentModificationAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @SuppressWarnings("serial") @Override public void authorize(final PrincipalActionContext inActionContext) { final long commentId = (Long) inActionContext.getParams(); String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); final CommentDTO comment = getCommentById(commentId); commentDeletableSetter.execute(currentUserAccountId, getParentActivity(comment, currentUserAccountId), new ArrayList<CommentDTO>() { { add(comment); } }); if (!comment.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify comment id: " + commentId); } } CommentModificationAuthorization(final DomainMapper<List<Long>, List<CommentDTO>> inCommentDAO,
            final DomainMapper<List<Long>, List<ActivityDTO>> inActivityDAO,
            final CommentDeletePropertyStrategy inCommentDeletableSetter); @SuppressWarnings("serial") @Override void authorize(final PrincipalActionContext inActionContext); }
CommentModificationAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @SuppressWarnings("serial") @Override public void authorize(final PrincipalActionContext inActionContext) { final long commentId = (Long) inActionContext.getParams(); String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); final CommentDTO comment = getCommentById(commentId); commentDeletableSetter.execute(currentUserAccountId, getParentActivity(comment, currentUserAccountId), new ArrayList<CommentDTO>() { { add(comment); } }); if (!comment.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify comment id: " + commentId); } } CommentModificationAuthorization(final DomainMapper<List<Long>, List<CommentDTO>> inCommentDAO,
            final DomainMapper<List<Long>, List<ActivityDTO>> inActivityDAO,
            final CommentDeletePropertyStrategy inCommentDeletableSetter); @SuppressWarnings("serial") @Override void authorize(final PrincipalActionContext inActionContext);  }