Search in sources :

Example 6 with RBACManager

use of org.apache.archiva.redback.rbac.RBACManager in project archiva by apache.

the class ArchivaRbacManager method getAllUserAssignments.

@Override
public List<UserAssignment> getAllUserAssignments() throws RbacManagerException {
    Map<String, UserAssignment> allUserAssignments = new HashMap<>();
    boolean allFailed = true;
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            List<UserAssignment> userAssignments = rbacManager.getAllUserAssignments();
            for (UserAssignment ua : userAssignments) {
                UserAssignment userAssignment = allUserAssignments.get(ua.getPrincipal());
                if (userAssignment != null) {
                    for (String roleName : ua.getRoleNames()) {
                        userAssignment.addRoleName(roleName);
                    }
                }
                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<>(allUserAssignments.values());
}
Also used : UserAssignment(org.apache.archiva.redback.rbac.UserAssignment) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) AbstractRBACManager(org.apache.archiva.redback.rbac.AbstractRBACManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) RbacObjectNotFoundException(org.apache.archiva.redback.rbac.RbacObjectNotFoundException) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RbacObjectInvalidException(org.apache.archiva.redback.rbac.RbacObjectInvalidException)

Example 7 with RBACManager

use of org.apache.archiva.redback.rbac.RBACManager in project archiva by apache.

the class ArchivaRbacManager method getAllRoles.

@Override
public List<Role> getAllRoles() throws RbacManagerException {
    Map<String, Role> allRoles = new HashMap<>();
    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<>(allRoles.values());
}
Also used : Role(org.apache.archiva.redback.rbac.Role) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) AbstractRBACManager(org.apache.archiva.redback.rbac.AbstractRBACManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) RbacObjectNotFoundException(org.apache.archiva.redback.rbac.RbacObjectNotFoundException) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RbacObjectInvalidException(org.apache.archiva.redback.rbac.RbacObjectInvalidException)

Example 8 with RBACManager

use of org.apache.archiva.redback.rbac.RBACManager in project archiva by apache.

the class ArchivaRbacManager method roleExists.

@Override
public boolean roleExists(String name) throws RbacManagerException {
    Role r = rolesCache.get(name);
    if (r != null) {
        return true;
    }
    boolean allFailed = true;
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            boolean exists = rbacManager.roleExists(name);
            if (exists) {
                return true;
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (lastException != null && allFailed) {
        throw new RbacManagerException(lastException.getMessage(), lastException);
    }
    return false;
}
Also used : Role(org.apache.archiva.redback.rbac.Role) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) AbstractRBACManager(org.apache.archiva.redback.rbac.AbstractRBACManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) RbacObjectNotFoundException(org.apache.archiva.redback.rbac.RbacObjectNotFoundException) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RbacObjectInvalidException(org.apache.archiva.redback.rbac.RbacObjectInvalidException)

Example 9 with RBACManager

use of org.apache.archiva.redback.rbac.RBACManager in project archiva by apache.

the class ArchivaRbacManager method getResource.

@Override
public Resource getResource(String resourceIdentifier) throws RbacObjectNotFoundException, RbacManagerException {
    Resource el = resourcesCache.get(resourceIdentifier);
    if (el != null) {
        return el;
    }
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            Resource r = rbacManager.getResource(resourceIdentifier);
            if (r != null) {
                resourcesCache.put(resourceIdentifier, r);
                return r;
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (lastException != null) {
        throw new RbacManagerException(lastException.getMessage(), lastException);
    }
    return null;
}
Also used : RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) Resource(org.apache.archiva.redback.rbac.Resource) AbstractRBACManager(org.apache.archiva.redback.rbac.AbstractRBACManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) RbacObjectNotFoundException(org.apache.archiva.redback.rbac.RbacObjectNotFoundException) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RbacObjectInvalidException(org.apache.archiva.redback.rbac.RbacObjectInvalidException)

Example 10 with RBACManager

use of org.apache.archiva.redback.rbac.RBACManager in project archiva by apache.

the class ArchivaRbacManager method saveResource.

@Override
public Resource saveResource(Resource resource) throws RbacObjectInvalidException, RbacManagerException {
    boolean allFailed = true;
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            if (!rbacManager.isReadOnly()) {
                resource = rbacManager.saveResource(resource);
                allFailed = false;
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (lastException != null && allFailed) {
        throw new RbacManagerException(lastException.getMessage(), lastException);
    }
    return resource;
}
Also used : RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) AbstractRBACManager(org.apache.archiva.redback.rbac.AbstractRBACManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) RbacObjectNotFoundException(org.apache.archiva.redback.rbac.RbacObjectNotFoundException) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RbacObjectInvalidException(org.apache.archiva.redback.rbac.RbacObjectInvalidException)

Aggregations

RBACManager (org.apache.archiva.redback.rbac.RBACManager)25 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)24 AbstractRBACManager (org.apache.archiva.redback.rbac.AbstractRBACManager)24 RbacManagerException (org.apache.archiva.redback.rbac.RbacManagerException)23 RbacObjectInvalidException (org.apache.archiva.redback.rbac.RbacObjectInvalidException)23 RbacObjectNotFoundException (org.apache.archiva.redback.rbac.RbacObjectNotFoundException)23 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Role (org.apache.archiva.redback.rbac.Role)3 UserAssignment (org.apache.archiva.redback.rbac.UserAssignment)3 Operation (org.apache.archiva.redback.rbac.Operation)2 Permission (org.apache.archiva.redback.rbac.Permission)2 Resource (org.apache.archiva.redback.rbac.Resource)2 Map (java.util.Map)1 RBACManagerImplementationInformation (org.apache.archiva.rest.api.model.RBACManagerImplementationInformation)1