Search in sources :

Example 46 with IdmIdentityRoleDto

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

the class DefaultIdmRoleCompositionService method removeSubRoles.

@Override
@Transactional
public void removeSubRoles(EntityEvent<IdmIdentityRoleDto> event, BasePermission... permission) {
    Assert.notNull(event, "Event is required.");
    IdmIdentityRoleDto directRole = event.getContent();
    Assert.notNull(directRole, "Direct role is required.");
    Assert.notNull(directRole.getId(), "Direct role identifier is required.");
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setDirectRoleId(directRole.getId());
    // 
    identityRoleService.find(filter, null).forEach(subIdentityRole -> {
        IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.DELETE, subIdentityRole);
        // 
        identityRoleService.publish(subEvent, event, permission);
        // Notes identity-accounts to ACM
        notingIdentityAccountForDelayedAcm(event, subEvent);
    });
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with IdmIdentityRoleDto

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

the class DefaultIdmIdentityRoleService method siemLog.

/**
 * Method provides specific logic for role assignment siem logging.
 */
@Override
protected void siemLog(EntityEvent<IdmIdentityRoleDto> event, String status, String detail) {
    if (event == null) {
        return;
    }
    IdmIdentityRoleDto dto = event.getContent();
    String operationType = event.getType().name();
    String action = siemLoggerManager.buildAction(SiemLoggerManager.ROLE_ASSIGNMENT_LEVEL_KEY, operationType);
    if (siemLoggerManager.skipLogging(action)) {
        return;
    }
    IdmIdentityContractDto contractDto = lookupService.lookupEmbeddedDto(dto, IdmIdentityRole_.identityContract.getName());
    IdmRoleDto subjectDto = lookupService.lookupEmbeddedDto(dto, IdmIdentityRole_.role.getName());
    IdmIdentityDto targetDto = lookupService.lookupEmbeddedDto(contractDto, IdmIdentityContract_.identity.getName());
    String transactionUuid = Objects.toString(dto.getTransactionId(), "");
    siemLog(action, status, targetDto, subjectDto, transactionUuid, detail);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 48 with IdmIdentityRoleDto

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

the class DefaultIdmRoleRequestServiceIntegrationTest method removePermissionViaRoleRequestTest.

@Test
@Transactional
public void removePermissionViaRoleRequestTest() {
    this.addPermissionViaRoleRequestTest();
    IdmIdentityDto testA = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto roleA = getHelper().createRole(100);
    IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
    getHelper().createIdentityRole(testA, roleA);
    IdmRoleRequestDto request = new IdmRoleRequestDto();
    request.setApplicant(testA.getId());
    request.setExecuteImmediately(true);
    request.setRequestedByType(RoleRequestedByType.MANUALLY);
    request = roleRequestService.save(request);
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(testA.getId());
    Assert.assertEquals(1, identityRoles.size());
    IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
    conceptA.setRoleRequest(request.getId());
    conceptA.setRole(identityRoles.get(0).getRole());
    conceptA.setOperation(ConceptRoleRequestOperation.REMOVE);
    conceptA.setIdentityContract(contractA.getId());
    conceptA.setIdentityRole(identityRoles.get(0).getId());
    conceptA = conceptRoleRequestService.save(conceptA);
    getHelper().startRequestInternal(request, true, true);
    request = roleRequestService.get(request.getId());
    Assert.assertEquals(RoleRequestState.EXECUTED, request.getState());
    identityRoles = identityRoleService.findAllByIdentity(testA.getId());
    Assert.assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with IdmIdentityRoleDto

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

the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesWithParameterAttachment.

@Test
@Transactional
public void testCopyRolesWithParameterAttachment() {
    long countBefore = attachmentManager.find(null).getTotalElements();
    String attributeCode = "attr-" + System.currentTimeMillis();
    // Prepare identity, role and parameters
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto role = getHelper().createRole();
    IdmFormAttributeDto attribute = new IdmFormAttributeDto(attributeCode);
    attribute.setPersistentType(PersistentType.ATTACHMENT);
    IdmFormDefinitionDto definition = formService.createDefinition(IdmIdentityRole.class, FormService.DEFAULT_DEFINITION_CODE, ImmutableList.of(attribute));
    role.setIdentityRoleAttributeDefinition(definition.getId());
    role = roleService.save(role);
    final IdmRoleDto roleFinal = role;
    definition.getFormAttributes().forEach(attr -> {
        roleFormAttributeService.addAttributeToSubdefintion(roleFinal, attr);
    });
    attribute = formService.getAttribute(definition, attributeCode);
    assertNotNull(attribute);
    IdmIdentityContractDto identityContact = getHelper().createContract(identity);
    IdmIdentityRoleDto identityRoleDto = this.getHelper().createIdentityRole(identityContact, role);
    // Add attachment to identity role
    String originalContent = "test-content-" + System.currentTimeMillis();
    IdmAttachmentDto attachment = prepareAttachment(originalContent);
    attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
    attachment = attachmentManager.saveAttachment(null, attachment);
    List<IdmFormInstanceDto> eavs = identityRoleDto.getEavs();
    IdmFormInstanceDto formInstanceDto = eavs.get(0);
    IdmFormValueDto newValue = new IdmFormValueDto(attribute);
    newValue.setShortTextValue(attachment.getName());
    newValue.setUuidValue(attachment.getId());
    formInstanceDto.setValues(Lists.newArrayList(newValue));
    identityRoleDto.setEavs(Lists.newArrayList(formInstanceDto));
    identityRoleDto = identityRoleService.save(identityRoleDto);
    IdmFormInstanceDto identityRoleValues = identityRoleService.getRoleAttributeValues(identityRoleDto);
    identityRoleValues = identityRoleService.getRoleAttributeValues(identityRoleDto);
    List<IdmFormValueDto> values = identityRoleValues.getValues();
    assertEquals(1, values.size());
    IdmFormValueDto originalValue = values.get(0);
    // Assign roles by identity
    IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
    List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
    List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
    IdmIdentityContractDto identityContractDto = getHelper().createContract(identityDto);
    IdmRoleRequestDto createdRequest = roleRequestService.createRequest(identityContractDto);
    IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
    requestByIdentityDto.setIdentityContract(identityContractDto.getId());
    requestByIdentityDto.setRoleRequest(createdRequest.getId());
    requestByIdentityDto.setIdentityRoles(identityRolesId);
    requestByIdentityDto.setCopyRoleParameters(true);
    IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
    List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
    assertEquals(1, concepts.size());
    IdmConceptRoleRequestDto concept = concepts.stream().filter(cntp -> {
        return cntp.getRole().equals(roleFinal.getId());
    }).findAny().orElse(null);
    assertNotNull(concept);
    IdmFormInstanceDto formInstance = conceptRoleRequestService.getRoleAttributeValues(concept, false);
    values = formInstance.getValues();
    assertEquals(1, values.size());
    IdmFormValueDto copyValue = values.get(0);
    assertEquals(originalValue.getPersistentType(), copyValue.getPersistentType());
    assertEquals(originalValue.getFormAttribute(), copyValue.getFormAttribute());
    assertNotEquals(originalValue.getUuidValue(), copyValue.getUuidValue());
    assertEquals(countBefore + 2, attachmentManager.find(null).getTotalElements());
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleRequestByIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with IdmIdentityRoleDto

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

the class DefaultIdmRoleRequestServiceIntegrationTest method testExecuteRoleRequestValueAsync.

@Test
public void testExecuteRoleRequestValueAsync() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto identityContact = getHelper().createContract(identity);
    IdmRoleDto role = createRoleWithAttributes(true);
    IdmFormDefinitionDto definition = formService.getDefinition(role.getIdentityRoleAttributeDefinition());
    IdmFormAttributeDto ipAttributeDto = // 
    definition.getFormAttributes().stream().filter(// 
    attribute -> IP.equals(attribute.getCode())).findFirst().get();
    // 
    try {
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
        // Add value
        IdmFormValueDto formValue = new IdmFormValueDto(ipAttributeDto);
        formValue.setStringValue(getHelper().createName());
        formValue.setPersistentType(PersistentType.TEXT);
        formValue.setFormAttribute(ipAttributeDto.getId());
        IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
        formInstance.setFormDefinition(definition);
        formInstance.getValues().add(formValue);
        // Create request
        IdmRoleRequestDto request = new IdmRoleRequestDto();
        request.setApplicant(identity.getId());
        request.setRequestedByType(RoleRequestedByType.MANUALLY);
        request.setExecuteImmediately(true);
        request = roleRequestService.save(request);
        // Create concept
        IdmConceptRoleRequestDto conceptRole = new IdmConceptRoleRequestDto();
        conceptRole.setIdentityContract(identityContact.getId());
        conceptRole.setRole(role.getId());
        conceptRole.setOperation(ConceptRoleRequestOperation.ADD);
        conceptRole.setRoleRequest(request.getId());
        conceptRole.getEavs().add(formInstance);
        conceptRole = conceptRoleRequestService.save(conceptRole);
        // Start request
        Map<String, Serializable> variables = new HashMap<>();
        variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.FALSE);
        RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, request, variables);
        event.setPriority(PriorityType.HIGH);
        // 
        request = roleRequestService.startRequest(event);
        UUID requestId = request.getId();
        getHelper().waitForResult(res -> {
            return roleRequestService.get(requestId).getState() != RoleRequestState.EXECUTED;
        }, 500, 50);
        IdmRoleRequestDto roleRequestDto = roleRequestService.get(request);
        assertEquals(RoleRequestState.EXECUTED, roleRequestDto.getState());
        conceptRole = conceptRoleRequestService.get(conceptRole.getId());
        assertEquals(RoleRequestState.EXECUTED, conceptRole.getState());
        IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
        identityRoleFilter.setIdentityContractId(identityContact.getId());
        List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
        assertEquals(1, identityRoles.size());
        IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
        IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRoleDto);
        assertNotNull(formInstanceDto);
        List<IdmFormValueDto> values = formInstanceDto.getValues();
        assertEquals(1, values.size());
        assertEquals(formValue.getValue(), values.get(0).getValue());
    } finally {
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
        // cleanup form definition
        getHelper().deleteIdentity(identity.getId());
        getHelper().deleteRole(role.getId());
        formService.deleteDefinition(definition);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) HashMap(java.util.HashMap) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)511 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)407 Test (org.junit.Test)401 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)400 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)282 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)280 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)151 UUID (java.util.UUID)146 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)113 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)113 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)111 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)109 List (java.util.List)108 Autowired (org.springframework.beans.factory.annotation.Autowired)107 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)101 Transactional (org.springframework.transaction.annotation.Transactional)94 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)92 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)89 LocalDate (java.time.LocalDate)87 Assert (org.junit.Assert)79