Is it possible to port this fragment of code from Java 8 to Java 7?
protected UserDetailsService userDetailsService() {
return (username) -> {
User u = crmService.findUserByUsername(username);
return new org.springframework.security.core.userdetails.User(
u.getUsername(), u.getPassword(), u.isEnabled(),
u.isEnabled(), u.isEnabled(), u.isEnabled(),
AuthorityUtils.createAuthorityList("USER", "write"));
};
}
You can do it in such way:
protected UserDetailsService userDetailsService() {
return new UserDetailsService() {
@Override
UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User u = crmService.findUserByUsername(username);
return new org.springframework.security.core.userdetails.User(
u.getUsername(), u.getPassword(), u.isEnabled(),
u.isEnabled(), u.isEnabled(), u.isEnabled(),
AuthorityUtils.createAuthorityList("USER", "write"));
}
}
}
But definitely you should think about extracting it to normal class and just returning new object there
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With