test_class.declarator: service
test_class.modifier: private
test_class.original_string: private ResourcePermissionService service;
test_class.type: ResourcePermissionService
test_class.var_name: service
test_class.declarator: alienDAO
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private IGenericSearchDAO alienDAO;
test_class.type: IGenericSearchDAO
test_class.var_name: alienDAO
test_class.declarator: resourceSaver
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private ResourcePermissionService.IResourceSaver resourceSaver;
test_class.type: ResourcePermissionService.IResourceSaver
test_class.var_name: resourceSaver
test_class.declarator: resourceSecuredCaptor
test_class.modifier: @Captor
      private
test_class.original_string: @Captor
      private ArgumentCaptor<ISecurityEnabledResource> resourceSecuredCaptor;
test_class.type: ArgumentCaptor<ISecurityEnabledResource>
test_class.var_name: resourceSecuredCaptor
test_class.declarator: resourceSecured
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private ISecurityEnabledResource resourceSecured;
test_class.type: ISecurityEnabledResource
test_class.var_name: resourceSecured
test_class.declarator: publisher
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private ApplicationEventPublisher publisher;
test_class.type: ApplicationEventPublisher
test_class.var_name: publisher
test_class.declarator: applicationEnvironmentService
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private ApplicationEnvironmentService applicationEnvironmentService;
test_class.type: ApplicationEnvironmentService
test_class.var_name: applicationEnvironmentService
test_class.file: alien4cloud-core/src/test/java/alien4cloud/authorization/ResourcePermissionServiceTest.java
test_class.identifier: ResourcePermissionServiceTest
test_case.body: @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);
      }
test_case.class_method_signature: ResourcePermissionServiceTest.when_permission_added_at_application_level_unrelated_environment_and_env_type_are_unmodified()
test_case.full_signature: @Test public void when_permission_added_at_application_level_unrelated_environment_and_env_type_are_unmodified()
test_case.identifier: when_permission_added_at_application_level_unrelated_environment_and_env_type_are_unmodified
test_case.invocations: add addPermissions addPermissions addPermissions addPermissions setId setEnvironmentType setId setEnvironmentType thenReturn when getByApplicationId grantAuthorizedEnvironmentsAndEnvTypesPerApplication toString save verify capture containsExactly assertThat getPermissions getValue isEmpty assertThat getPermissions getValue containsExactly assertThat getPermissions getValue containsExactly assertThat getPermissions getValue toString
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void when_permission_added_at_application_level_unrelated_environment_and_env_type_are_unmodified()
focal_class.declarator: alienDAO
focal_class.modifier: @Resource(name = "alien-es-dao")
      private
focal_class.original_string: @Resource(name = "alien-es-dao")
      private IGenericSearchDAO alienDAO;
focal_class.type: IGenericSearchDAO
focal_class.var_name: alienDAO
focal_class.declarator: alienUserDao
focal_class.modifier: @Inject
      private
focal_class.original_string: @Inject
      private IAlienUserDao alienUserDao;
focal_class.type: IAlienUserDao
focal_class.var_name: alienUserDao
focal_class.declarator: alienGroupDao
focal_class.modifier: @Inject
      private
focal_class.original_string: @Inject
      private IAlienGroupDao alienGroupDao;
focal_class.type: IAlienGroupDao
focal_class.var_name: alienGroupDao
focal_class.declarator: applicationEnvironmentService
focal_class.modifier: @Inject
      private
focal_class.original_string: @Inject
      private ApplicationEnvironmentService applicationEnvironmentService;
focal_class.type: ApplicationEnvironmentService
focal_class.var_name: applicationEnvironmentService
focal_class.declarator: publisher
focal_class.modifier: @Inject
      private
focal_class.original_string: @Inject
      private ApplicationEventPublisher publisher;
