update loaduserbyusername

This commit is contained in:
Loredana Crusoveanu 2016-09-30 12:01:23 -04:00
parent d12d4e6ca5
commit a7340609b2
1 changed files with 3 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package org.baeldung.security; package org.baeldung.security;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import org.baeldung.persistence.model.MyUser; import org.baeldung.persistence.model.MyUser;
@ -27,11 +28,8 @@ public class MyUserDetailsService implements UserDetailsService {
if (user == null) { if (user == null) {
throw new UsernameNotFoundException("No user found with username: " + username); throw new UsernameNotFoundException("No user found with username: " + username);
} }
else { return new User(user.getUsername(), user.getPassword(), Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")));
final Collection<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
return new User(user.getUsername(), user.getPassword(), authorities);
}
} }
} }