Search in sources :

Example 1 with ISecurityEnabledResource

use of alien4cloud.security.ISecurityEnabledResource in project alien4cloud by alien4cloud.

the class ResourcePermissionServiceTest method check_revoked_permissions_have_been_removed_from_resource.

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

        @Override
        public String getId() {
            return "id";
        }
    };
    HashSet<Permission> permissions = new HashSet<>();
    permissions.add(Permission.READ);
    permissions.add(Permission.ADMIN);
    resourceSecured.addPermissions(Subject.APPLICATION, "subject1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.APPLICATION, "subject3", new HashSet<>(permissions));
    // When
    service.revokePermission(resourceSecured, resourceSaver, Subject.APPLICATION, "subject1", "subject2");
    // Then
    verify(resourceSaver).save(resourceSecuredCaptor.capture());
    ISecurityEnabledResource resourceSecuredSaved = resourceSecuredCaptor.getValue();
    assertThat(resourceSecuredSaved.getPermissions(Subject.APPLICATION, "subject1")).containsExactly(Permission.READ);
    assertThat(resourceSecuredSaved.getPermissions(Subject.APPLICATION, "subject2")).isEmpty();
    assertThat(resourceSecuredSaved.getPermissions(Subject.APPLICATION, "subject3")).containsExactlyInAnyOrder(Permission.ADMIN, Permission.READ);
}
Also used : ISecurityEnabledResource(alien4cloud.security.ISecurityEnabledResource) Permission(alien4cloud.security.Permission) AbstractSecurityEnabledResource(alien4cloud.security.AbstractSecurityEnabledResource) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AbstractSecurityEnabledResource (alien4cloud.security.AbstractSecurityEnabledResource)1 ISecurityEnabledResource (alien4cloud.security.ISecurityEnabledResource)1 Permission (alien4cloud.security.Permission)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1