Search in sources :

Example 11 with RbacManagerException

use of org.apache.archiva.redback.rbac.RbacManagerException 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)

Example 12 with RbacManagerException

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

the class ArchivaRbacManager method removeResource.

@Override
public void removeResource(Resource resource) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException {
    boolean allFailed = true;
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            rbacManager.removeResource(resource);
            resourcesCache.remove(resource.getIdentifier());
            allFailed = false;
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (lastException != null && allFailed) {
        throw new RbacManagerException(lastException.getMessage(), lastException);
    }
}
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)

Example 13 with RbacManagerException

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

the class ArchivaRbacManager method getOperation.

@Override
public Operation getOperation(String operationName) throws RbacObjectNotFoundException, RbacManagerException {
    Operation el = operationsCache.get(operationName);
    if (el != null) {
        return el;
    }
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            Operation o = rbacManager.getOperation(operationName);
            if (o != null) {
                operationsCache.put(operationName, o);
                return o;
            }
        } 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) AbstractRBACManager(org.apache.archiva.redback.rbac.AbstractRBACManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) Operation(org.apache.archiva.redback.rbac.Operation) 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 14 with RbacManagerException

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

the class ArchivaRbacManager method getUserAssignment.

@Override
public UserAssignment getUserAssignment(String principal) throws RbacObjectNotFoundException, RbacManagerException {
    UserAssignment el = userAssignmentsCache.get(principal);
    if (el != null) {
        return el;
    }
    UserAssignment ua = null;
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            if (ua == null) {
                ua = rbacManager.getUserAssignment(principal);
            } else {
                UserAssignment userAssignment = rbacManager.getUserAssignment(principal);
                if (userAssignment != null) {
                    for (String roleName : userAssignment.getRoleNames()) {
                        ua.addRoleName(roleName);
                    }
                }
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (ua != null) {
        userAssignmentsCache.put(principal, ua);
        return ua;
    }
    if (lastException != null) {
        throw new RbacManagerException(lastException.getMessage(), lastException);
    }
    return null;
}
Also used : UserAssignment(org.apache.archiva.redback.rbac.UserAssignment) 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 15 with RbacManagerException

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

the class SecuritySynchronization method assignRepositoryObserverToGuestUser.

private void assignRepositoryObserverToGuestUser(List<ManagedRepositoryConfiguration> repos) {
    for (ManagedRepositoryConfiguration repoConfig : repos) {
        String repoId = repoConfig.getId();
        String principal = UserManager.GUEST_USERNAME;
        try {
            UserAssignment ua;
            if (rbacManager.userAssignmentExists(principal)) {
                ua = rbacManager.getUserAssignment(principal);
            } else {
                ua = rbacManager.createUserAssignment(principal);
            }
            ua.addRoleName(ArchivaRoleConstants.toRepositoryObserverRoleName(repoId));
            rbacManager.saveUserAssignment(ua);
        } catch (RbacManagerException e) {
            log.warn("Unable to add role [{}] to {} user.", ArchivaRoleConstants.toRepositoryObserverRoleName(repoId), principal, e);
        }
    }
}
Also used : UserAssignment(org.apache.archiva.redback.rbac.UserAssignment) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration)

Aggregations

RbacManagerException (org.apache.archiva.redback.rbac.RbacManagerException)25 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)23 AbstractRBACManager (org.apache.archiva.redback.rbac.AbstractRBACManager)23 RBACManager (org.apache.archiva.redback.rbac.RBACManager)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 UserAssignment (org.apache.archiva.redback.rbac.UserAssignment)5 Role (org.apache.archiva.redback.rbac.Role)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 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)1 User (org.apache.archiva.redback.users.User)1 UserManager (org.apache.archiva.redback.users.UserManager)1 UserManagerException (org.apache.archiva.redback.users.UserManagerException)1 UserNotFoundException (org.apache.archiva.redback.users.UserNotFoundException)1