@Test(expected = AuthorizationException.class) public void testAuthorizeFollowingFailUserFollowingSelf() { final SetFollowingStatusRequest request = new SetFollowingStatusRequest("ntaccount", "ntaccount", EntityType.PERSON, false, Follower.FollowerStatus.FOLLOWING); context.checking(new Expectations() { { oneOf(principalMock).getAccountId(); will(returnValue("ntaccount")); } }); ServiceActionContext currentContext = new ServiceActionContext(request, principalMock); sut.authorize(currentContext); context.assertIsSatisfied(); }
@Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getParams(); if (request.getFollowerUniqueId() != null && request.getFollowerUniqueId().equals(request.getTargetUniqueId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_FOLLOWING_SELF); throw new AuthorizationException(AUTH_ERROR_FOLLOWING_SELF); } if (request.getFollowerUniqueId() != null && !request.getFollowerUniqueId() .equals(inActionContext.getPrincipal().getAccountId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_NONOWNER_FOLLOWING); throw new AuthorizationException(AUTH_ERROR_NONOWNER_FOLLOWING); } }
SetFollowingPersonStatusAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getParams(); if (request.getFollowerUniqueId() != null && request.getFollowerUniqueId().equals(request.getTargetUniqueId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_FOLLOWING_SELF); throw new AuthorizationException(AUTH_ERROR_FOLLOWING_SELF); } if (request.getFollowerUniqueId() != null && !request.getFollowerUniqueId() .equals(inActionContext.getPrincipal().getAccountId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_NONOWNER_FOLLOWING); throw new AuthorizationException(AUTH_ERROR_NONOWNER_FOLLOWING); } } }
SetFollowingPersonStatusAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getParams(); if (request.getFollowerUniqueId() != null && request.getFollowerUniqueId().equals(request.getTargetUniqueId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_FOLLOWING_SELF); throw new AuthorizationException(AUTH_ERROR_FOLLOWING_SELF); } if (request.getFollowerUniqueId() != null && !request.getFollowerUniqueId() .equals(inActionContext.getPrincipal().getAccountId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_NONOWNER_FOLLOWING); throw new AuthorizationException(AUTH_ERROR_NONOWNER_FOLLOWING); } }  }
SetFollowingPersonStatusAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getParams(); if (request.getFollowerUniqueId() != null && request.getFollowerUniqueId().equals(request.getTargetUniqueId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_FOLLOWING_SELF); throw new AuthorizationException(AUTH_ERROR_FOLLOWING_SELF); } if (request.getFollowerUniqueId() != null && !request.getFollowerUniqueId() .equals(inActionContext.getPrincipal().getAccountId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_NONOWNER_FOLLOWING); throw new AuthorizationException(AUTH_ERROR_NONOWNER_FOLLOWING); } }  @Override void authorize(final PrincipalActionContext inActionContext); }
SetFollowingPersonStatusAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getParams(); if (request.getFollowerUniqueId() != null && request.getFollowerUniqueId().equals(request.getTargetUniqueId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_FOLLOWING_SELF); throw new AuthorizationException(AUTH_ERROR_FOLLOWING_SELF); } if (request.getFollowerUniqueId() != null && !request.getFollowerUniqueId() .equals(inActionContext.getPrincipal().getAccountId())) { logger.error("Error occurred authorizing Following a person: " + AUTH_ERROR_NONOWNER_FOLLOWING); throw new AuthorizationException(AUTH_ERROR_NONOWNER_FOLLOWING); } }  @Override void authorize(final PrincipalActionContext inActionContext);  }