Search in sources :

Example 1 with EnvironmentType

use of alien4cloud.model.application.EnvironmentType in project alien4cloud by alien4cloud.

the class ResourcePermissionService method grantAuthorizedEnvironmentsAndEnvTypesPerApplication.

public void grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd, String[] environmentTypesToAdd) {
    List<String> envIds = Lists.newArrayList();
    IResourceSaver noSave = null;
    if (ArrayUtils.isNotEmpty(applicationsToAdd)) {
        grantPermission(resource, noSave, Subject.APPLICATION, applicationsToAdd);
        // when an app is added, all eventual existing env authorizations are removed
        for (String applicationToAddId : applicationsToAdd) {
            ApplicationEnvironment[] aes = applicationEnvironmentService.getByApplicationId(applicationToAddId);
            for (ApplicationEnvironment ae : aes) {
                envIds.add(ae.getId());
            }
        }
        if (!envIds.isEmpty()) {
            revokePermission(resource, noSave, Subject.ENVIRONMENT, envIds.toArray(new String[envIds.size()]));
        }
        // remove all all eventual existing env type authorizations
        Set<String> envTypes = Sets.newHashSet();
        for (String applicationToAddId : applicationsToAdd) {
            for (EnvironmentType envType : EnvironmentType.values()) {
                envTypes.add(applicationToAddId + ":" + envType.toString());
            }
        }
        if (!envTypes.isEmpty()) {
            revokePermission(resource, noSave, Subject.ENVIRONMENT_TYPE, envTypes.toArray(new String[envTypes.size()]));
        }
    }
    if (ArrayUtils.isNotEmpty(environmentsToAdd)) {
        List<String> envToAddSet = Arrays.stream(environmentsToAdd).filter(env -> !envIds.contains(env)).collect(Collectors.toList());
        grantPermission(resource, noSave, Subject.ENVIRONMENT, envToAddSet.toArray(new String[envToAddSet.size()]));
    }
    if (ArrayUtils.isNotEmpty(environmentTypesToAdd)) {
        grantPermission(resource, noSave, Subject.ENVIRONMENT_TYPE, environmentTypesToAdd);
    }
    alienDAO.save(resource);
}
Also used : BeforePermissionRevokedEvent(org.alien4cloud.alm.events.BeforePermissionRevokedEvent) Lists(org.elasticsearch.common.collect.Lists) Arrays(java.util.Arrays) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) Subject(alien4cloud.security.Subject) AbstractSecurityEnabledResource(alien4cloud.security.AbstractSecurityEnabledResource) ArrayUtils(org.apache.commons.lang3.ArrayUtils) User(alien4cloud.security.model.User) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) MapUtils(org.apache.commons.collections4.MapUtils) Permission(alien4cloud.security.Permission) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Resource(javax.annotation.Resource) Set(java.util.Set) IGenericSearchDAO(alien4cloud.dao.IGenericSearchDAO) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IAlienGroupDao(alien4cloud.security.groups.IAlienGroupDao) IAlienUserDao(alien4cloud.security.users.IAlienUserDao) List(java.util.List) ISecurityEnabledResource(alien4cloud.security.ISecurityEnabledResource) Group(alien4cloud.security.model.Group) EnvironmentType(alien4cloud.model.application.EnvironmentType) AllArgsConstructor(lombok.AllArgsConstructor) Comparator(java.util.Comparator) AfterPermissionRevokedEvent(org.alien4cloud.alm.events.AfterPermissionRevokedEvent) NoArgsConstructor(lombok.NoArgsConstructor) EnvironmentType(alien4cloud.model.application.EnvironmentType) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Aggregations

ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)1 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 EnvironmentType (alien4cloud.model.application.EnvironmentType)1 AbstractSecurityEnabledResource (alien4cloud.security.AbstractSecurityEnabledResource)1 ISecurityEnabledResource (alien4cloud.security.ISecurityEnabledResource)1 Permission (alien4cloud.security.Permission)1 Subject (alien4cloud.security.Subject)1 IAlienGroupDao (alien4cloud.security.groups.IAlienGroupDao)1 Group (alien4cloud.security.model.Group)1 User (alien4cloud.security.model.User)1 IAlienUserDao (alien4cloud.security.users.IAlienUserDao)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1