public boolean canUpdateRepository(Repository repository) { return authorizationManager.authorize(repository, RepositoryAction.UPDATE, user); }
public boolean canReadOrgUnit(OrganizationalUnit organizationalUnit) { return authorizationManager.authorize(organizationalUnit, OrganizationalUnitAction.READ, user); }
public boolean canDeleteOrgUnit(OrganizationalUnit organizationalUnit) { return authorizationManager.authorize(organizationalUnit, OrganizationalUnitAction.DELETE, user); }
@Override public SeekableByteChannel newByteChannel(Path path, OpenOption... options) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { if (!authManager.authorize(toResource(path), getUser())) { throw new SecurityException(); } return service.newByteChannel(path, options); }
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<Path> filter) throws IllegalArgumentException, NotDirectoryException, IOException, SecurityException { if (!authManager.authorize(toResource(dir), getUser())) { throw new SecurityException(); } return service.newDirectoryStream(dir, filter); }
@Override public Path createFile(Path path, FileAttribute<?>... attrs) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { if (!authManager.authorize(toResource(path), getUser())) { throw new SecurityException(); } return service.createFile(path, attrs); }
@Override public Path createDirectories(Path dir, FileAttribute<?>... attrs) throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { if (!authManager.authorize(toResource(dir), getUser())) { throw new SecurityException(); } return service.createDirectories(dir, attrs); }
@Override public void delete(Path path, DeleteOption... options) throws IllegalArgumentException, NoSuchFileException, DirectoryNotEmptyException, IOException, SecurityException { if (!authManager.authorize(toResource(path), getUser())) { throw new SecurityException(); } service.delete(path, options); }
@Override public Path write(Path path, byte[] bytes, OpenOption... options) throws IOException, UnsupportedOperationException, SecurityException { if (!authManager.authorize(toResource(path), getUser())) { throw new SecurityException(); } return service.write(path, bytes); }
private void setOUCreationPermission(final boolean hasPermission) { when(authorizationManager.authorize(eq(OrganizationalUnit.RESOURCE_TYPE), eq(OrganizationalUnitAction.CREATE), any(User.class))).thenReturn(hasPermission); } }
public static boolean authorize(Permission permission) { AuthorizationManagerHelper helper = get(); return helper.getAuthorizationManager().authorize(permission, helper.getUser()); }
@Before public void setup() { when(authManager.authorize(any(Resource.class), eq(identity))).thenReturn(true); final Button button = mock(Button.class); when(button.getElement()).thenReturn(mock(HTMLButtonElement.class)); when(buttons.get()).thenReturn(button); when(kebabMenus.get()).thenReturn(mock(KebabMenu.class)); }
@Test public void shouldNotStartUnauthorizedActivities() throws Exception { when(authzManager.authorize(any(Resource.class), eq(dorothy))).thenReturn(false); activityManager.getActivities(kansas); verify(kansasActivity, never()).onStartup(kansas); }
@Test public void shouldNotSeeUnauthorizedActivities() throws Exception { when(authzManager.authorize(any(Resource.class), eq(dorothy))).thenReturn(false); Set<Activity> activities = activityManager.getActivities(kansas); assertEquals(0, activities.size()); }
@Test public void shouldNotLeakUnauthorizedActivityInstances() throws Exception { when(authzManager.authorize(any(Resource.class), eq(dorothy))).thenReturn(false); activityManager.getActivities(kansas); // this overspecified; all we care is that any activity that was created has also been destroyed. // it would be equally okay if the bean was never instantiated in the first place. verify(activityBeansCache).getActivity("kansas"); verify(iocManager).destroyBean(kansasActivity); }
@Test public void profilePreferencesWasNotAddedWithPermissionWithForceTest() { when(profileService.isForce()).thenReturn(true); doReturn(true).when(authorizationManager).authorize(eq(WorkbenchFeatures.EDIT_PROFILE_PREFERENCES), any()); defaultAdminPageHelper.setup(); verifyProfilePreferenceAdded(false); }
@Test public void testAddCurrentPerspective() { final Menus menus = MenuFactory.newSimpleItem(NAME).perspective(PERSPECTIVE_ID).endMenu().build(); final PlaceRequest placeRequest = new DefaultPlaceRequest(PERSPECTIVE_ID); final PerspectiveActivity perspectiveActivity = mock(PerspectiveActivity.class); when(perspectiveActivity.getPlace()).thenReturn(placeRequest); when(perspectiveManager.getCurrentPerspective()).thenReturn(perspectiveActivity); when(authzManager.authorize(any(Resource.class), eq(identity))).thenReturn(true); presenter.addMenus(menus); verify(view).selectMenuItem(PERSPECTIVE_ID); }
@Test public void testAddCurrentPerspective() { final Menus menus = MenuFactory.newSimpleItem(NAME).perspective(PERSPECTIVE_ID).endMenu().build(); final PlaceRequest placeRequest = new DefaultPlaceRequest(PERSPECTIVE_ID); final PerspectiveActivity perspectiveActivity = mock(PerspectiveActivity.class); when(perspectiveActivity.getPlace()).thenReturn(placeRequest); when(perspectiveManager.getCurrentPerspective()).thenReturn(perspectiveActivity); when(authzManager.authorize(any(Resource.class), eq(identity))).thenReturn(true); presenter.addMenus(menus); verify(presenter).selectMenuItem(PERSPECTIVE_ID); }
@Test public void preferencesShouldBeSavedOnGlobalScopeWhenUserHasPermissionTest() { doReturn(globalScope).when(scopeFactory).createScope(GuvnorPreferenceScopes.GLOBAL); doReturn(true).when(authorizationManager).authorize(eq(WorkbenchFeatures.EDIT_GLOBAL_PREFERENCES), any()); defaultAdminPageHelper.setup(); verifyLibraryPreferencesWasAddedInGlobalScope(); verifyArtifactRepositoryPreferencesWasAddedInGlobalScope(); verifyManagePreferencesWasAddedInGlobalScope(); verifyServiceTasksAdminWasAdded(); }
@Test public void testPerspectiveDeleteAction() { workbenchController.perspective(perspectiveActivity).delete() .granted(onGranted) .denied(onDenied); verify(authorizationManager).authorize(perspectiveActivity, PerspectiveAction.DELETE, user); } }