@Test public void testPerformSecurityCheck() { final long tabId = TAB_ID; final Tab tab = context.mock(Tab.class); context.checking(new Expectations() { { oneOf(tabMapper).findTabByGadgetId(GADGET_ID); will(returnValue(tab)); oneOf(tab).getId(); will(returnValue(tabId)); oneOf(principalMock).getAccountId(); will(returnValue("testUser")); oneOf(tabPermission).canModifyGadgets("testUser", tabId, true); will(returnValue(true)); } }); ServiceActionContext currentContext = new ServiceActionContext(GADGET_ID, principalMock); sut.authorize(currentContext); context.assertIsSatisfied(); }
@Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tab.getId(), true)) { throw new AuthorizationException("Failed to authorize deleting of the supplied gadget."); } }
DeleteGadgetAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tab.getId(), true)) { throw new AuthorizationException("Failed to authorize deleting of the supplied gadget."); } } }
DeleteGadgetAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tab.getId(), true)) { throw new AuthorizationException("Failed to authorize deleting of the supplied gadget."); } } DeleteGadgetAuthorization(final TabMapper mapper, final TabPermission inTabPermission); }
DeleteGadgetAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tab.getId(), true)) { throw new AuthorizationException("Failed to authorize deleting of the supplied gadget."); } } DeleteGadgetAuthorization(final TabMapper mapper, final TabPermission inTabPermission); @Override void authorize(final PrincipalActionContext inActionContext); }
DeleteGadgetAuthorization implements AuthorizationStrategy<PrincipalActionContext> { @Override public void authorize(final PrincipalActionContext inActionContext) throws AuthorizationException { Long gadgetId = (Long) inActionContext.getParams(); Tab tab = tabMapper.findTabByGadgetId(gadgetId); if (!tabPermission.canModifyGadgets(inActionContext.getPrincipal().getAccountId(), tab.getId(), true)) { throw new AuthorizationException("Failed to authorize deleting of the supplied gadget."); } } DeleteGadgetAuthorization(final TabMapper mapper, final TabPermission inTabPermission); @Override void authorize(final PrincipalActionContext inActionContext);  }