Search in sources :

Example 11 with IdmAuthorizationPolicyFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter in project CzechIdMng by bcvsolutions.

the class IdmAuthorizationPolicyControllerRestTest method testFindByAuthorizableType.

@Test
public void testFindByAuthorizableType() {
    IdmRoleDto role = getHelper().createRole();
    // 
    IdmAuthorizationPolicyDto policyOne = getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ);
    // other
    getHelper().createBasePolicy(role.getId(), CoreGroupPermission.ROLE, IdmRole.class, IdmBasePermission.READ);
    // 
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setRoleId(role.getId());
    // FIXME: move to api
    filter.setAuthorizableType(IdmIdentity.class.getCanonicalName());
    List<IdmAuthorizationPolicyDto> policies = find(filter);
    Assert.assertEquals(1, policies.size());
    Assert.assertTrue(policies.stream().anyMatch(p -> p.getId().equals(policyOne.getId())));
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) AuthorizationPolicyByIdentityFilterBuilder(eu.bcvsolutions.idm.core.model.repository.filter.AuthorizationPolicyByIdentityFilterBuilder) StringUtils(org.apache.commons.lang3.StringUtils) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) BasePermissionEvaluator(eu.bcvsolutions.idm.core.security.evaluator.BasePermissionEvaluator) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 12 with IdmAuthorizationPolicyFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter in project CzechIdMng by bcvsolutions.

the class RoleTransitiveEvaluatorsIntegrationTest method testDisabledPolicy.

@Test
public void testDisabledPolicy() {
    IdmIdentityDto identity = createIdentityWithRole(true);
    IdmRoleDto role = null;
    // before disbale
    try {
        loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
        // 
        role = roleService.get(TEST_ROLE_ID, IdmBasePermission.READ);
        assertEquals(TEST_ROLE_ID, role.getId());
        assertEquals(1, roleService.find(null, IdmBasePermission.READ).getTotalElements());
        assertEquals(1, roleTreeNodeService.find(null, IdmBasePermission.READ).getTotalElements());
        assertEquals(3, authorizationPolicyService.find(null, IdmBasePermission.READ).getTotalElements());
    } finally {
        logout();
    }
    // 
    // disable policy
    loginAsAdmin();
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setRoleId(role.getId());
    filter.setAuthorizableType(IdmRole.class.getCanonicalName());
    IdmAuthorizationPolicyDto policy = authorizationPolicyService.find(filter, null).getContent().get(0);
    policy.setDisabled(true);
    authorizationPolicyService.save(policy);
    logout();
    // after disable
    try {
        loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
        // 
        assertEquals(0, roleService.find(null, IdmBasePermission.READ).getTotalElements());
        assertEquals(0, roleTreeNodeService.find(null, IdmBasePermission.READ).getTotalElements());
        assertEquals(0, authorizationPolicyService.find(null, IdmBasePermission.READ).getTotalElements());
    } finally {
        logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 13 with IdmAuthorizationPolicyFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter in project CzechIdMng by bcvsolutions.

the class IdmAuthorizationPolicyControllerRestTest method testFindByText.

@Test
public void testFindByText() {
    IdmRoleDto role = getHelper().createRole();
    // 
    IdmAuthorizationPolicyDto policyOne = getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ);
    // other
    getHelper().createBasePolicy(role.getId(), CoreGroupPermission.ROLE, IdmRole.class, IdmBasePermission.READ);
    // 
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setRoleId(role.getId());
    filter.setText(IdmIdentity.class.getSimpleName());
    List<IdmAuthorizationPolicyDto> policies = find(filter);
    Assert.assertEquals(1, policies.size());
    Assert.assertTrue(policies.stream().anyMatch(p -> p.getId().equals(policyOne.getId())));
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) AuthorizationPolicyByIdentityFilterBuilder(eu.bcvsolutions.idm.core.model.repository.filter.AuthorizationPolicyByIdentityFilterBuilder) StringUtils(org.apache.commons.lang3.StringUtils) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) BasePermissionEvaluator(eu.bcvsolutions.idm.core.security.evaluator.BasePermissionEvaluator) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 14 with IdmAuthorizationPolicyFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter in project CzechIdMng by bcvsolutions.

the class AbstractInitApplicationProcessor method findConfiguredPolicies.

/**
 * Find all configured role policies (disabled included).
 *
 * @param role related role
 * @return configured policies
 */
protected List<IdmAuthorizationPolicyDto> findConfiguredPolicies(IdmRoleDto role) {
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setRoleId(role.getId());
    return authorizationPolicyService.find(filter, null).getContent();
}
Also used : IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter)

Example 15 with IdmAuthorizationPolicyFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter in project CzechIdMng by bcvsolutions.

the class RoleExportBulkAction method exportPermissions.

/**
 * Export permissions for given role.
 *
 * @param role
 */
private void exportPermissions(IdmRoleDto role) {
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setRoleId(role.getId());
    List<IdmAuthorizationPolicyDto> dtos = authorizationPolicyService.find(filter, null).getContent();
    if (dtos.isEmpty()) {
        authorizationPolicyService.export(ExportManager.BLANK_UUID, this.getBatch());
    }
    dtos.forEach(dto -> {
        authorizationPolicyService.export(dto.getId(), this.getBatch());
    });
    // Set parent field -> set authoritative mode.
    this.getExportManager().setAuthoritativeMode(IdmAuthorizationPolicy_.role.getName(), "roleId", IdmAuthorizationPolicyDto.class, this.getBatch());
}
Also used : IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter)

Aggregations

IdmAuthorizationPolicyFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter)19 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)13 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)12 Test (org.junit.Test)11 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)9 List (java.util.List)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)7 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)7 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)7 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 Assert (org.junit.Assert)6 RoleConfiguration (eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration)5 IdmGroupPermission (eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission)5 StringUtils (org.apache.commons.lang3.StringUtils)5 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)4 AbstractReadWriteDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController)4 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)4 IdmAuthorizationPolicyService (eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService)4