|
@@ -1,10 +1,6 @@
|
|
|
package es.uv.garcosda.security;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.security.core.GrantedAuthority;
|
|
|
-import org.springframework.security.core.authority.AuthorityUtils;
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
@@ -27,19 +23,6 @@ public class CustomUserDetailsService implements UserDetailsService {
|
|
|
throws UsernameNotFoundException {
|
|
|
User user = userRepository.findByUsername(userName)
|
|
|
.orElseThrow(() -> new UsernameNotFoundException("User "+userName+" not found"));
|
|
|
- return new org.springframework.security.core.userdetails.User(
|
|
|
- user.getUsername(),
|
|
|
- user.getPassword(),
|
|
|
- getAuthorities(user));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private static Collection<? extends GrantedAuthority> getAuthorities(User user) {
|
|
|
- String[] userRoles = user.getRoles()
|
|
|
- .stream()
|
|
|
- .map((role) -> role.getName())
|
|
|
- .toArray(String[]::new);
|
|
|
- Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(userRoles);
|
|
|
- return authorities;
|
|
|
+ return new AuthUser(user);
|
|
|
}
|
|
|
}
|