summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-web-common
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2013-02-21 14:36:05 +0000
committerOlivier Lamy <olamy@apache.org>2013-02-21 14:36:05 +0000
commit659fa128b8f90629e383a55e9bb8e0ab76dcb6da (patch)
tree6dd9c62f024df58ce307eec1455ccf9cef4b7c25 /archiva-modules/archiva-web/archiva-web-common
parenta2c520430f336fb1a2d0ae5eb83b9e0f8e2865a7 (diff)
downloadarchiva-659fa128b8f90629e383a55e9bb8e0ab76dcb6da.tar.gz
archiva-659fa128b8f90629e383a55e9bb8e0ab76dcb6da.zip
really chain of rbac manager
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1448652 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web/archiva-web-common')
-rw-r--r--archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java560
1 files changed, 525 insertions, 35 deletions
diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java
index 84af9c165..f2e21d133 100644
--- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java
+++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java
@@ -35,7 +35,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -105,41 +107,130 @@ public class ArchivaRbacManager
public Role saveRole( Role role )
throws RbacObjectInvalidException, RbacManagerException
{
- return getRbacManagerForWrite().saveRole( role );
+ Exception lastException = null;
+ boolean allFailed = true;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ role = rbacManager.saveRole( role );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return role;
}
public void saveRoles( Collection<Role> roles )
throws RbacObjectInvalidException, RbacManagerException
{
- getRbacManagerForWrite().saveRoles( roles );
+ Exception lastException = null;
+ boolean allFailed = true;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ rbacManager.saveRoles( roles );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
}
public Role getRole( String roleName )
throws RbacObjectNotFoundException, RbacManagerException
{
+ Exception lastException = null;
for ( RBACManager rbacManager : rbacManagersPerId.values() )
{
- Role role = rbacManager.getRole( roleName );
- if ( role != null )
+ try
+ {
+ Role role = rbacManager.getRole( roleName );
+ if ( role != null )
+ {
+ return role;
+ }
+ }
+ catch ( Exception e )
{
- return role;
+ lastException = e;
}
}
log.debug( "cannot find role for name: ‘{}", roleName );
+ if ( lastException != null )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
return null;
}
public List<Role> getAllRoles()
throws RbacManagerException
{
- // iterate and aggregate results ?
- return getRbacManagerForWrite().getAllRoles();
+ Map<String, Role> allRoles = new HashMap<String, Role>();
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ List<Role> roles = rbacManager.getAllRoles();
+ for ( Role role : roles )
+ {
+ allRoles.put( role.getName(), role );
+ }
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+
+ return new ArrayList<Role>( allRoles.values() );
}
public void removeRole( Role role )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
- getRbacManagerForWrite().removeRole( role );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ rbacManager.removeRole( role );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
}
public Permission createPermission( String name )
@@ -157,25 +248,108 @@ public class ArchivaRbacManager
public Permission savePermission( Permission permission )
throws RbacObjectInvalidException, RbacManagerException
{
- return getRbacManagerForWrite().savePermission( permission );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ permission = rbacManager.savePermission( permission );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+
+ return permission;
}
public Permission getPermission( String permissionName )
throws RbacObjectNotFoundException, RbacManagerException
{
- return getRbacManagerForWrite().getPermission( permissionName );
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ Permission p = rbacManager.getPermission( permissionName );
+ if ( p != null )
+ {
+ return p;
+ }
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return null;
}
public List<Permission> getAllPermissions()
throws RbacManagerException
{
- return getRbacManagerForWrite().getAllPermissions();
+ Map<String, Permission> allPermissions = new HashMap<String, Permission>();
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ List<Permission> permissions = rbacManager.getAllPermissions();
+ for ( Permission p : permissions )
+ {
+ allPermissions.put( p.getName(), p );
+ }
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return new ArrayList<Permission>( allPermissions.values() );
}
public void removePermission( Permission permission )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
- getRbacManagerForWrite().removePermission( permission );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ rbacManager.removePermission( permission );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
}
public Operation createOperation( String name )
@@ -187,25 +361,107 @@ public class ArchivaRbacManager
public Operation saveOperation( Operation operation )
throws RbacObjectInvalidException, RbacManagerException
{
- return getRbacManagerForWrite().saveOperation( operation );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ operation = rbacManager.saveOperation( operation );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return operation;
}
public Operation getOperation( String operationName )
throws RbacObjectNotFoundException, RbacManagerException
{
- return getRbacManagerForWrite().getOperation( operationName );
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ Operation o = rbacManager.getOperation( operationName );
+ if ( o != null )
+ {
+ return o;
+ }
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return null;
}
public List<Operation> getAllOperations()
throws RbacManagerException
{
- return getRbacManagerForWrite().getAllOperations();
+ Map<String, Operation> allOperations = new HashMap<String, Operation>();
+ 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<Operation>( allOperations.values() );
}
public void removeOperation( Operation operation )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
- getRbacManagerForWrite().removeOperation( operation );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ rbacManager.removeOperation( operation );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
}
public Resource createResource( String identifier )
@@ -217,25 +473,109 @@ public class ArchivaRbacManager
public Resource saveResource( Resource resource )
throws RbacObjectInvalidException, RbacManagerException
{
- return getRbacManagerForWrite().saveResource( resource );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ resource = rbacManager.saveResource( resource );
+
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return resource;
}
public Resource getResource( String resourceIdentifier )
throws RbacObjectNotFoundException, RbacManagerException
{
- return getRbacManagerForWrite().getResource( resourceIdentifier );
+
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ Resource r = rbacManager.getResource( resourceIdentifier );
+ if ( r != null )
+ {
+ return r;
+ }
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return null;
}
public List<Resource> getAllResources()
throws RbacManagerException
{
- return getRbacManagerForWrite().getAllResources();
+ Map<String, Resource> allResources = new HashMap<String, Resource>();
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ List<Resource> resources = rbacManager.getAllResources();
+ for ( Resource r : resources )
+ {
+ allResources.put( r.getIdentifier(), r );
+ }
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return new ArrayList<Resource>( allResources.values() );
}
public void removeResource( Resource resource )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
- getRbacManagerForWrite().removeResource( resource );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ rbacManager.removeResource( resource );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
}
public UserAssignment createUserAssignment( String principal )
@@ -247,61 +587,211 @@ public class ArchivaRbacManager
public UserAssignment saveUserAssignment( UserAssignment userAssignment )
throws RbacObjectInvalidException, RbacManagerException
{
- return getRbacManagerForWrite().saveUserAssignment( userAssignment );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ userAssignment = rbacManager.saveUserAssignment( userAssignment );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return userAssignment;
}
public UserAssignment getUserAssignment( String principal )
throws RbacObjectNotFoundException, RbacManagerException
{
- return getRbacManagerForWrite().getUserAssignment( principal );
+
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ UserAssignment ua = rbacManager.getUserAssignment( principal );
+ if ( ua != null )
+ {
+ return ua;
+ }
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return null;
}
@Override
public boolean userAssignmentExists( String principal )
{
- return getRbacManagerForWrite().userAssignmentExists( principal );
+
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ boolean exists = rbacManager.userAssignmentExists( principal );
+ if ( exists )
+ {
+ return true;
+ }
+ }
+ catch ( Exception e )
+ {
+ // no op
+ }
+ }
+
+ return false;
}
@Override
public boolean userAssignmentExists( UserAssignment assignment )
{
- return getRbacManagerForWrite().userAssignmentExists( assignment );
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ boolean exists = rbacManager.userAssignmentExists( assignment );
+ if ( exists )
+ {
+ return true;
+ }
+ }
+ catch ( Exception e )
+ {
+ // no op
+ }
+ }
+
+ return false;
}
public List<UserAssignment> getAllUserAssignments()
throws RbacManagerException
{
- // iterate
- return getRbacManagerForWrite().getAllUserAssignments();
+ Map<String, UserAssignment> allUserAssignments = new HashMap<String, UserAssignment>();
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ List<UserAssignment> userAssignments = rbacManager.getAllUserAssignments();
+ for ( UserAssignment ua : userAssignments )
+ {
+ allUserAssignments.put( ua.getPrincipal(), ua );
+ }
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return new ArrayList<UserAssignment>( allUserAssignments.values() );
}
public List<UserAssignment> getUserAssignmentsForRoles( Collection<String> roleNames )
throws RbacManagerException
{
- // iterate ?
- return getRbacManagerForWrite().getUserAssignmentsForRoles( roleNames );
+ List<UserAssignment> allUserAssignments = new ArrayList<UserAssignment>();
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ List<UserAssignment> userAssignments = rbacManager.getUserAssignmentsForRoles( roleNames );
+
+ allUserAssignments.addAll( userAssignments );
+
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return allUserAssignments;
}
public void removeUserAssignment( UserAssignment userAssignment )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
- getRbacManagerForWrite().removeUserAssignment( userAssignment );
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
+ {
+ try
+ {
+ rbacManager.removeUserAssignment( userAssignment );
+ allFailed = false;
+ }
+ catch ( Exception e )
+ {
+ lastException = e;
+ }
+ }
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
}
@Override
public boolean roleExists( String name )
throws RbacManagerException
{
- boolean exists = false;
- for ( RBACManager manager : rbacManagersPerId.values() )
+ boolean allFailed = true;
+ Exception lastException = null;
+ for ( RBACManager rbacManager : rbacManagersPerId.values() )
{
- exists = manager.roleExists( name );
- if ( exists )
+ try
+ {
+ boolean exists = rbacManager.roleExists( name );
+ if ( exists )
+ {
+ return true;
+ }
+ }
+ catch ( Exception e )
{
- return true;
+ lastException = e;
}
}
- return exists;
+
+ if ( lastException != null && allFailed )
+ {
+ throw new RbacManagerException( lastException.getMessage(), lastException );
+ }
+ return false;
}
@Override