use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProcessor method savePassword.
/**
* Saves identity's password and fill valid till from password policy
*
* @param identity
* @param newPassword
*/
protected void savePassword(IdmIdentityDto identity, PasswordChangeDto passwordChangeDto) {
LOG.debug("Saving password for identity [{}].", identity.getUsername());
//
if (passwordChangeDto.getMaxPasswordAge() == null) {
IdmPasswordPolicyDto defaultValidatePolicy = passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.VALIDATE);
if (defaultValidatePolicy != null && defaultValidatePolicy.getMaxPasswordAge() != null) {
// put new valid till by default password policy
passwordChangeDto.setMaxPasswordAge(DateTime.now().plusDays(defaultValidatePolicy.getMaxPasswordAge()));
} else {
passwordChangeDto.setMaxPasswordAge(null);
LOG.warn("Default validate password policy not exists or max password age is not filled." + " For identity username [{}] will be valid till null.", identity.getUsername());
}
}
this.passwordService.save(identity, passwordChangeDto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class PasswordPolicySaveProcessor method process.
@Override
public EventResult<IdmPasswordPolicyDto> process(EntityEvent<IdmPasswordPolicyDto> event) {
IdmPasswordPolicyDto dto = event.getContent();
//
if (validatePasswordPolicyAttributes(dto)) {
if (dto.isDefaultPolicy()) {
this.passwordPolicyRepository.updateDefaultPolicyByType(dto.getType(), dto.getId());
}
} else {
throw new ResultCodeException(CoreResultCode.PASSWORD_POLICY_DEFAULT_TYPE, ImmutableMap.of("name", dto.getName()));
}
//
dto = passwordPolicyService.saveInternal(dto);
event.setContent(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class IdmPasswordPolicyController method validate.
/**
* Validate password by given password policy id
*
* @param backendId
* @return
*/
@RequestMapping(value = "/{backendId}/validate", method = RequestMethod.POST)
@ApiOperation(value = "Validate password", nickname = "validatePassword", response = IdmPasswordValidationDto.class, tags = { IdmPasswordPolicyController.TAG }, notes = "Validate password by password policy.")
public Resource<IdmPasswordValidationDto> validate(@ApiParam(value = "Policy's uuid identifier.", required = true) @PathVariable String backendId, @Valid @RequestBody(required = true) IdmPasswordValidationDto password) {
IdmPasswordPolicyDto passwordPolicy = getPasswordPolicy(backendId);
//
this.passwordPolicyService.validate(password, passwordPolicy);
//
password.setValid(true);
//
return new Resource<IdmPasswordValidationDto>(password);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class IdentityPasswordPreValidateDefinitionProcessor method validateDefinition.
public List<IdmPasswordPolicyDto> validateDefinition(PasswordChangeDto passwordChangeDto) {
List<IdmPasswordPolicyDto> passwordPolicyList = new ArrayList<>();
IdmPasswordPolicyDto defaultPasswordPolicy = this.passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.VALIDATE);
if (defaultPasswordPolicy == null) {
defaultPasswordPolicy = new IdmPasswordPolicyDto();
}
for (String account : passwordChangeDto.getAccounts()) {
SysSystemDto system = DtoUtils.getEmbedded(accountService.get(UUID.fromString(account)), AccAccount_.system, SysSystemDto.class);
IdmPasswordPolicyDto passwordPolicy;
//
if (system.getPasswordPolicyValidate() == null) {
passwordPolicy = defaultPasswordPolicy;
} else {
passwordPolicy = passwordPolicyService.get(system.getPasswordPolicyValidate());
}
if (!passwordPolicyList.contains(passwordPolicy) && passwordPolicy != null) {
passwordPolicyList.add(passwordPolicy);
}
}
if (passwordChangeDto.isIdm() && !passwordPolicyList.contains(defaultPasswordPolicy)) {
passwordPolicyList.add(defaultPasswordPolicy);
}
return passwordPolicyList;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto in project CzechIdMng by bcvsolutions.
the class IdentityPasswordValidateProcessor method validateDefinition.
/**
* Method returns password policy list for accounts
*
* @param identity
* @param passwordChangeDto
* @return
*/
public List<IdmPasswordPolicyDto> validateDefinition(IdmIdentityDto identity, PasswordChangeDto passwordChangeDto) {
List<IdmPasswordPolicyDto> passwordPolicyList = new ArrayList<>();
// Find user accounts
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(filter, null).getContent();
//
// get default password policy
IdmPasswordPolicyDto defaultPasswordPolicy = this.passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.VALIDATE);
//
if (passwordChangeDto.isIdm() && defaultPasswordPolicy != null) {
passwordPolicyList.add(defaultPasswordPolicy);
}
//
// get systems, only ownership
identityAccounts.stream().filter(identityAccount -> {
return identityAccount.isOwnership() && (passwordChangeDto.isAll() || passwordChangeDto.getAccounts().contains(identityAccount.getAccount().toString()));
}).forEach(identityAccount -> {
// get validate password policy from system
// TODO: change to DTO after refactoring
IdmPasswordPolicy passwordPolicyEntity = identityAccountRepository.findOne(identityAccount.getId()).getAccount().getSystem().getPasswordPolicyValidate();
IdmPasswordPolicyDto passwordPolicy = null;
if (passwordPolicyEntity != null) {
passwordPolicy = passwordPolicyService.get(passwordPolicyEntity.getId());
}
// validate
if (passwordPolicy == null) {
passwordPolicy = defaultPasswordPolicy;
}
if (!passwordPolicyList.contains(passwordPolicy) && passwordPolicy != null) {
passwordPolicyList.add(passwordPolicy);
}
});
return passwordPolicyList;
}
Aggregations