Search in sources :

Example 1 with ApplicationEnvironment

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

the class VariableExpressionService method getInEnvironmentScope.

public List<ScopeVariableExpressionDTO> getInEnvironmentScope(String varName, String applicationId, String topologyVersion, String envId) {
    Application application = applicationService.getOrFail(applicationId);
    if (StringUtils.isBlank(envId)) {
        return Arrays.stream(applicationEnvironmentService.getAuthorizedByApplicationId(applicationId)).map(env -> getVariableDef(varName, Csar.createId(env.getApplicationId(), topologyVersion), env)).collect(Collectors.toList());
    } else {
        ApplicationEnvironment env = applicationEnvironmentService.getOrFail(envId);
        AuthorizationUtil.checkAuthorizationForEnvironment(application, env);
        return Lists.newArrayList(getVariableDef(varName, Csar.createId(env.getApplicationId(), topologyVersion), env));
    }
}
Also used : Arrays(java.util.Arrays) Setter(lombok.Setter) Getter(lombok.Getter) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) EditorFileService(org.alien4cloud.tosca.editor.EditorFileService) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationService(alien4cloud.application.ApplicationService) YamlParserUtil(alien4cloud.utils.YamlParserUtil) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Collection(java.util.Collection) ScopeVariableExpressionDTO(org.alien4cloud.tosca.variable.ScopeVariableExpressionDTO) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) AuthorizationUtil(alien4cloud.security.AuthorizationUtil) List(java.util.List) EnvironmentType(alien4cloud.model.application.EnvironmentType) Variable(org.alien4cloud.tosca.variable.model.Variable) QuickFileStorageService(org.alien4cloud.tosca.variable.QuickFileStorageService) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 2 with ApplicationEnvironment

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

the class ResourcePermissionServiceTest method when_permission_added_at_application_level_remove_any_permissions_hidden_at_lower_level.

@Test
public void when_permission_added_at_application_level_remove_any_permissions_hidden_at_lower_level() {
    // Given
    resourceSecured = new AbstractSecurityEnabledResource() {

        @Override
        public String getId() {
            return "id";
        }
    };
    HashSet<Permission> permissions = new HashSet<>();
    permissions.add(Permission.ADMIN);
    resourceSecured.addPermissions(Subject.APPLICATION, "subject1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT, "subject1_1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT, "subject1_2", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT_TYPE, "subject1:INTEGRATION_TESTS", new HashSet<>(permissions));
    ApplicationEnvironment ae1 = new ApplicationEnvironment();
    ae1.setId("subject1_1");
    ae1.setEnvironmentType(EnvironmentType.INTEGRATION_TESTS);
    ApplicationEnvironment ae2 = new ApplicationEnvironment();
    ae2.setId("subject1_2");
    ae2.setEnvironmentType(EnvironmentType.INTEGRATION_TESTS);
    Mockito.when(applicationEnvironmentService.getByApplicationId("subject1")).thenReturn(new ApplicationEnvironment[] { ae1, ae2 });
    // When
    service.grantAuthorizedEnvironmentsAndEnvTypesPerApplication((AbstractSecurityEnabledResource) resourceSecured, new String[] { "subject1" }, new String[] { "subject1_1", "subject1_2" }, new String[] { "subject_env_1_1" });
    // Then
    verify(alienDAO).save(resourceSecuredCaptor.capture());
    assertThat(resourceSecuredCaptor.getValue().getPermissions(Subject.APPLICATION, "subject1")).containsExactly(Permission.ADMIN);
    assertThat(resourceSecuredCaptor.getValue().getPermissions(Subject.ENVIRONMENT, "subject1_1")).isEmpty();
    assertThat(resourceSecuredCaptor.getValue().getPermissions(Subject.ENVIRONMENT, "subject1_2")).isEmpty();
    assertThat(resourceSecuredCaptor.getValue().getPermissions(Subject.ENVIRONMENT_TYPE, "subject1:INTEGRATION_TESTS")).isEmpty();
}
Also used : Permission(alien4cloud.security.Permission) AbstractSecurityEnabledResource(alien4cloud.security.AbstractSecurityEnabledResource) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ApplicationEnvironment

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

the class ResourcePermissionServiceTest method when_permission_added_at_application_level_unrelated_environment_and_env_type_are_unmodified.

