Search in sources :

Example 1 with UserEntity

use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class PasswordResetTokenServiceImpl method resetPassword.

@Override
public void resetPassword(String userEmail) {
    UserEntity user = null;
    try {
        user = userRepository.findUserByEmail(userEmail).get();
    } catch (NoSuchElementException e) {
        throw new CustomParameterizedException(i18n.translate("email.emailUserNotFound"));
    } catch (Exception ex) {
        throw new CustomParameterizedException(i18n.translate("email.errorResetMail"));
    }
    if (user == null) {
        throw new CustomParameterizedException(i18n.translate("email.emailUserNotFound"));
    }
    String token = UUID.randomUUID().toString();
    createPasswordResetTokenForUser(user, token);
    SimpleMailMessage template = new SimpleMailMessage();
    template.setText(loadTemplate(applicationProps.getTemplates().getResetMail()));
    String[] args = { i18n.translate("email.bodyTitle"), i18n.translate("email.bodyGreeting"), applicationProps.getClient().getLoginUrl() + "?" + MAIL_PARAM_TOKEN + "=" + token + "&" + MAIL_PARAM_ID + "=" + user.getId(), i18n.translate("email.bodyReset", user.getEmail()), i18n.translate("email.bodySign") };
    emailService.sendSimpleMessageUsingTemplate(user.getEmail(), i18n.translate("email.resetPassword"), template, args);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity) NoSuchElementException(java.util.NoSuchElementException) NoSuchElementException(java.util.NoSuchElementException) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) IOException(java.io.IOException) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 2 with UserEntity

use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class UserDetailsServiceImpl method loadUserByUsername.

@Override
public UserDetailsDTO loadUserByUsername(String username) throws UsernameNotFoundException {
    LOG.info("Loading user details: {}", username);
    UserEntity user = userRepository.findOneByUsername(username).orElseThrow(() -> new UsernameNotFoundException("Username not found " + username));
    List<UserRoleEntity> roles = userRoleRepo.findByUser(user);
    UserApplicationEntity userApp = userApplicationRepo.findByUser(user).orElseGet(UserApplicationEntity::new);
    Optional<OrganizationEntity> organization = userApp.getOrganizationOpt();
    Optional<ApplicationEntity> application = userApp.getApplicationOpt();
    return UserDetailsDTO.builder().username(user.getUsername()).password(user.getPass()).enabled(user.isActive()).application(application.map(applicationMapper::entityToDto).orElse(null)).organization(organization.map(organizationMapper::entityToDto).orElse(null)).grantedAuthorities(this.getGrantedAuthorities(roles)).build();
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserRoleEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)

Example 3 with UserEntity

use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class UserServiceImpl method addUser.

@Override
public UserDTO addUser(UserDTO userDTO) {
    userRepository.findOneByUsername(userDTO.getUsername()).ifPresent(user -> {
        throw new CustomParameterizedException("User already exists.", new ImmutableMultimap.Builder<String, String>().put("username", user.getUsername()).build().asMap());
    });
    UserEntity user = new UserEntity();
    BeanUtils.copyProperties(userDTO, user);
    UserEntity newUser = userRepository.save(user);
    return userMapper.entityToDto(newUser);
}
Also used : CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)

Example 4 with UserEntity

use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotEconomicMapper method newSnapshotToEconomicEntity.

public SnapshotEconomicEntity newSnapshotToEconomicEntity(NewSnapshot snapshot, SnapshotIndicatorEntity indicator) {
    UserEntity user = null;
    TermCondPolEntity termCond = null;
    TermCondPolEntity privPol = null;
    if (snapshot.getUserName() != null) {
        user = userRepository.findOneByUsername(snapshot.getUserName()).get();
    }
    if (snapshot.getTermCondId() != null) {
        termCond = termCondPolRepository.findOne(snapshot.getTermCondId());
    }
    if (snapshot.getPrivPolId() != null) {
        privPol = termCondPolRepository.findOne(snapshot.getPrivPolId());
    }
    return new SnapshotEconomicEntity().surveyDefinition(new SurveyEntity(snapshot.getSurveyId())).surveyIndicator(indicator).staticProperties(snapshot.getMappedEconomicSurveyData(propertyAttributeSupport.staticEconomic(), propertyAttributeSupport::propertySchemaToSystemName)).additionalProperties(snapshot.getEconomicSurveyData(propertyAttributeSupport.additional())).user(user).termCond(termCond).privPol(privPol);
}
Also used : SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity) TermCondPolEntity(py.org.fundacionparaguaya.pspserver.security.entities.TermCondPolEntity)

Example 5 with UserEntity

use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotDraftServiceImpl method getSnapshotDraftByUser.

public List<SnapshotDraft> getSnapshotDraftByUser(UserDetailsDTO details, String familyName) {
    UserEntity user = userRepository.findOneByUsername(details.getUsername()).orElse(null);
    if (user == null) {
        return Collections.emptyList();
    }
    List<SnapshotDraftEntity> draftList = repository.findAll(where(userEquals(user.getId())).and(likeFamilyName(familyName)).and(createdAtLessDays(SNAPSHOT_DRAFT_MAX_DAY)));
    return mapper.entityListToDtoList(draftList);
}
Also used : SnapshotDraftEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)

Aggregations

UserEntity (py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)7 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)4 UnknownResourceException (py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 NoSuchElementException (java.util.NoSuchElementException)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)1 ApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)1 OrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity)1 UserApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)1 PasswordResetTokenEntity (py.org.fundacionparaguaya.pspserver.security.entities.PasswordResetTokenEntity)1 TermCondPolEntity (py.org.fundacionparaguaya.pspserver.security.entities.TermCondPolEntity)1 UserRoleEntity (py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity)1 SnapshotDraftEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity)1 SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)1 SurveyEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity)1