|
Last change
on this file was 5ea00d7, checked in by Malek Alavi <malekalavi7@…>, 7 days ago |
|
Initial project upload
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | package mk.ukim.finki.wp.db.service;
|
|---|
| 2 |
|
|---|
| 3 | import lombok.RequiredArgsConstructor;
|
|---|
| 4 | import mk.ukim.finki.wp.db.entity.user.UserEntity;
|
|---|
| 5 | import mk.ukim.finki.wp.db.repository.UserEntityRepository;
|
|---|
| 6 | import org.springframework.security.core.userdetails.*;
|
|---|
| 7 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|---|
| 8 | import org.springframework.stereotype.Service;
|
|---|
| 9 |
|
|---|
| 10 | import java.util.List;
|
|---|
| 11 |
|
|---|
| 12 | @Service
|
|---|
| 13 | @RequiredArgsConstructor
|
|---|
| 14 | public class CustomUserDetailsService implements UserDetailsService {
|
|---|
| 15 |
|
|---|
| 16 | private final UserEntityRepository userEntityRepository;
|
|---|
| 17 |
|
|---|
| 18 | @Override
|
|---|
| 19 | public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
|
|---|
| 20 |
|
|---|
| 21 | UserEntity user = userEntityRepository
|
|---|
| 22 | .findByEmail(email)
|
|---|
| 23 | .orElseThrow(() -> new UsernameNotFoundException("User not found: " + email));
|
|---|
| 24 |
|
|---|
| 25 | return new org.springframework.security.core.userdetails.User(
|
|---|
| 26 | user.getEmail(),
|
|---|
| 27 | user.getPassword(),
|
|---|
| 28 | List.of(new SimpleGrantedAuthority("ROLE_" + user.getRole().name()))
|
|---|
| 29 | );
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.