Constructor injection user details

This commit is contained in:
Rohan Sircar 2020-05-27 17:09:15 +05:30
parent af024f4cef
commit 4a8e409539

View File

@ -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) {
@ -35,8 +37,7 @@ public class MyUserDetailsService implements UserDetailsService {
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();
}