@Test(expected = AuthorizationException.class) public void testPerformSecurityCheckWithTabNull() { final Long tabId = null; final List<Tab> tabs = new ArrayList<Tab>(); tabs.add(tab); context.checking(new Expectations() { { allowing(actionContext).getParams(); will(returnValue(addGadgetRequest)); allowing(addGadgetRequest).getTabId(); will(returnValue(tabId)); oneOf(personMapper).findByAccountId("testUser"); will(returnValue(person)); allowing(actionContext).getPrincipal(); will(returnValue(principal)); allowing(principal).getAccountId(); will(returnValue("testUser")); oneOf(person).getStartTabGroup(); will(returnValue(tabGroup)); oneOf(tabGroup).getTabs(); will(returnValue(tabs)); oneOf(tab).getId(); will(returnValue(1L)); oneOf(tabPermission).canModifyGadgets("testUser", 1L, true); will(returnValue(false)); } }); 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);  }