Search in sources :

Example 1 with UserRoleEntity

use of py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity 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 2 with UserRoleEntity

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

the class UserRoleServiceImpl method addUserRole.

@Override
public UserRoleDTO addUserRole(UserRoleDTO userRoleDTO) {
    UserRoleEntity userRole = new UserRoleEntity();
    BeanUtils.copyProperties(userRoleDTO, userRole);
    UserRoleEntity newUserRole = userRoleRepository.save(userRole);
    return userRoleMapper.entityToDto(newUserRole);
}
Also used : UserRoleEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity)

Example 3 with UserRoleEntity

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

the class UserServiceImpl method createUserRole.

private UserRoleEntity createUserRole(UserEntity user, Role role) {
    UserRoleEntity userRole = new UserRoleEntity();
    userRole.setUser(user);
    userRole.setRole(role);
    return userRoleRepository.save(userRole);
}
Also used : UserRoleEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity)

Aggregations

UserRoleEntity (py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity)3 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)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 UserEntity (py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)1