Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revise the user concept #39

Open
th-schwarz opened this issue Jun 22, 2024 · 1 comment
Open

revise the user concept #39

th-schwarz opened this issue Jun 22, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@th-schwarz
Copy link
Owner

th-schwarz commented Jun 22, 2024

  • introduce an user
  • each user can have one or more hosts, this should be respected at the log view
  • the api-token should be removed
@th-schwarz th-schwarz changed the title user-based hosts revise the user concept Jun 22, 2024
@th-schwarz th-schwarz added the enhancement New feature or request label Jun 22, 2024
@th-schwarz th-schwarz self-assigned this Jun 22, 2024
@th-schwarz
Copy link
Owner Author

th-schwarz commented Jun 22, 2024

@Service
public class CustomUserDetailsService implements UserDetailsService {

    private UserRepository userRepository;

    public CustomUserDetailsService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
        User user = userRepository.findByEmail(email);

        if (user != null) {
            return new org.springframework.security.core.userdetails.User(user.getEmail(),
                    user.getPassword(),
                    mapRolesToAuthorities(user.getRoles()));
        }else{
            throw new UsernameNotFoundException("Invalid username or password.");
        }
    }

    private Collection < ? extends GrantedAuthority> mapRolesToAuthorities(Collection <Role> roles) {
        Collection < ? extends GrantedAuthority> mapRoles = roles.stream()
                .map(role -> new SimpleGrantedAuthority(role.getName()))
                .collect(Collectors.toList());
        return mapRoles;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant