private String runAsUser( Callable<String> callable ) { try { if ( callable != null ) { return SecurityHelper.getInstance().runAsUser( this.actionUser, callable ); } } catch ( Exception e ) { logger.error( e.getMessage(), e ); } return null; }
@SuppressWarnings( "deprecation" ) public void testVoter() throws Exception { SecurityHelper.getInstance().runAsUser( "suzy", new Callable<Void>() { @Override public Void call() throws Exception { RepositoryFile testFile = new RepositoryFile( "Test Folder", null, null ); //$NON-NLS-1$ // RepositoryFile has no acls on it. Nobody should be able to access it. // But, we're using an allowAll voter. PentahoAllowAllAclVoter voter = new PentahoAllowAllAclVoter(); assertTrue( voter.hasAccess( PentahoSessionHolder.getSession(), testFile, IPentahoAclEntry.PERM_EXECUTE ) ); IPentahoAclEntry entry = voter.getEffectiveAcl( PentahoSessionHolder.getSession(), testFile ); assertEquals( ( (PentahoAclEntry) entry ).getMask(), IPentahoAclEntry.PERM_FULL_CONTROL ); assertTrue( voter.isPentahoAdministrator( PentahoSessionHolder.getSession() ) ); assertTrue( voter.isGranted( PentahoSessionHolder.getSession(), new SimpleGrantedAuthority( "ROLE_ANYTHING" ) ) ); //$NON-NLS-1$ return null; } } ); } }
public void testVoter() throws Exception { SecurityHelper.getInstance().runAsUser( "suzy", new Callable<Void>() { @Override public Void call() throws Exception { RepositoryFile testFile = new RepositoryFile( "Test Folder", null, null ); //$NON-NLS-1$ Map<IPermissionRecipient, IPermissionMask> perms = new LinkedHashMap<IPermissionRecipient, IPermissionMask>(); perms.put( new SimpleUser( "suzy" ), new SimplePermissionMask( IPentahoAclEntry.PERM_NOTHING ) ); perms.put( new SimpleRole( "ROLE_POWER_USER" ), new SimplePermissionMask( IPentahoAclEntry.PERM_FULL_CONTROL ) ); SpringSecurityPermissionMgr.instance().getPermissions( testFile ); // Now, the stage is set. We should be able to double-check that suzy // has no access to the testFile. PentahoUserOverridesVoter voter = new PentahoUserOverridesVoter(); assertNotNull( voter ); assertFalse( voter.hasAccess( PentahoSessionHolder.getSession(), testFile, IPentahoAclEntry.PERM_EXECUTE ) ); return null; } } ); } }
@SuppressWarnings( "deprecation" ) public void testVoter() throws Exception { SecurityHelper.getInstance().runAsUser( "suzy", new Callable<Void>() { @Override public Void call() throws Exception { RepositoryFile testFile = new RepositoryFile( "Test Folder", null, null ); //$NON-NLS-1$ Map<IPermissionRecipient, IPermissionMask> perms = new LinkedHashMap<IPermissionRecipient, IPermissionMask>(); perms.put( new SimpleUser( "suzy" ), new SimplePermissionMask( IPentahoAclEntry.PERM_EXECUTE ) ); perms.put( new SimpleRole( "ROLE_POWER_USER" ), new SimplePermissionMask( IPentahoAclEntry.PERM_SUBSCRIBE ) ); SpringSecurityPermissionMgr.instance().setPermissions( perms, testFile ); PentahoBasicAclVoter voter = new PentahoBasicAclVoterForTesting( new MockAuthentication( "suzy", Arrays.asList( new GrantedAuthority[] { new SimpleGrantedAuthority( "ROLE_AUTHENTICATED" ), new SimpleGrantedAuthority( "ROLE_POWER_USER" ) } ) ) ); assertTrue( voter.hasAccess( PentahoSessionHolder.getSession(), testFile, IPentahoAclEntry.PERM_EXECUTE ) ); assertTrue( voter.hasAccess( PentahoSessionHolder.getSession(), testFile, IPentahoAclEntry.PERM_SUBSCRIBE ) ); assertFalse( voter.hasAccess( PentahoSessionHolder.getSession(), testFile, IPentahoAclEntry.PERM_ADMINISTRATION ) ); PentahoAclEntry entry = voter.getEffectiveAcl( PentahoSessionHolder.getSession(), testFile ); assertNotNull( entry ); assertEquals( entry.printPermissionsBlock(), "XS----" ); //$NON-NLS-1$ return null; } } ); }
getSecurityHelper().runAsUser( principalName, new Callable<Void>() { @Override public Void call() throws Exception {
@Override public Void call() throws Exception { try { SecurityHelper.getInstance().runAsUser( "suzy", new Callable<Void>() { @Override public Void call() throws Exception { assertEquals( ( (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal() ).getUsername(), "suzy" ); throw new NullPointerException(); } } ); } catch ( Exception e ) { /* No-op */ } assertEquals( ( (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal() ).getUsername(), "admin" ); return null; } } );
ISecurityHelper mockSecurityHelper = Mockito.mock( ISecurityHelper.class ); SecurityHelper.setMockInstance( mockSecurityHelper ); when( mockSecurityHelper.runAsUser( Mockito.anyString(), Mockito.any() ) ).thenReturn( mockOutputPath ); PowerMockito.mockStatic( PentahoSystem.class ); IUnifiedRepository mockRepository = Mockito.mock( IUnifiedRepository.class );
ISecurityHelper mockSecurityHelper = Mockito.mock( ISecurityHelper.class ); SecurityHelper.setMockInstance( mockSecurityHelper ); when( mockSecurityHelper.runAsUser( Mockito.anyString(), Mockito.any() ) ).thenReturn( mockOutputPath ); PowerMockito.mockStatic( PentahoSystem.class ); IUnifiedRepository mockRepository = Mockito.mock( IUnifiedRepository.class );
final Class<IAction> iaction = (Class<IAction>) actionBean.getClass(); SecurityHelper.getInstance().runAsUser( actionUser, new Callable<Void>() { @Override public Void call() throws Exception { SecurityHelper.getInstance().runAsUser( actionUser, new Callable<Void>() { @Override public Void call() throws Exception {
requiresUpdate = SecurityHelper.getInstance().runAsUser( actionUser, actionBeanRunner );