private void invalidateCachedOperation( Operation operation ) { if ( operation != null ) { operationsCache.remove( operation.getName() ); } }
public void removeOperation( Operation operation ) throws RbacObjectNotFoundException, RbacManagerException { RBACObjectAssertions.assertValid( "Remove Operation", operation ); if ( operation.isPermanent() ) { throw new RbacPermanentException( "Unable to delete permanent operation [" + operation.getName() + "]" ); } assertOpertionExists( operation.getName() ); operations.remove( operation.getName() ); }
public boolean operationExists( String name ) { try { for ( Operation operation : getAllOperations() ) { if ( StringUtils.equals( operation.getName(), name ) ) { return true; } } } catch ( RbacManagerException e ) { return false; } return false; }
private Map<String, List<Permission>> getPermissionMapByOperation( Collection<Permission> permissions ) { Map<String, List<Permission>> userPermMap = new HashMap<String, List<Permission>>(); for ( Permission permission : permissions ) { List<Permission> permList = userPermMap.get( permission.getOperation().getName() ); if ( permList != null ) { permList.add( permission ); } else { List<Permission> newPermList = new ArrayList<Permission>( permissions.size() ); newPermList.add( permission ); userPermMap.put( permission.getOperation().getName(), newPermList ); } } return userPermMap; }
public static void assertValid( String scope, Operation operation ) throws RbacObjectInvalidException { if ( operation == null ) { throw new RbacObjectInvalidException( scope, "Null Operation object is invalid." ); } if ( StringUtils.isEmpty( operation.getName() ) ) { throw new RbacObjectInvalidException( scope, "Operation.name must not be empty." ); } }
public Operation saveOperation( Operation operation ) throws RbacManagerException { triggerInit(); RBACObjectAssertions.assertValid( "Save Operation", operation ); operations.put( operation.getName(), operation ); return operation; }
public boolean operationExists( Operation operation ) { if ( operation == null ) { return false; } if ( operationsCache.hasKey( operation.getName() ) ) { return true; } return this.rbacImpl.operationExists( operation ); }
@Override public List<Operation> getAllOperations() throws RbacManagerException { Map<String, Operation> allOperations = new HashMap<>(); boolean allFailed = true; Exception lastException = null; for ( RBACManager rbacManager : rbacManagersPerId.values() ) { try { List<Operation> operations = rbacManager.getAllOperations(); for ( Operation o : operations ) { allOperations.put( o.getName(), o ); } allFailed = false; } catch ( Exception e ) { lastException = e; } } if ( lastException != null && allFailed ) { throw new RbacManagerException( lastException.getMessage(), lastException ); } return new ArrayList<>( allOperations.values() ); }
public Operation( org.apache.archiva.redback.rbac.Operation operation ) { this.name = operation.getName(); this.description = operation.getDescription(); this.permanent = operation.isPermanent(); }
@Override public List<Operation> getAllOperations() throws RbacManagerException { Map<String, Operation> allOperations = new HashMap<>(); boolean allFailed = true; Exception lastException = null; for ( RBACManager rbacManager : rbacManagersPerId.values() ) { try { List<? extends Operation> operations = rbacManager.getAllOperations(); for ( Operation o : operations ) { allOperations.put( o.getName(), o ); } allFailed = false; } catch ( Exception e ) { lastException = e; } } if ( lastException != null && allFailed ) { throw new RbacManagerException( lastException.getMessage(), lastException ); } return new ArrayList<>( allOperations.values() ); }
@Override public void removeOperation( Operation operation ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { boolean allFailed = true; Exception lastException = null; for ( RBACManager rbacManager : rbacManagersPerId.values() ) { try { rbacManager.removeOperation( operation ); operationsCache.remove( operation.getName() ); allFailed = false; } catch ( Exception e ) { lastException = e; } } if ( lastException != null && allFailed ) { throw new RbacManagerException( lastException.getMessage(), lastException ); } }
@Override public void removeOperation( Operation operation ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { boolean allFailed = true; Exception lastException = null; for ( RBACManager rbacManager : rbacManagersPerId.values() ) { try { rbacManager.removeOperation( operation ); operationsCache.remove( operation.getName() ); allFailed = false; } catch ( Exception e ) { lastException = e; } } if ( lastException != null && allFailed ) { throw new RbacManagerException( lastException.getMessage(), lastException ); } }
@Test public void testPerformanceOperations() throws RbacManagerException { rbacDefaults.createDefaults(); String operIdEditRepo = "edit-repository"; String operIdDelRepo = "delete-repository"; long startTime = System.currentTimeMillis(); for ( int i = 0; i <= ITERATIONS; i++ ) { Operation operEditRepo = rbacManager.getOperation( operIdEditRepo ); Operation operDelRepo = rbacManager.getOperation( operIdDelRepo ); assertNotNull( operEditRepo ); assertNotNull( operDelRepo ); assertEquals( operIdEditRepo, operEditRepo.getName() ); assertEquals( operIdDelRepo, operDelRepo.getName() ); } long endTime = System.currentTimeMillis(); assertPerformance( "Operations", startTime, endTime, ITERATIONS, 500 ); } }
public Permission createPermission( String name, String operationName, String resourceIdentifier ) throws RbacManagerException { Permission permission; try { permission = getPermission( name ); if ( StringUtils.equals( operationName, permission.getOperation().getName() ) ) { throw new RbacManagerException( "Attempted to create a permission named '" + name + "' with an operation named '" + operationName + "', but that overides the existing '" + name + "' permission with operation '" + permission.getOperation().getName() + "'" ); } } catch ( RbacObjectNotFoundException e ) { permission = new MemoryPermission(); permission.setName( name ); permission.setOperation( createOperation( operationName ) ); permission.setResource( createResource( resourceIdentifier ) ); } return permission; }
operation.setName( p.getOperation().getName() ); permission.setOperation( operation );