use of eu.bcvsolutions.idm.core.model.entity.IdmPasswordPolicy 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;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmPasswordPolicy in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordPolicyService method save.
@Override
@Transactional
public IdmPasswordPolicyDto save(IdmPasswordPolicyDto dto, BasePermission... permission) {
Assert.notNull(dto);
//
if (!ObjectUtils.isEmpty(permission)) {
IdmPasswordPolicy persistEntity = null;
if (dto.getId() != null) {
persistEntity = this.getEntity(dto.getId());
if (persistEntity != null) {
// check access on previous entity - update is needed
checkAccess(persistEntity, IdmBasePermission.UPDATE);
}
}
// TODO: remove one checkAccess?
checkAccess(toEntity(dto, persistEntity), permission);
}
//
LOG.debug("Saving entity [{}]", dto.getName());
if (isNew(dto)) {
// throw event with create
return entityEventProcessorService.process(new PasswordPolicyEvent(PasswordPolicyEvenType.CREATE, dto)).getContent();
}
// else throw event with update
return entityEventProcessorService.process(new PasswordPolicyEvent(PasswordPolicyEvenType.UPDATE, dto)).getContent();
}
Aggregations