@Test(expected = AuthorizationException.class) public void testForbidden() { mockery.checking(new Expectations() { { allowing(activityIdFromParamsTransformer).transform(params); will(returnValue(ACTIVITY_ID)); allowing(getActivityDAO).execute(ACTIVITY_ID); will(returnValue(activity)); oneOf(activityAuthorizer).authorize(USER_ID, activity, ActivityInteractionType.COMMENT); will(returnValue(false)); } }); sut.authorize(TestContextCreator.createPrincipalActionContext(params, null, USER_ID)); mockery.assertIsSatisfied(); }
public void authorize(final PrincipalActionContext inActionContext) { ActivityDTO activity = null; final Principal principal = inActionContext.getPrincipal(); try { long activityId = activityIdFromParamsTransformer.transform(inActionContext.getParams()); activity = getActivityDAO.execute(activityId); } catch (Exception ex) { logger.error("Error occurred retrieving the activity dto params.", ex); throw new AuthorizationException( "This action could not authorize the request due to failure retrieving parameters.", ex); } if (!activityAuthorizer.authorize(principal.getId(), activity, type)) { throw new AuthorizationException("Current user does not have permissions to " + type.toString().toLowerCase() + " activity."); } }
ActivityAuthorizationStrategy implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) { ActivityDTO activity = null; final Principal principal = inActionContext.getPrincipal(); try { long activityId = activityIdFromParamsTransformer.transform(inActionContext.getParams()); activity = getActivityDAO.execute(activityId); } catch (Exception ex) { logger.error("Error occurred retrieving the activity dto params.", ex); throw new AuthorizationException( "This action could not authorize the request due to failure retrieving parameters.", ex); } if (!activityAuthorizer.authorize(principal.getId(), activity, type)) { throw new AuthorizationException("Current user does not have permissions to " + type.toString().toLowerCase() + " activity."); } } }
ActivityAuthorizationStrategy implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) { ActivityDTO activity = null; final Principal principal = inActionContext.getPrincipal(); try { long activityId = activityIdFromParamsTransformer.transform(inActionContext.getParams()); activity = getActivityDAO.execute(activityId); } catch (Exception ex) { logger.error("Error occurred retrieving the activity dto params.", ex); throw new AuthorizationException( "This action could not authorize the request due to failure retrieving parameters.", ex); } if (!activityAuthorizer.authorize(principal.getId(), activity, type)) { throw new AuthorizationException("Current user does not have permissions to " + type.toString().toLowerCase() + " activity."); } } ActivityAuthorizationStrategy(final ActivityInteractionAuthorizationStrategy inActivityAuthorizer,
            final ActivityInteractionType inType,
            final Transformer<Serializable, Long> inActivityIdFromParamsTransformer,
            final DomainMapper<Long, ActivityDTO> inGetActivityDAO); }
ActivityAuthorizationStrategy implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) { ActivityDTO activity = null; final Principal principal = inActionContext.getPrincipal(); try { long activityId = activityIdFromParamsTransformer.transform(inActionContext.getParams()); activity = getActivityDAO.execute(activityId); } catch (Exception ex) { logger.error("Error occurred retrieving the activity dto params.", ex); throw new AuthorizationException( "This action could not authorize the request due to failure retrieving parameters.", ex); } if (!activityAuthorizer.authorize(principal.getId(), activity, type)) { throw new AuthorizationException("Current user does not have permissions to " + type.toString().toLowerCase() + " activity."); } } ActivityAuthorizationStrategy(final ActivityInteractionAuthorizationStrategy inActivityAuthorizer,
            final ActivityInteractionType inType,
            final Transformer<Serializable, Long> inActivityIdFromParamsTransformer,
            final DomainMapper<Long, ActivityDTO> inGetActivityDAO); void authorize(final PrincipalActionContext inActionContext); }
ActivityAuthorizationStrategy implements AuthorizationStrategy<PrincipalActionContext> { public void authorize(final PrincipalActionContext inActionContext) { ActivityDTO activity = null; final Principal principal = inActionContext.getPrincipal(); try { long activityId = activityIdFromParamsTransformer.transform(inActionContext.getParams()); activity = getActivityDAO.execute(activityId); } catch (Exception ex) { logger.error("Error occurred retrieving the activity dto params.", ex); throw new AuthorizationException( "This action could not authorize the request due to failure retrieving parameters.", ex); } if (!activityAuthorizer.authorize(principal.getId(), activity, type)) { throw new AuthorizationException("Current user does not have permissions to " + type.toString().toLowerCase() + " activity."); } } ActivityAuthorizationStrategy(final ActivityInteractionAuthorizationStrategy inActivityAuthorizer,
            final ActivityInteractionType inType,
            final Transformer<Serializable, Long> inActivityIdFromParamsTransformer,
            final DomainMapper<Long, ActivityDTO> inGetActivityDAO); void authorize(final PrincipalActionContext inActionContext);  }