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