Search in sources :

Example 71 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class EntityStateSaveProcessor method process.

@Override
public EventResult<IdmEntityStateDto> process(EntityEvent<IdmEntityStateDto> event) {
    IdmEntityStateDto entity = event.getContent();
    entity = service.saveInternal(entity);
    event.setContent(entity);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 72 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class AbstractIdentityPasswordValidateProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto identity = event.getContent();
    PasswordChangeDto passwordChangeDto = (PasswordChangeDto) event.getProperties().get(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO);
    Assert.notNull(passwordChangeDto);
    // 
    if (requiresOriginalPassword()) {
        PasswordChangeType passwordChangeType = identityConfiguration.getPasswordChangeType();
        if (passwordChangeType == PasswordChangeType.DISABLED) {
            // check if isn't disable password change
            throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_DISABLED);
        } else if (passwordChangeType == PasswordChangeType.ALL_ONLY && !passwordChangeDto.isAll()) {
            // for all only must change also password for czechidm
            throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_ALL_ONLY);
        }
        // checkAccess(identity, IdentityBasePermission.PASSWORDCHANGE) is called before event publishing
        if (identity.getId().equals(securityService.getCurrentId()) && identityConfiguration.isRequireOldPassword()) {
            if (passwordChangeDto.getOldPassword() == null) {
                throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_CURRENT_FAILED_IDM);
            }
            // authentication trough chain
            boolean successChainAuthentication = authenticationManager.validate(identity.getUsername(), passwordChangeDto.getOldPassword());
            if (!successChainAuthentication) {
                throw new ResultCodeException(CoreResultCode.PASSWORD_CHANGE_CURRENT_FAILED_IDM);
            }
        }
    }
    if (passwordChangeDto.isAll() || passwordChangeDto.isIdm()) {
        // change identity's password
        // validate password
        IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
        // set old password for validation - valid till, from and history check
        IdmPasswordDto oldPassword = this.passwordService.findOneByIdentity(identity.getId());
        passwordValidationDto.setOldPassword(oldPassword == null ? null : oldPassword.getId());
        passwordValidationDto.setPassword(passwordChangeDto.getNewPassword());
        passwordValidationDto.setIdentity(identity);
        this.passwordPolicyService.validate(passwordValidationDto);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : PasswordChangeType(eu.bcvsolutions.idm.core.api.domain.PasswordChangeType) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 73 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class IdentityCreatePasswordValidateProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    GuardedString password = event.getContent().getPassword();
    IdmIdentityDto identity = event.getContent();
    // when create identity password can be null
    if (password != null) {
        IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
        passwordValidationDto.setPassword(password);
        passwordValidationDto.setIdentity(identity);
        // validate create new password by default password policy
        this.passwordPolicyService.validate(passwordValidationDto);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 74 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class IdentityPasswordChangeNotificationProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto identity = event.getContent();
    List<EventResult<IdmIdentityDto>> results = event.getContext().getResults();
    // 
    List<IdmAccountDto> successAccounts = new ArrayList<>();
    List<OperationResult> failureResults = new ArrayList<>();
    List<String> systemNames = new ArrayList<>();
    for (EventResult<IdmIdentityDto> eventResult : results) {
        eventResult.getResults().forEach(result -> {
            if (result.getModel() != null) {
                boolean success = result.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name());
                if (success) {
                    IdmAccountDto account = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
                    systemNames.add(account.getSystemName());
                    successAccounts.add(account);
                } else {
                    // exception is logged before
                    failureResults.add(result);
                }
            }
        });
    }
    // send notification if at least one system success
    if (!successAccounts.isEmpty()) {
        notificationManager.send(CoreModuleDescriptor.TOPIC_PASSWORD_CHANGED, new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).addParameter("successSystemNames", StringUtils.join(systemNames, ", ")).addParameter("successAccounts", successAccounts).addParameter("failureResults", failureResults).addParameter("name", identityService.getNiceLabel(identity)).addParameter("username", identity.getUsername()).build(), identity);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : ArrayList(java.util.ArrayList) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 75 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class IdentityPasswordExpiredProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto identity = event.getContent();
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    // 
    LOG.info("Sending warning notification to identity [{}], password expired in [{}]", identity.getUsername(), password.getValidTill());
    DateTimeFormatter dateFormat = DateTimeFormat.forPattern(getConfigurationService().getDateFormat());
    // 
    notificationManager.send(CoreModuleDescriptor.TOPIC_PASSWORD_EXPIRED, new IdmMessageDto.Builder(NotificationLevel.WARNING).addParameter("expiration", dateFormat.print(password.getValidTill())).addParameter("identity", identity).build(), identity);
    return new DefaultEventResult<>(event, this);
}
Also used : IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Aggregations

DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)91 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)12 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)11 UUID (java.util.UUID)11 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)10 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)7 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)7 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)6 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)5 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)5 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)5 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)5 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)5 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)4 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)4 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)4 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)4 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)4 ArrayList (java.util.ArrayList)4