Constructor injection user details
This commit is contained in:
parent
af024f4cef
commit
4a8e409539
@ -12,14 +12,16 @@ import org.springframework.security.core.userdetails.UserDetailsService;
|
|||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class MyUserDetailsService implements UserDetailsService {
|
public class MyUserDetailsService implements UserDetailsService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(final String username) {
|
public UserDetails loadUserByUsername(final String username) {
|
||||||
@ -35,8 +37,7 @@ public class MyUserDetailsService implements UserDetailsService {
|
|||||||
|
|
||||||
return User.withUsername(user.getUserName())
|
return User.withUsername(user.getUserName())
|
||||||
.password(user.getPassword())
|
.password(user.getPassword())
|
||||||
.roles(userRoles.stream()
|
.roles(userRoles.stream().map(ur -> ur.getRole().getName())
|
||||||
.map(ur -> ur.getRole().getName())
|
|
||||||
.toArray(size -> new String[size]))
|
.toArray(size -> new String[size]))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user