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);
}
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();
}
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);
}
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);
}
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();
}
}
Aggregations