-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuserdetails.java
More file actions
executable file
·37 lines (29 loc) · 1.15 KB
/
userdetails.java
File metadata and controls
executable file
·37 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);
@Autowired
private UserRepository userRepository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepository.findByUsername(username).orElse(null);
if (user == null) {
String message = "Username not found: " + username;
log.info(message);
throw new UsernameNotFoundException(message);
}
List<GrantedAuthority> authorities = user.getRole().getPermissions()
.stream()
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
return new org.springframework.security.core.userdetails.User(
username,
user.getPasswordDigest(),
user.getEnabled(),
true, //Account Not Expired
true, //Credentials Not Expired
true, //Account Not Locked
authorities
) {
};
}
}