forked from dlizarra/spring-angular2-cli-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomUserDetailsService.java
More file actions
27 lines (19 loc) · 909 Bytes
/
CustomUserDetailsService.java
File metadata and controls
27 lines (19 loc) · 909 Bytes
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
package com.dlizarra.starter.support.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import com.dlizarra.starter.user.User;
import com.dlizarra.starter.user.UserRepository;
@Service
public class CustomUserDetailsService implements UserDetailsService {
@Autowired
private UserRepository userRepository;
@Override
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
final User user = userRepository.findByUsername(username)
.orElseThrow(() -> new UsernameNotFoundException("Username " + username + " not found."));
return new CustomUserDetails(user);
}
}