use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultAuthorizationManagerIntegrationTest method testPredicate.
@Test
public void testPredicate() {
loginAsAdmin(InitTestData.TEST_USER_1);
// prepare role
IdmRoleDto role = helper.createRole();
helper.createUuidPolicy(role.getId(), role.getId(), IdmBasePermission.READ);
helper.createBasePolicy(role.getId(), IdmBasePermission.AUTOCOMPLETE);
// prepare identity
IdmIdentityDto identity = helper.createIdentity();
identity.setPassword(new GuardedString("heslo"));
identityService.save(identity);
// assign role
helper.createIdentityRole(identity, role);
logout();
//
// empty without login
IdmRoleFilter filter = new IdmRoleFilter();
assertEquals(0, roleService.find(filter, null, IdmBasePermission.READ).getTotalElements());
assertEquals(0, roleService.find(filter, null, IdmBasePermission.AUTOCOMPLETE).getTotalElements());
//
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
//
// evaluate access
assertEquals(1, roleService.find(filter, null, IdmBasePermission.READ).getTotalElements());
assertEquals(roleService.find(null).getTotalElements(), roleService.find(filter, null, IdmBasePermission.AUTOCOMPLETE).getTotalElements());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnlyOnTheSameEnvironment.
@Test
public void testDuplicateRoleOnlyOnTheSameEnvironment() {
IdmRoleDto role = createRole();
// create attributes, automatic roles etc.
createRoleFormAttribute(role, getHelper().createName(), getHelper().createName());
createAutomaticRole(role, getHelper().createTreeNode());
createAutomaticRole(role, getHelper().createName());
//
Assert.assertFalse(findAllSubRoles(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByTree(role).isEmpty());
Assert.assertFalse(findRoleFormAttributes(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByAttribute(role).isEmpty());
//
String roleBaseCode = role.getBaseCode();
//
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, false);
bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, false);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, false);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
IdmRoleFilter filter = new IdmRoleFilter();
filter.setEnvironment(role.getEnvironment());
List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
Assert.assertNotNull(duplicate);
Assert.assertEquals(duplicate.getName(), role.getName());
Assert.assertEquals(duplicate.getDescription(), role.getDescription());
//
Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByTree(duplicate).isEmpty());
Assert.assertTrue(findRoleFormAttributes(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByAttribute(duplicate).isEmpty());
//
role.setDescription(getHelper().createName());
//
processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
filter = new IdmRoleFilter();
filter.setProperty(IdmRole_.name.getName());
filter.setValue(role.getName());
roles = roleService.find(filter, null).getContent();
// on the same environment is created the second duplicate
Assert.assertEquals(3, roles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnTheSameEnvironmentWithComposition.
/**
* Sub roles are used the same as on parent
*/
@Test
public void testDuplicateRoleOnTheSameEnvironmentWithComposition() {
IdmRoleDto role = createRole();
List<IdmRoleCompositionDto> subRoles = findAllSubRoles(role);
Assert.assertFalse(subRoles.isEmpty());
//
String roleBaseCode = role.getBaseCode();
//
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
IdmRoleFilter filter = new IdmRoleFilter();
filter.setEnvironment(role.getEnvironment());
List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
//
List<IdmRoleCompositionDto> duplicateSubRoles = findAllSubRoles(duplicate);
Assert.assertFalse(duplicateSubRoles.isEmpty());
Assert.assertEquals(subRoles.size(), duplicateSubRoles.size());
Assert.assertTrue(duplicateSubRoles.stream().allMatch(s -> subRoles.stream().anyMatch(r -> r.getSub().equals(s.getSub()))));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnlyOnTheSameEnvironmentGivenAsProperty.
@Test
public void testDuplicateRoleOnlyOnTheSameEnvironmentGivenAsProperty() {
IdmRoleDto role = createRole();
// create attributes, automatic roles etc.
createRoleFormAttribute(role, getHelper().createName(), getHelper().createName());
createAutomaticRole(role, getHelper().createTreeNode());
createAutomaticRole(role, getHelper().createName());
//
Assert.assertFalse(findAllSubRoles(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByTree(role).isEmpty());
Assert.assertFalse(findRoleFormAttributes(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByAttribute(role).isEmpty());
//
String roleBaseCode = role.getBaseCode();
//
String targetEnvironment = role.getEnvironment();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, false);
bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, false);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, false);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
IdmRoleFilter filter = new IdmRoleFilter();
filter.setEnvironment(targetEnvironment);
List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
Assert.assertEquals(role.getName(), duplicate.getName());
Assert.assertEquals(role.getDescription(), duplicate.getDescription());
//
Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByTree(duplicate).isEmpty());
Assert.assertTrue(findRoleFormAttributes(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByAttribute(duplicate).isEmpty());
//
role.setDescription(getHelper().createName());
//
processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
filter = new IdmRoleFilter();
filter.setProperty(IdmRole_.name.getName());
filter.setValue(role.getName());
roles = roleService.find(filter, null).getContent();
// on the same environment is created the second duplicate
Assert.assertEquals(3, roles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleDeleteBulkActionIntegrationTest method processBulkActionByFilter.
@Test
public void processBulkActionByFilter() {
String testDescription = "bulkActionName" + System.currentTimeMillis();
List<IdmRoleDto> roles = this.createRoles(5);
for (IdmRoleDto role : roles) {
role.setDescription(testDescription);
role = roleService.save(role);
}
IdmRoleFilter filter = new IdmRoleFilter();
filter.setValue(testDescription);
filter.setProperty(IdmRole_.description.getName());
List<IdmRoleDto> checkIdentities = roleService.find(filter, null).getContent();
assertEquals(5, checkIdentities.size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmRole.class, RoleDeleteBulkAction.NAME);
bulkAction.setTransformedFilter(filter);
bulkAction.setFilter(toMap(filter));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 5l, null, null);
for (IdmRoleDto role : roles) {
IdmRoleDto dto = roleService.get(role.getId());
assertNull(dto);
}
}
Aggregations