Search in sources :

Example 1 with IdmConceptRoleRequestFilter

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

the class IdmConceptRoleRequestController method toFilter.

@Override
protected IdmConceptRoleRequestFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmConceptRoleRequestFilter filter = new IdmConceptRoleRequestFilter();
    filter.setText(getParameterConverter().toString(parameters, "text"));
    filter.setRoleRequestId(getParameterConverter().toUuid(parameters, "roleRequestId"));
    filter.setState(getParameterConverter().toEnum(parameters, "state", RoleRequestState.class));
    return filter;
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState)

Example 2 with IdmConceptRoleRequestFilter

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

the class IdentitySynchronizationExecutor method createEntityAccount.

@Override
protected EntityAccountDto createEntityAccount(AccAccountDto account, IdmIdentityDto entity, SynchronizationContext context) {
    Assert.notNull(account);
    Assert.notNull(entity);
    EntityAccountDto entityAccount = super.createEntityAccount(account, entity, context);
    Assert.isInstanceOf(AccIdentityAccountDto.class, entityAccount, "For identity sync must be entity-account relation instance of AccIdentityAccountDto!");
    AccIdentityAccountDto identityAccount = (AccIdentityAccountDto) entityAccount;
    SysSyncIdentityConfigDto config = this.getConfig(context);
    UUID defaultRoleId = config.getDefaultRole();
    if (defaultRoleId == null) {
        return identityAccount;
    }
    // Default role is defines
    IdmRoleDto defaultRole = DtoUtils.getEmbedded(config, SysSyncIdentityConfig_.defaultRole, IdmRoleDto.class);
    context.getLogItem().addToLog(MessageFormat.format("Default role [{1}] is defines and will be assigned to the identity [{0}].", entity.getCode(), defaultRole.getCode()));
    Assert.notNull(defaultRole, "Default role must be found for this sync configuration!");
    IdmIdentityContractDto primeContract = identityContractService.getPrimeValidContract(entity.getId());
    if (primeContract == null) {
        context.getLogItem().addToLog("Warning! - Default role is set, but could not be assigned to identity, because was not found any valid identity contract!");
        this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
        return identityAccount;
    }
    // Create role request for default role and primary contract
    IdmRoleRequestDto roleRequest = roleRequestService.createRequest(primeContract, defaultRole);
    roleRequest = roleRequestService.startRequestInternal(roleRequest.getId(), false);
    // Load concept (can be only one)
    IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
    conceptFilter.setRoleRequestId(roleRequest.getId());
    UUID identityRoleId = conceptRoleRequestService.find(conceptFilter, null).getContent().get(0).getIdentityRole();
    Assert.notNull(identityRoleId, "Identity role relation had to been created!");
    identityAccount.setIdentityRole(identityRoleId);
    AccIdentityAccountDto duplicate = this.findDuplicate(identityAccount);
    if (duplicate != null) {
        // This IdentityAccount is new and duplicated, we do not want create duplicated
        // relation.
        // Same IdentityAccount had to be created by assigned default role!
        context.getLogItem().addToLog(MessageFormat.format("This identity-account (identity-role id: {2}) is new and duplicated, " + "we do not want create duplicated relation! " + "We will reusing already persisted identity-account [{3}]. " + "Probable reason: Same  identity-account had to be created by assigned default role!", identityAccount.getAccount(), identityAccount.getIdentity(), identityAccount.getIdentityRole(), duplicate.getId()));
        // Reusing duplicate
        return duplicate;
    }
    return identityAccount;
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) UUID(java.util.UUID) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 3 with IdmConceptRoleRequestFilter

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

the class SelfRoleRequestEvaluatorIntegrationTest method testCanReadSelfRoleRequest.