focal_class.type: ApplicationEventPublisher
focal_class.var_name: publisher
focal_class.file: alien4cloud-core/src/main/java/alien4cloud/authorization/ResourcePermissionService.java
focal_class.identifier: ResourcePermissionService
focal_class.class_method_signature: ResourcePermissionService.grantPermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects)
focal_class.full_signature: public void grantPermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects)
focal_class.identifier: grantPermission
focal_class.modifiers: public
focal_class.parameters: (ISecurityEnabledResource resource, Subject subjectType, String... subjects)
focal_class.return: void
focal_class.signature: void grantPermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects)
focal_class.class_method_signature: ResourcePermissionService.grantPermission(ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects)
focal_class.full_signature: public void grantPermission(ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects)
focal_class.identifier: grantPermission
focal_class.modifiers: public
focal_class.parameters: (ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects)
focal_class.return: void
focal_class.signature: void grantPermission(ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects)
focal_class.class_method_signature: ResourcePermissionService.revokePermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects)
focal_class.full_signature: public void revokePermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects)
focal_class.identifier: revokePermission
focal_class.modifiers: public
focal_class.parameters: (ISecurityEnabledResource resource, Subject subjectType, String... subjects)
focal_class.return: void
focal_class.signature: void revokePermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects)
focal_class.class_method_signature: ResourcePermissionService.revokePermission(ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects)
focal_class.full_signature: public void revokePermission(ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects)
focal_class.identifier: revokePermission
focal_class.modifiers: public
focal_class.parameters: (ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects)
focal_class.return: void
focal_class.signature: void revokePermission(ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects)
focal_class.class_method_signature: ResourcePermissionService.hasPermission(ISecurityEnabledResource resource, Subject subjectType, String subject)
focal_class.full_signature: private boolean hasPermission(ISecurityEnabledResource resource, Subject subjectType, String subject)
focal_class.identifier: hasPermission
focal_class.modifiers: private
focal_class.parameters: (ISecurityEnabledResource resource, Subject subjectType, String subject)
focal_class.return: boolean
focal_class.signature: boolean hasPermission(ISecurityEnabledResource resource, Subject subjectType, String subject)
focal_class.class_method_signature: ResourcePermissionService.anyHasPermission(ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects)
focal_class.full_signature: public boolean anyHasPermission(ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects)
focal_class.identifier: anyHasPermission
focal_class.modifiers: public
focal_class.parameters: (ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects)
focal_class.return: boolean
focal_class.signature: boolean anyHasPermission(ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects)
focal_class.class_method_signature: ResourcePermissionService.allHavePermission(ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects)
focal_class.full_signature: public boolean allHavePermission(ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects)
focal_class.identifier: allHavePermission
focal_class.modifiers: public
focal_class.parameters: (ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects)
focal_class.return: boolean
focal_class.signature: boolean allHavePermission(ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects)
focal_class.class_method_signature: ResourcePermissionService.getAuthorizedUsers(AbstractSecurityEnabledResource resource)
focal_class.full_signature: public List<User> getAuthorizedUsers(AbstractSecurityEnabledResource resource)
focal_class.identifier: getAuthorizedUsers
focal_class.modifiers: public
focal_class.parameters: (AbstractSecurityEnabledResource resource)
focal_class.return: List<User>
focal_class.signature: List<User> getAuthorizedUsers(AbstractSecurityEnabledResource resource)
focal_class.class_method_signature: ResourcePermissionService.getAuthorizedGroups(AbstractSecurityEnabledResource resource)
focal_class.full_signature: public List<Group> getAuthorizedGroups(AbstractSecurityEnabledResource resource)
focal_class.identifier: getAuthorizedGroups
focal_class.modifiers: public
focal_class.parameters: (AbstractSecurityEnabledResource resource)
focal_class.return: List<Group>
focal_class.signature: List<Group> getAuthorizedGroups(AbstractSecurityEnabledResource resource)
focal_class.class_method_signature: ResourcePermissionService.revokeAuthorizedEnvironmentsAndEnvironmentTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToDelete,
                                                                                String[] environmentsToDelete, String[] environmentTypesToDelete)
focal_class.full_signature: public void revokeAuthorizedEnvironmentsAndEnvironmentTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToDelete,
                                                                                String[] environmentsToDelete, String[] environmentTypesToDelete)
focal_class.identifier: revokeAuthorizedEnvironmentsAndEnvironmentTypesPerApplication
focal_class.modifiers: public
focal_class.parameters: (AbstractSecurityEnabledResource resource, String[] applicationsToDelete,
                                                                                String[] environmentsToDelete, String[] environmentTypesToDelete)
focal_class.return: void
focal_class.signature: void revokeAuthorizedEnvironmentsAndEnvironmentTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToDelete,
                                                                                String[] environmentsToDelete, String[] environmentTypesToDelete)
focal_class.class_method_signature: ResourcePermissionService.grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                       String[] environmentTypesToAdd)
focal_class.full_signature: public void grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                       String[] environmentTypesToAdd)
focal_class.identifier: grantAuthorizedEnvironmentsAndEnvTypesPerApplication
focal_class.modifiers: public
focal_class.parameters: (AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                       String[] environmentTypesToAdd)
focal_class.return: void
focal_class.signature: void grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                       String[] environmentTypesToAdd)
focal_method.body: 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);
      }
focal_method.class_method_signature: ResourcePermissionService.grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                       String[] environmentTypesToAdd)
focal_method.full_signature: public void grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                       String[] environmentTypesToAdd)
focal_method.identifier: grantAuthorizedEnvironmentsAndEnvTypesPerApplication
focal_method.invocations: newArrayList isNotEmpty grantPermission getByApplicationId add getId isEmpty revokePermission toArray size newHashSet values add toString isEmpty revokePermission toArray size isNotEmpty collect filter stream contains toList grantPermission toArray size isNotEmpty grantPermission save
focal_method.modifiers: public
focal_method.parameters: (AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                       String[] environmentTypesToAdd)
focal_method.return: void
focal_method.signature: void grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                       String[] environmentTypesToAdd)