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.stereotype.Service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class MyUserDetailsService implements UserDetailsService {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
private final UserService userService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(final String username) {
|
||||
@ -32,11 +34,10 @@ public class MyUserDetailsService implements UserDetailsService {
|
||||
}
|
||||
|
||||
Set<UserRole> userRoles = user.getUserRoles();
|
||||
|
||||
|
||||
return User.withUsername(user.getUserName())
|
||||
.password(user.getPassword())
|
||||
.roles(userRoles.stream()
|
||||
.map(ur -> ur.getRole().getName())
|
||||
.roles(userRoles.stream().map(ur -> ur.getRole().getName())
|
||||
.toArray(size -> new String[size]))
|
||||
.build();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user