@Test public void testPerformSecurityCheckHappyPath() { final Long tabId = new Long(1); context.checking(new Expectations() { { allowing(actionContext).getParams(); will(returnValue(addGadgetRequest)); allowing(addGadgetRequest).getTabId(); will(returnValue(tabId)); oneOf(actionContext).getPrincipal(); will(returnValue(principal)); oneOf(principal).getAccountId(); will(returnValue("testUser")); oneOf(tabPermission).canModifyGadgets("testUser", tabId, true); will(returnValue(true)); } }); sut.authorize(actionContext); context.assertIsSatisfied(); }
@Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { AddGadgetRequest request = (AddGadgetRequest) inActionContext.getParams(); Long tabId = request.getTabId(); if (tabId == null) { Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId()); tabId = person.getStartTabGroup().getTabs().get(0).getId(); } if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tabId, true)) { throw new AuthorizationException("Failed to authorize adding of the supplied gadget."); } }
AddGadgetAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { AddGadgetRequest request = (AddGadgetRequest) inActionContext.getParams(); Long tabId = request.getTabId(); if (tabId == null) { Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId()); tabId = person.getStartTabGroup().getTabs().get(0).getId(); } if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tabId, true)) { throw new AuthorizationException("Failed to authorize adding of the supplied gadget."); } } }
AddGadgetAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { AddGadgetRequest request = (AddGadgetRequest) inActionContext.getParams(); Long tabId = request.getTabId(); if (tabId == null) { Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId()); tabId = person.getStartTabGroup().getTabs().get(0).getId(); } if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tabId, true)) { throw new AuthorizationException("Failed to authorize adding of the supplied gadget."); } } AddGadgetAuthorization(final TabMapper inTabMapper, final TabPermission inTabPermission,
            final PersonMapper inPersonMapper); }
AddGadgetAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { AddGadgetRequest request = (AddGadgetRequest) inActionContext.getParams(); Long tabId = request.getTabId(); if (tabId == null) { Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId()); tabId = person.getStartTabGroup().getTabs().get(0).getId(); } if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tabId, true)) { throw new AuthorizationException("Failed to authorize adding of the supplied gadget."); } } AddGadgetAuthorization(final TabMapper inTabMapper, final TabPermission inTabPermission,
            final PersonMapper inPersonMapper); @Override void authorize(final PrincipalActionContext inActionContext); }
AddGadgetAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { AddGadgetRequest request = (AddGadgetRequest) inActionContext.getParams(); Long tabId = request.getTabId(); if (tabId == null) { Person person = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId()); tabId = person.getStartTabGroup().getTabs().get(0).getId(); } if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tabId, true)) { throw new AuthorizationException("Failed to authorize adding of the supplied gadget."); } } AddGadgetAuthorization(final TabMapper inTabMapper, final TabPermission inTabPermission,
            final PersonMapper inPersonMapper); @Override void authorize(final PrincipalActionContext inActionContext);  }