Search in sources :

Example 21 with RBACManager

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

the class ArchivaRbacManager method saveOperation.

@Override
public Operation saveOperation(Operation operation) throws RbacObjectInvalidException, RbacManagerException {
    boolean allFailed = true;
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            if (!rbacManager.isReadOnly()) {
                operation = rbacManager.saveOperation(operation);
                allFailed = false;
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (lastException != null && allFailed) {
        throw new RbacManagerException(lastException.getMessage(), lastException);
    }
    return operation;
}
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 22 with RBACManager

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

the class ArchivaRbacManager method initialize.

@Override
public void initialize() {
    try {
        List<String> rbacManagerIds = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getRbacManagerImpls();
        clearCaches();
        if (rbacManagerIds.isEmpty()) {
            rbacManagerIds.add(RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL);
        }
        log.info("use rbacManagerIds: '{}'", rbacManagerIds);
        this.rbacManagersPerId = new LinkedHashMap<>(rbacManagerIds.size());
        for (String id : rbacManagerIds) {
            if (StringUtils.equalsIgnoreCase("jdo", id)) {
                id = RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL;
            }
            RBACManager rbacManager = applicationContext.getBean("rbacManager#" + id, RBACManager.class);
            rbacManagersPerId.put(id, rbacManager);
        }
    } catch (RepositoryAdminException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : AbstractRBACManager(org.apache.archiva.redback.rbac.AbstractRBACManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 23 with RBACManager

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

the class ArchivaRbacManager method getAllPermissions.

@Override
public List<Permission> getAllPermissions() throws RbacManagerException {
    Map<String, Permission> allPermissions = new HashMap<>();
    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<>(allPermissions.values());
}
Also used : RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Permission(org.apache.archiva.redback.rbac.Permission) 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 24 with RBACManager

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

the class ArchivaRbacManager method getPermission.

@Override
public Permission getPermission(String permissionName) throws RbacObjectNotFoundException, RbacManagerException {
    Permission el = permissionsCache.get(permissionName);
    if (el != null) {
        return el;
    }
    Exception lastException = null;
    for (RBACManager rbacManager : rbacManagersPerId.values()) {
        try {
            Permission p = rbacManager.getPermission(permissionName);
            if (p != null) {
                permissionsCache.put(permissionName, p);
                return p;
            }
        } 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) Permission(org.apache.archiva.redback.rbac.Permission) 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 25 with RBACManager

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

the class DefaultRedbackRuntimeConfigurationService method getRbacManagerImplementationInformations.

@Override
public List<RBACManagerImplementationInformation> getRbacManagerImplementationInformations() throws ArchivaRestServiceException {
    Map<String, RBACManager> beans = applicationContext.getBeansOfType(RBACManager.class);
    if (beans.isEmpty()) {
        return Collections.emptyList();
    }
    List<RBACManagerImplementationInformation> informations = new ArrayList<>(beans.size());
    for (Map.Entry<String, RBACManager> entry : beans.entrySet()) {
        RBACManager rbacManager = applicationContext.getBean(entry.getKey(), RBACManager.class);
        if (rbacManager.isFinalImplementation()) {
            RBACManagerImplementationInformation information = new RBACManagerImplementationInformation();
            information.setBeanId(StringUtils.substringAfter(entry.getKey(), "#"));
            information.setDescriptionKey(rbacManager.getDescriptionKey());
            information.setReadOnly(rbacManager.isReadOnly());
            informations.add(information);
        }
    }
    return informations;
}
Also used : ArrayList(java.util.ArrayList) RBACManager(org.apache.archiva.redback.rbac.RBACManager) Map(java.util.Map) RBACManagerImplementationInformation(org.apache.archiva.rest.api.model.RBACManagerImplementationInformation)

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