Search in sources :

Example 1 with IdmPasswordPolicyDto

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);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)

Example 2 with IdmPasswordPolicyDto

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);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 3 with IdmPasswordPolicyDto

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);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) Resource(org.springframework.hateoas.Resource) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with IdmPasswordPolicyDto

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;
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) ArrayList(java.util.ArrayList) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 5 with IdmPasswordPolicyDto

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;
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) ProvisioningEvent(eu.bcvsolutions.idm.acc.event.ProvisioningEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) Enabled(eu.bcvsolutions.idm.core.security.api.domain.Enabled) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmPasswordService(eu.bcvsolutions.idm.core.api.service.IdmPasswordService) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) ArrayList(java.util.ArrayList) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdentityEventType(eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdentityProcessor(eu.bcvsolutions.idm.core.api.event.processor.IdentityProcessor) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) Description(org.springframework.context.annotation.Description) AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) PasswordChangeType(eu.bcvsolutions.idm.core.api.domain.PasswordChangeType) AccIdentityAccountRepository(eu.bcvsolutions.idm.acc.repository.AccIdentityAccountRepository) IdmPasswordPolicyType(eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyType) IdentityPasswordProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentityPasswordProcessor) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) IdmPasswordPolicy(eu.bcvsolutions.idm.core.model.entity.IdmPasswordPolicy) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) IdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.IdentityConfiguration) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) Assert(org.springframework.util.Assert) IdmPasswordPolicyService(eu.bcvsolutions.idm.core.api.service.IdmPasswordPolicyService) IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordPolicy(eu.bcvsolutions.idm.core.model.entity.IdmPasswordPolicy) ArrayList(java.util.ArrayList) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)

Aggregations

IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)49 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)33 Test (org.junit.Test)33 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)13 ArrayList (java.util.ArrayList)11 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)9 IdmPasswordValidationDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto)9 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)8 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)7 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)6 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)6 HashMap (java.util.HashMap)4 Map (java.util.Map)3 AccModuleDescriptor (eu.bcvsolutions.idm.acc.AccModuleDescriptor)2 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)2 SysSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter)2 ProvisioningEvent (eu.bcvsolutions.idm.acc.event.ProvisioningEvent)2 AccIdentityAccountRepository (eu.bcvsolutions.idm.acc.repository.AccIdentityAccountRepository)2