@Test public void testAuthorizeSuccess() throws Exception { context.checking(new Expectations() { { allowing(actionContext).getParams(); will(returnValue(activityId)); allowing(actionContext).getPrincipal(); will(returnValue(principal)); allowing(principal).getAccountId(); will(returnValue(userAcctId)); allowing(principal).getId(); will(returnValue(userId)); oneOf(activityDAO).execute(activityIds); will(returnValue(activities)); oneOf(activityDeletableSetter).execute(userAcctId, userId, activity); oneOf(activity).isDeletable(); will(returnValue(true)); } }); sut.authorize(actionContext); context.assertIsSatisfied(); }
@Override public void authorize(final PrincipalActionContext inActionContext) { Long activityId = (Long) inActionContext.getParams(); ActivityDTO activity = getActivityById(activityId); try { String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); Long currentUserId = inActionContext.getPrincipal().getId(); activityDeletePropertySetter.execute(currentUserAccountId, currentUserId, activity); } catch (Exception ex) { log.error("Error occurred determining access rights for activity delete.", ex); throw new AuthorizationException("Unable to determine access rights."); } if (!activity.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify activity id: " + activityId); } }
DeleteActivityAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) { Long activityId = (Long) inActionContext.getParams(); ActivityDTO activity = getActivityById(activityId); try { String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); Long currentUserId = inActionContext.getPrincipal().getId(); activityDeletePropertySetter.execute(currentUserAccountId, currentUserId, activity); } catch (Exception ex) { log.error("Error occurred determining access rights for activity delete.", ex); throw new AuthorizationException("Unable to determine access rights."); } if (!activity.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify activity id: " + activityId); } } }
DeleteActivityAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) { Long activityId = (Long) inActionContext.getParams(); ActivityDTO activity = getActivityById(activityId); try { String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); Long currentUserId = inActionContext.getPrincipal().getId(); activityDeletePropertySetter.execute(currentUserAccountId, currentUserId, activity); } catch (Exception ex) { log.error("Error occurred determining access rights for activity delete.", ex); throw new AuthorizationException("Unable to determine access rights."); } if (!activity.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify activity id: " + activityId); } } DeleteActivityAuthorization(final DomainMapper<List<Long>, List<ActivityDTO>>  inActivityByIdDAO,
            final ActivityDeletePropertyStrategy inActivityDeletePropertySetter); }
DeleteActivityAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) { Long activityId = (Long) inActionContext.getParams(); ActivityDTO activity = getActivityById(activityId); try { String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); Long currentUserId = inActionContext.getPrincipal().getId(); activityDeletePropertySetter.execute(currentUserAccountId, currentUserId, activity); } catch (Exception ex) { log.error("Error occurred determining access rights for activity delete.", ex); throw new AuthorizationException("Unable to determine access rights."); } if (!activity.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify activity id: " + activityId); } } DeleteActivityAuthorization(final DomainMapper<List<Long>, List<ActivityDTO>>  inActivityByIdDAO,
            final ActivityDeletePropertyStrategy inActivityDeletePropertySetter); @Override void authorize(final PrincipalActionContext inActionContext); }
DeleteActivityAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) { Long activityId = (Long) inActionContext.getParams(); ActivityDTO activity = getActivityById(activityId); try { String currentUserAccountId = inActionContext.getPrincipal().getAccountId(); Long currentUserId = inActionContext.getPrincipal().getId(); activityDeletePropertySetter.execute(currentUserAccountId, currentUserId, activity); } catch (Exception ex) { log.error("Error occurred determining access rights for activity delete.", ex); throw new AuthorizationException("Unable to determine access rights."); } if (!activity.isDeletable()) { throw new AuthorizationException("Current user does not have permissions to modify activity id: " + activityId); } } DeleteActivityAuthorization(final DomainMapper<List<Long>, List<ActivityDTO>>  inActivityByIdDAO,
            final ActivityDeletePropertyStrategy inActivityDeletePropertySetter); @Override void authorize(final PrincipalActionContext inActionContext);  }