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())));
}
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();
}
}
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())));
}
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();
}
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());
}
Aggregations