use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyService method enhancedControlForSimilar.
/**
* Method sets to which attribute of identity is similar to password - password validation
*
* @param passwordPolicy
* @param passwordValidationDto
* @param errors
* @return
*/
private Map<String, Object> enhancedControlForSimilar(IdmPasswordPolicyDto passwordPolicy, IdmPasswordValidationDto passwordValidationDto, Map<String, Object> errors) {
String password = passwordValidationDto.getPassword().asString();
if (passwordPolicy.isEnchancedControl()) {
String[] attributes = passwordPolicy.getIdentityAttributeCheck().split(", ");
IdmIdentityDto identity = passwordValidationDto.getIdentity();
for (int index = 0; index < attributes.length; index++) {
if (attributes[index].equals(IdmPasswordPolicyIdentityAttributes.EMAIL.name())) {
if (identity.getEmail() != null && identity.getEmail().toLowerCase().matches("(?i).*" + password.toLowerCase() + ".*")) {
errors.put(PASSWORD_SIMILAR_EMAIL, identity.getEmail());
}
} else if (attributes[index].equals(IdmPasswordPolicyIdentityAttributes.FIRSTNAME.name())) {
if (identity.getFirstName() != null && identity.getFirstName().toLowerCase().matches("(?i).*" + password.toLowerCase() + ".*")) {
errors.put(PASSWORD_SIMILAR_FIRSTNAME, identity.getFirstName());
}
} else if (attributes[index].equals(IdmPasswordPolicyIdentityAttributes.LASTNAME.name())) {
if (identity.getLastName() != null && identity.getLastName().toLowerCase().matches("(?i).*" + password.toLowerCase() + ".*")) {
errors.put(PASSWORD_SIMILAR_LASTNAME, identity.getLastName());
}
} else if (attributes[index].equals(IdmPasswordPolicyIdentityAttributes.USERNAME.name())) {
if (identity.getUsername() != null && identity.getUsername().toLowerCase().matches("(?i).*" + password.toLowerCase() + ".*")) {
errors.put(PASSWORD_SIMILAR_USERNAME, identity.getUsername());
}
}
}
}
return errors;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method startApprovalProcess.
@Override
@Transactional
public boolean startApprovalProcess(IdmRoleRequestDto request, boolean checkRight, EntityEvent<IdmRoleRequestDto> event, String wfDefinition) {
// and do realization immediately (without start approval process)
if (request.isExecuteImmediately()) {
boolean haveRightExecuteImmediately = securityService.hasAnyAuthority(CoreGroupPermission.ROLE_REQUEST_EXECUTE);
if (checkRight && !haveRightExecuteImmediately) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_NO_EXECUTE_IMMEDIATELY_RIGHT, ImmutableMap.of("new", request));
}
// All concepts in progress state will be set on approved (we can
// execute it immediately)
request.getConceptRoles().stream().filter(concept -> {
return RoleRequestState.IN_PROGRESS == concept.getState();
}).forEach(concept -> {
concept.setState(RoleRequestState.APPROVED);
conceptRoleRequestService.save(concept);
});
// Execute request immediately
return true;
} else {
IdmIdentityDto applicant = identityService.get(request.getApplicant());
Map<String, Object> variables = new HashMap<>();
// Minimize size of DTO persisting to WF
IdmRoleRequestDto eventRequest = event.getContent();
trimRequest(eventRequest);
eventRequest.setConceptRoles(null);
eventRequest.setOriginalRequest(null);
variables.put(EntityEvent.EVENT_PROPERTY, event);
ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinition, IdmIdentity.class.getSimpleName(), applicant.getUsername(), applicant.getId().toString(), variables);
// We have to refresh request (maybe was changed in wf process)
request = this.get(request.getId());
request.setWfProcessId(processInstance.getProcessInstanceId());
this.save(request);
}
return false;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class AbstractNotificationSender method send.
@Override
@Transactional
public List<N> send(String topic, IdmMessageDto message) {
Assert.notNull(securityService, "Security service is required for this operation");
Assert.notNull(topic, "Message topic can not be null.");
Assert.notNull(message, "Message can not be null.");
//
AbstractAuthentication auth = securityService.getAuthentication();
IdmIdentityDto currentIdentityDto = auth == null ? null : auth.getCurrentIdentity();
if (currentIdentityDto == null || currentIdentityDto.getId() == null) {
LOG.warn("No identity is currently signed, swallowing the message: [{}], parameters: [{}].", message.getTextMessage(), message.getParameters());
// system, guest, etc.
return null;
}
return send(topic, message, Lists.newArrayList(currentIdentityDto));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class AsynchronousAccountManagementIntegrationTest method testAsynchronousAccountManagementError.
@Test
public void testAsynchronousAccountManagementError() {
// add error to some script
SysSystemDto system = helper.createTestResourceSystem(true);
SysSystemMappingDto mapping = helper.getDefaultMapping(system);
SysSystemAttributeMappingDto attributeHandlingUserName = schemaAttributeHandlingService.findBySystemMappingAndName(mapping.getId(), TestHelper.ATTRIBUTE_MAPPING_NAME);
// username is transformed with error
attributeHandlingUserName.setTransformToResourceScript("returan \"" + "error" + "\";");
attributeHandlingUserName = schemaAttributeHandlingService.save(attributeHandlingUserName);
IdmIdentityDto identity = helper.createIdentity();
IdmRoleDto role = helper.createRole();
helper.createRoleSystem(role, system);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
try {
helper.waitForResult(res -> {
return !(entityEventService.findByState(configurationService.getInstanceId(), OperationState.CREATED).isEmpty() && entityEventService.findByState(configurationService.getInstanceId(), OperationState.RUNNING).isEmpty());
});
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNull(account);
//
// find event result with exception
IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
eventFilter.setOwnerId(identityRole.getId());
eventFilter.setStates(Lists.newArrayList(OperationState.EXCEPTION));
List<IdmEntityEventDto> failedEvents = entityEventService.find(eventFilter, null).getContent();
//
Assert.assertEquals(1, failedEvents.size());
Assert.assertEquals(CoreResultCode.GROOVY_SCRIPT_EXCEPTION.getCode(), failedEvents.get(0).getResult().getCode());
} finally {
identityService.delete(identity);
systemService.delete(system);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class AsynchronousAccountManagementIntegrationTest method testAsynchronousAccountManagementGreenLine.
@Test
public void testAsynchronousAccountManagementGreenLine() {
IdmIdentityDto identity = helper.createIdentity();
SysSystemDto system = helper.createTestResourceSystem(true);
IdmRoleDto role = helper.createRole();
helper.createRoleSystem(role, system);
helper.createIdentityRole(identity, role);
try {
helper.waitForResult(res -> {
return !(entityEventService.findByState(configurationService.getInstanceId(), OperationState.CREATED).isEmpty() && entityEventService.findByState(configurationService.getInstanceId(), OperationState.RUNNING).isEmpty());
});
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertNotNull(helper.findResource(account.getRealUid()));
} finally {
identityService.delete(identity);
systemService.delete(system);
}
}
Aggregations