@Test
public void when_permission_added_at_application_level_unrelated_environment_and_env_type_are_unmodified() {
    // Given
    resourceSecured = new AbstractSecurityEnabledResource() {

        @Override
        public String getId() {
            return "id";
        }
    };
    HashSet<Permission> permissions = new HashSet<>();
    permissions.add(Permission.ADMIN);
    resourceSecured.addPermissions(Subject.APPLICATION, "subject1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT, "subject1_1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT, "subject2_1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT_TYPE, "subject1:INTEGRATION_TESTS", new HashSet<>(permissions));
    ApplicationEnvironment ae1 = new ApplicationEnvironment();
    ae1.setId("subject1_1");
    ae1.setEnvironmentType(EnvironmentType.INTEGRATION_TESTS);
    ApplicationEnvironment ae2 = new ApplicationEnvironment();
    ae2.setId("subject2_1");
    ae2.setEnvironmentType(EnvironmentType.INTEGRATION_TESTS);
    Mockito.when(applicationEnvironmentService.getByApplicationId("subject1")).thenReturn(new ApplicationEnvironment[] { ae1 });
    // When
    service.grantAuthorizedEnvironmentsAndEnvTypesPerApplication((AbstractSecurityEnabledResource) resourceSecured, new String[] { "subject1" }, new String[] { "subject1_1", "subject2_1" }, new String[] { EnvironmentType.INTEGRATION_TESTS.toString() });
    // Then
    verify(alienDAO).save(resourceSecuredCaptor.capture());
    assertThat(resourceSecuredCaptor.getValue().getPermissions(Subject.APPLICATION, "subject1")).containsExactly(Permission.ADMIN);
    assertThat(resourceSecuredCaptor.getValue().getPermissions(Subject.ENVIRONMENT, "subject1_1")).isEmpty();
    assertThat(resourceSecuredCaptor.getValue().getPermissions(Subject.ENVIRONMENT, "subject2_1")).containsExactly(Permission.ADMIN);
    assertThat(resourceSecuredCaptor.getValue().getPermissions(Subject.ENVIRONMENT_TYPE, EnvironmentType.INTEGRATION_TESTS.toString())).containsExactly(Permission.ADMIN);
}
Also used : Permission(alien4cloud.security.Permission) AbstractSecurityEnabledResource(alien4cloud.security.AbstractSecurityEnabledResource) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ApplicationEnvironment

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

the class ResourcePermissionServiceTest method when_many_app_env_permission_are_revoked_the_resource_is_saved_only_one_time.

@Test
public void when_many_app_env_permission_are_revoked_the_resource_is_saved_only_one_time() throws Exception {
    // Given
    resourceSecured = new AbstractSecurityEnabledResource() {

        @Override
        public String getId() {
            return "id";
        }
    };
    HashSet<Permission> permissions = new HashSet<>();
    permissions.add(Permission.ADMIN);
    resourceSecured.addPermissions(Subject.APPLICATION, "subject1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT, "subject1_1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT, "subject1_2", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT_TYPE, "subject_env_1_1", new HashSet<>(permissions));
    ApplicationEnvironment ae1 = new ApplicationEnvironment();
    ae1.setId("subject1_1");
    ApplicationEnvironment ae2 = new ApplicationEnvironment();
    ae2.setId("subject1_2");
    Mockito.when(applicationEnvironmentService.getByApplicationId("subject1")).thenReturn(new ApplicationEnvironment[] { ae1, ae2 });
    // When
    service.revokeAuthorizedEnvironmentsAndEnvironmentTypesPerApplication((AbstractSecurityEnabledResource) resourceSecured, new String[] { "subject1" }, new String[] { "subject1_1", "subject1_2" }, new String[] { "subject_env_1_1" });
    // Then
    verify(alienDAO).save(resourceSecuredCaptor.capture());
}
Also used : Permission(alien4cloud.security.Permission) AbstractSecurityEnabledResource(alien4cloud.security.AbstractSecurityEnabledResource) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ApplicationEnvironment

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

the class AlienContextVariables method getProperty.

@Override
public Object getProperty(String name) {
    if (!name.startsWith("a4c.")) {
        return null;
    }
    switch(name) {
        case "a4c.application":
            return application;
        case "a4c.application.id":
            return ifNotNull(application, Application::getId);
        case "a4c.application.name":
            return ifNotNull(application, Application::getName);
        case "a4c.environment.type":
            return ifNotNull(applicationEnvironment, ApplicationEnvironment::getEnvironmentType);
        case "a4c.environment.name":
            return ifNotNull(applicationEnvironment, ApplicationEnvironment::getName);
    }
    // lookup for a tag
    if (name.startsWith("a4c.application.tags.")) {
        if (application != null && application.getTags() != null) {
            String tagName = StringUtils.removeStart(name, "a4c.application.tags.");
            for (Tag tag : application.getTags()) {
                if (tag.getName().equals(tagName)) {
                    return tag.getValue();
                }
            }
        }
    }
    // lookup for meta properties
    String metaName = StringUtils.removeStart(name, "a4c.");
    String metaValue = findMetaProperties(metaName, application);
    if (metaValue != null) {
        return metaValue;
    }
    metaValue = findMetaProperties(metaName, location);
    if (metaValue != null) {
        return metaValue;
    }
    return null;
}
Also used : Tag(alien4cloud.model.common.Tag) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Aggregations

ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)82 ApiOperation (io.swagger.annotations.ApiOperation)42 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 Application (alien4cloud.model.application.Application)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)35 Audit (alien4cloud.audit.annotation.Audit)27 List (java.util.List)17 Collectors (java.util.stream.Collectors)16 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)15 RestResponse (alien4cloud.rest.model.RestResponse)15 Topology (org.alien4cloud.tosca.model.templates.Topology)15 Set (java.util.Set)14 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)13 NotFoundException (alien4cloud.exception.NotFoundException)13 Map (java.util.Map)13 Resource (javax.annotation.Resource)12 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)11 Deployment (alien4cloud.model.deployment.Deployment)11 Arrays (java.util.Arrays)11 Location (alien4cloud.model.orchestrators.locations.Location)10