Search in sources :

Example 6 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.

the class IdmAutomaticRoleAttributeController method deleteViaRequest.

@ResponseBody
@RequestMapping(value = "/delete-via-request/{backendId}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUTOMATIC_ROLE_ATTRIBUTE_DELETE + "')")
@ApiOperation(value = "Delete automatic role by attribute. Uses request.", nickname = "deleteAutomaticRoleAttributeViaRequest", tags = { IdmAutomaticRoleAttributeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_ATTRIBUTE_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUTOMATIC_ROLE_ATTRIBUTE_DELETE, description = "") }) })
public ResponseEntity<?> deleteViaRequest(@ApiParam(value = "Automatic role's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmAutomaticRoleAttributeDto automaticRole = this.getDto(backendId);
    Assert.notNull(automaticRole);
    requestService.deleteAutomaticRole(automaticRole, AutomaticRoleRequestType.ATTRIBUTE);
    throw new AcceptedException();
}
Also used : AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException 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!");
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 8 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException 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!");
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 9 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException 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!");
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 10 with AcceptedException

use of eu.bcvsolutions.idm.core.api.exception.AcceptedException in project CzechIdMng by bcvsolutions.

the class IdmRoleTreeNodeController method delete.

@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLETREENODE_DELETE + "')")
@ApiOperation(value = "Delete automatic role. Uses request!", nickname = "deleteRoleTreeNode", tags = { IdmRoleTreeNodeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLETREENODE_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLETREENODE_DELETE, description = "") }) })
public ResponseEntity<?> delete(@ApiParam(value = "Automatic role's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmRoleTreeNodeDto automaticRole = this.getDto(backendId);
    Assert.notNull(automaticRole);
    requestService.deleteAutomaticRole(automaticRole, AutomaticRoleRequestType.TREE);
    throw new AcceptedException();
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)17 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)10 UUID (java.util.UUID)10 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)6 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)6 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)5 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmRoleGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto)5 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)5 Test (org.junit.Test)5 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)4 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)3 IdmRoleTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IdmAutomaticRoleAttributeRuleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 RoleTreeNodeEvent (eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent)2