use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateTreeAutomaticRoleWithApproval.
@Test
public void testCreateTreeAutomaticRoleWithApproval() {
IdmRoleDto role = prepareRole();
IdmTreeNodeDto nodeOne = helper.createTreeNode();
IdmIdentityDto guaranteeIdentity = helper.createIdentity();
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(role.getId());
guarantee.setGuarantee(guaranteeIdentity.getId());
role.getGuarantees().add(guarantee);
role = roleService.save(role);
IdmRoleTreeNodeDto automaticRole = new IdmRoleTreeNodeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
automaticRole.setTreeNode(nodeOne.getId());
// Create automatic role via manager
try {
automaticRole = automaticRoleManager.createAutomaticRoleByTree(automaticRole, false);
} catch (AcceptedException ex) {
// The request is in approval
Assert.assertNotNull(ex.getIdentifier());
UUID requestId = UUID.fromString(ex.getIdentifier());
loginAsNoAdmin(guaranteeIdentity.getUsername());
try {
completeTasksFromUsers(guaranteeIdentity.getUsername(), "approve");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
Assert.assertEquals(RequestState.EXECUTED, request.getState());
Assert.assertNotNull(request.getAutomaticRole());
IdmRoleTreeNodeDto treeAutomaticRole = roleTreeNodeService.get(request.getAutomaticRole());
Assert.assertNotNull(treeAutomaticRole);
Assert.assertEquals(nodeOne.getId(), treeAutomaticRole.getTreeNode());
Assert.assertEquals(role.getId(), treeAutomaticRole.getRole());
return;
}
fail("Automatic role request have to be approving by gurantee!");
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testDeleteAutomaticAttributeRoleApproval.
@Test
public void testDeleteAutomaticAttributeRoleApproval() {
IdmRoleDto role = prepareRole();
IdmIdentityDto guaranteeIdentity = helper.createIdentity();
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(role.getId());
guarantee.setGuarantee(guaranteeIdentity.getId());
role.getGuarantees().add(guarantee);
role = roleService.save(role);
IdmIdentityDto identity = helper.createIdentity();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, true, rule);
// Delete automatic role via manager
try {
automaticRoleManager.deleteAutomaticRole(automaticRole, false);
} catch (AcceptedException ex) {
// The request is in approval
Assert.assertNotNull(ex.getIdentifier());
UUID requestId = UUID.fromString(ex.getIdentifier());
loginAsNoAdmin(guaranteeIdentity.getUsername());
try {
completeTasksFromUsers(guaranteeIdentity.getUsername(), "approve");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
Assert.assertEquals(RequestState.EXECUTED, request.getState());
IdmRoleTreeNodeDto deletedAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
Assert.assertNull(deletedAutomaticRole);
return;
}
fail("Automatic role request have to be approving by gurantee!");
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method notRightForExecuteImmediatelyExceptionTest.
@Test(expected = RoleRequestException.class)
public void notRightForExecuteImmediatelyExceptionTest() {
this.logout();
IdmIdentityDto identity = helper.createIdentity();
// Log as user without right for immediately execute role request (without
// approval)
Collection<GrantedAuthority> authorities = IdmAuthorityUtils.toAuthorities(moduleService.getAvailablePermissions()).stream().filter(authority -> {
return !CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_ADMIN.equals(authority.getAuthority()) && !IdmGroupPermission.APP_ADMIN.equals(authority.getAuthority());
}).collect(Collectors.toList());
SecurityContextHolder.getContext().setAuthentication(new IdmJwtAuthentication(new IdmIdentityDto(identity.getUsername()), null, authorities, "test"));
IdmRoleDto role = prepareRole();
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setState(RequestState.EXECUTED);
request.setOperation(RequestOperationType.ADD);
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
request.setExecuteImmediately(true);
request.setName(role.getName());
request.setRole(role.getId());
request = roleRequestService.save(request);
Assert.assertEquals(RequestState.CONCEPT, request.getState());
IdmAutomaticRoleAttributeRuleRequestDto rule = new IdmAutomaticRoleAttributeRuleRequestDto();
rule.setRequest(request.getId());
rule.setOperation(RequestOperationType.ADD);
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue("test");
rule = ruleRequestService.save(rule);
// We expect exception state (we don`t have right for execute without approval)
roleRequestService.startRequestInternal(request.getId(), true);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRoleWithApprovalDisapprove.
@Test
public void testCreateAutomaticAttributeRoleWithApprovalDisapprove() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto guaranteeIdentity = helper.createIdentity();
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(role.getId());
guarantee.setGuarantee(guaranteeIdentity.getId());
role.getGuarantees().add(guarantee);
role = roleService.save(role);
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
try {
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, false, rule);
} catch (AcceptedException ex) {
// The request is in approval
Assert.assertNotNull(ex.getIdentifier());
UUID requestId = UUID.fromString(ex.getIdentifier());
loginAsNoAdmin(guaranteeIdentity.getUsername());
try {
completeTasksFromUsers(guaranteeIdentity.getUsername(), "disapprove");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
Assert.assertEquals(RequestState.DISAPPROVED, request.getState());
Assert.assertNull(request.getAutomaticRole());
return;
}
fail("Automatic role request have to be approving by gurantee!");
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testDeleteTreeAutomaticRoleApproval.
@Test
public void testDeleteTreeAutomaticRoleApproval() {
IdmRoleDto role = prepareRole();
IdmTreeNodeDto nodeOne = helper.createTreeNode();
IdmIdentityDto guaranteeIdentity = helper.createIdentity();
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(role.getId());
guarantee.setGuarantee(guaranteeIdentity.getId());
role.getGuarantees().add(guarantee);
role = roleService.save(role);
IdmRoleTreeNodeDto automaticRole = new IdmRoleTreeNodeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
automaticRole.setTreeNode(nodeOne.getId());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByTree(automaticRole, true);
Assert.assertNotNull(automaticRole.getId());
IdmRoleTreeNodeDto treeAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
Assert.assertNotNull(treeAutomaticRole);
Assert.assertEquals(nodeOne.getId(), treeAutomaticRole.getTreeNode());
Assert.assertEquals(role.getId(), treeAutomaticRole.getRole());
// Delete automatic role via manager
try {
automaticRoleManager.deleteAutomaticRole(automaticRole, false);
} catch (AcceptedException ex) {
// The request is in approval
Assert.assertNotNull(ex.getIdentifier());
UUID requestId = UUID.fromString(ex.getIdentifier());
loginAsNoAdmin(guaranteeIdentity.getUsername());
try {
completeTasksFromUsers(guaranteeIdentity.getUsername(), "approve");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
Assert.assertEquals(RequestState.EXECUTED, request.getState());
IdmRoleTreeNodeDto deletedAutomaticRole = roleTreeNodeService.get(automaticRole.getId());
Assert.assertNull(deletedAutomaticRole);
return;
}
fail("Automatic role request have to be approving by gurantee!");
}
Aggregations