@Test
public void testCanReadSelfRoleRequest() {
    IdmRoleDto role = roleService.getByCode(InitDemoData.DEFAULT_ROLE_NAME);
    // prepare identity
    IdmIdentityDto identity = helper.createIdentity();
    // assign role request
    IdmRoleRequestDto roleRequest = helper.assignRoles(helper.getPrimeContract(identity.getId()), role);
    // 
    try {
        loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
        // 
        IdmRoleRequestDto read = roleRequestService.get(roleRequest.getId(), IdmBasePermission.READ);
        assertEquals(roleRequest, read);
        // 
        IdmConceptRoleRequestFilter filter = new IdmConceptRoleRequestFilter();
        filter.setRoleRequestId(roleRequest.getId());
        Page<IdmConceptRoleRequestDto> concepts = conceptRoleRequestController.find(filter, null, IdmBasePermission.READ);
        assertEquals(1, concepts.getTotalElements());
    } finally {
        logout();
    }
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 4 with IdmConceptRoleRequestFilter

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

the class DefaultIdmIdentityServiceIntegrationTest method testReferentialRoleRequestIntegrity.

@Test
public void testReferentialRoleRequestIntegrity() {
    IdmIdentityDto identity = helper.createIdentity();
    String username = identity.getUsername();
    // role with guarantee
    IdmRoleDto role = new IdmRoleDto();
    String roleName = "test_r_" + System.currentTimeMillis();
    role.setName(roleName);
    role = roleService.save(role);
    // assigned role
    IdmRoleRequestDto request = helper.assignRoles(helper.getPrimeContract(identity.getId()), false, role);
    IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
    conceptFilter.setRoleRequestId(request.getId());
    IdmIdentityRoleFilter identityRolefilter = new IdmIdentityRoleFilter();
    identityRolefilter.setIdentityId(identity.getId());
    assertNotNull(identityService.getByUsername(username));
    assertEquals(1, identityRoleService.find(identityRolefilter, null).getTotalElements());
    assertEquals(1, conceptRequestService.find(conceptFilter, null).getTotalElements());
    IdmConceptRoleRequestDto concept = conceptRequestService.find(conceptFilter, null).getContent().get(0);
    concept.setWfProcessId("test_wf_" + System.currentTimeMillis());
    conceptRequestService.save(concept);
    // 
    identityService.delete(identity);
    role = roleService.get(role.getId());
    // 
    assertNull(identityService.getByUsername(username));
    assertNull(passwordService.findOneByIdentity(identity.getId()));
    assertEquals(0, identityContractService.findAllByIdentity(identity.getId()).size());
    assertEquals(0, identityRoleService.find(identityRolefilter, null).getTotalElements());
    assertEquals(0, conceptRequestService.find(conceptFilter, null).getTotalElements());
    roleService.delete(role);
    assertNull(roleService.get(role.getId()));
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with IdmConceptRoleRequestFilter

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

the class IdmRoleRequestController method getConcepts.

@ResponseBody
@RequestMapping(value = "/{backendId}/concepts", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_READ + "')")
@ApiOperation(value = "Role request concepts", nickname = "getRoleRequestConcepts", tags = { IdmRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = "") }) })
@ApiImplicitParams({ @ApiImplicitParam(name = "parameters", allowMultiple = true, dataType = "string", paramType = "query", value = "Search criteria parameters. Parameters could be registered by module. Example id=25c5b9e8-b15d-4f95-b715-c7edf6f4aee6"), @ApiImplicitParam(name = "page", dataType = "string", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "string", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. " + "Multiple sort criteria are supported.") })
public Resources<?> getConcepts(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable String backendId, @RequestParam(required = false) MultiValueMap<String, Object> parameters, @PageableDefault Pageable pageable) {
    IdmRoleRequestDto entity = getDto(backendId);
    if (entity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    IdmConceptRoleRequestFilter filter = conceptRoleRequestController.toFilter(parameters);
    filter.setRoleRequestId(entity.getId());
    // 
    return toResources(conceptRoleRequestController.find(filter, pageable, IdmBasePermission.READ), IdmRoleRequestDto.class);
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) 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

IdmConceptRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter)10 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)6 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 Test (org.junit.Test)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)2 IdmAutomaticRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter)2 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)2 UUID (java.util.UUID)2 PageRequest (org.springframework.data.domain.PageRequest)2 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)1 EntityAccountDto (eu.bcvsolutions.idm.acc.dto.EntityAccountDto)1 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)1 RoleRequestState (eu.bcvsolutions.idm.core.api.domain.RoleRequestState)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)1