Search in sources :

Example 6 with IdmIdentityContractDto

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

the class IdentityContractAutomaticRoleProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto identityContract = event.getContent();
    UUID contractId = identityContract.getId();
    // 
    AutomaticRoleAttributeRuleType type = AutomaticRoleAttributeRuleType.CONTRACT;
    // get original event type
    if (CoreEventType.EAV_SAVE.name().equals(event.getProperties().get(EntityEventManager.EVENT_PROPERTY_PARENT_EVENT_TYPE))) {
        type = AutomaticRoleAttributeRuleType.CONTRACT_EAV;
    }
    // 
    // resolve automatic role by attribute
    Set<AbstractIdmAutomaticRoleDto> allNewPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(true, type, contractId);
    Set<AbstractIdmAutomaticRoleDto> allNotPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(false, type, contractId);
    automaticRoleAttributeService.processAutomaticRolesForContract(contractId, allNewPassedAutomaticRoleForContract, allNotPassedAutomaticRoleForContract);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) UUID(java.util.UUID) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 7 with IdmIdentityContractDto

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

the class IdentityContractExclusionProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    if (!StringUtils.isEmpty(getWorkflowDefinitionKey())) {
        // wf is configured - execute wf instance
        return super.process(event);
    }
    // 
    IdmIdentityContractDto contract = event.getContent();
    OperationResult result = process(contract, (Boolean) event.getProperties().get(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION));
    return new DefaultEventResult.Builder<>(event, this).setResult(result).build();
}
Also used : OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 8 with IdmIdentityContractDto

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

the class IdentityContractSaveProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto contract = event.getContent();
    contract = service.saveInternal(contract);
    event.setContent(contract);
    // 
    // check identity state
    IdmIdentityContractDto previousContract = event.getOriginalSource();
    IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity.getName(), IdmIdentityDto.class);
    if ((identity.getState() == IdentityState.CREATED || identity.isDisabled()) && contractChanged(previousContract, contract)) {
        // synchronize identity states, which has no effect on HR processes
        identity = identityService.get(contract.getIdentity());
        IdentityState newState = identityService.evaluateState(identity.getId());
        if (newState.isDisabled() && identity.getState() != newState) {
            identity.setState(newState);
            // publish new save event for identity with skip recalculation
            IdentityEvent identityEvent = new IdentityEvent(IdentityEventType.UPDATE, identity);
            identityEvent.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, true);
            identityService.publish(identityEvent);
        }
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Example 9 with IdmIdentityContractDto

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

the class IdentityAutomaticRoleProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    // 
    IdmIdentityDto identity = event.getContent();
    UUID identityId = identity.getId();
    // 
    AutomaticRoleAttributeRuleType type = AutomaticRoleAttributeRuleType.IDENTITY;
    if (CoreEventType.EAV_SAVE.name().equals(event.getProperties().get(EntityEventManager.EVENT_PROPERTY_PARENT_EVENT_TYPE))) {
        type = AutomaticRoleAttributeRuleType.IDENTITY_EAV;
    }
    // 
    for (IdmIdentityContractDto contract : identityContractService.findAllByIdentity(identityId)) {
        UUID contractId = contract.getId();
        Set<AbstractIdmAutomaticRoleDto> allNewPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(true, type, contractId);
        Set<AbstractIdmAutomaticRoleDto> allNotPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(false, type, contractId);
        automaticRoleAttributeService.processAutomaticRolesForContract(contractId, allNewPassedAutomaticRoleForContract, allNotPassedAutomaticRoleForContract);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 10 with IdmIdentityContractDto

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

the class InitApplicationData method init.

protected void init() {
    securityService.setSystemAuthentication();
    // 
    try {
        // prepare default form definitions
        if (formService.getDefinition(IdmIdentity.class) == null) {
            formService.createDefinition(IdmIdentity.class, new ArrayList<>());
        }
        if (formService.getDefinition(IdmRole.class) == null) {
            formService.createDefinition(IdmRole.class, new ArrayList<>());
        }
        if (formService.getDefinition(IdmTreeNode.class) == null) {
            formService.createDefinition(IdmTreeNode.class, new ArrayList<>());
        }
        if (formService.getDefinition(IdmIdentityContract.class) == null) {
            formService.createDefinition(IdmIdentityContract.class, new ArrayList<>());
        }
        // 
        // create super admin role
        IdmRoleDto existsSuperAdminRole = this.roleService.getByCode(ADMIN_ROLE);
        if (existsSuperAdminRole == null && this.roleService.find(new PageRequest(0, 1)).getTotalElements() == 0) {
            // 
            final IdmRoleDto superAdminRole = new IdmRoleDto();
            superAdminRole.setName(ADMIN_ROLE);
            superAdminRole.setRoleType(RoleType.SYSTEM);
            existsSuperAdminRole = this.roleService.save(superAdminRole);
            // super admin authorization policy
            IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
            policy.setGroupPermission(IdmGroupPermission.APP.getName());
            policy.setPermissions(IdmBasePermission.ADMIN);
            policy.setRole(existsSuperAdminRole.getId());
            policy.setEvaluator(BasePermissionEvaluator.class);
            authorizationPolicyService.save(policy);
            // 
            LOG.info(MessageFormat.format("Super admin Role created [id: {0}]", superAdminRole.getId()));
        }
        // 
        // create super admin
        IdmIdentityDto existsSuperAdmin = this.identityService.getByUsername(ADMIN_USERNAME);
        if (existsSuperAdmin == null || this.identityService.find(new PageRequest(0, 1)).getTotalElements() == 0) {
            // 
            IdmIdentityDto identityAdmin = new IdmIdentityDto();
            identityAdmin.setUsername(ADMIN_USERNAME);
            identityAdmin.setPassword(new GuardedString(ADMIN_PASSWORD));
            identityAdmin.setLastName("Administrator");
            identityAdmin = this.identityService.save(identityAdmin);
            LOG.info(MessageFormat.format("Super admin identity created [id: {0}]", identityAdmin.getId()));
            // 
            // create prime contract
            IdmIdentityContractDto contract = identityContractService.getPrimeContract(identityAdmin.getId());
            if (contract == null) {
                contract = identityContractService.prepareMainContract(identityAdmin.getId());
                contract = identityContractService.save(contract);
            }
            // 
            // assign super admin role
            IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
            identityRole.setIdentityContract(contract.getId());
            identityRole.setRole(existsSuperAdminRole.getId());
            identityRoleService.save(identityRole);
        }
        // 
        // create Node type for organization
        IdmTreeTypeDto treeType = treeTypeService.getByCode(DEFAULT_TREE_TYPE);
        if (treeType == null && this.treeTypeService.find(new PageRequest(0, 1)).getTotalElements() == 0) {
            treeType = new IdmTreeTypeDto();
            treeType.setCode(DEFAULT_TREE_TYPE);
            treeType.setName("Organization structure");
            treeType = this.treeTypeService.save(treeType);
            treeConfiguration.setDefaultType(treeType.getId());
            // create organization root
            if (treeNodeService.findRoots(treeType.getId(), new PageRequest(0, 1)).getTotalElements() == 0) {
                IdmTreeNodeDto organizationRoot = new IdmTreeNodeDto();
                organizationRoot.setCode("root");
                organizationRoot.setName("Root organization");
                organizationRoot.setTreeType(treeType.getId());
                organizationRoot = this.treeNodeService.save(organizationRoot);
            }
        }
        // 
        // initial missing scripts, current scripts isn't redploy
        scriptService.init();
        // save only missing templates, current templates is not redeploys
        notificationTemplateService.init();
        // 
        // init notification configuration, initialization topic need exists system templates!
        notificationConfigurationService.initDefaultTopics();
        // 
        // Cancels all previously ran tasks
        longRunningTaskManager.init();
        // 
        // Cancels all previously ran events
        entityEventManager.init();
    } finally {
        SecurityContextHolder.clearContext();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) PageRequest(org.springframework.data.domain.PageRequest) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)

Aggregations

IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)220 Test (org.junit.Test)170 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)156 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)92 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)91 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)53 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)48 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)45 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)36 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)35 LocalDate (org.joda.time.LocalDate)34 ArrayList (java.util.ArrayList)31 List (java.util.List)29 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)28 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)24 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)24 Transactional (org.springframework.transaction.annotation.Transactional)24 UUID (java.util.UUID)19 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)18