Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Odilio
Last active October 20, 2020 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Odilio/d38f5aeec867a15566e71159e84000c6 to your computer and use it in GitHub Desktop.
Save Odilio/d38f5aeec867a15566e71159e84000c6 to your computer and use it in GitHub Desktop.
package com.bootstrap.springboot.service;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@Service
public class JwtUserDetailsService implements UserDetailsService {
@Autowired
private UserService userService;
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
com.bootstrap.springboot.model.User user = userService.getByEmail(email);
if (user.getEmail().equals(email)) {
return new User(email, user.getPassword(),
new ArrayList<>());
} else {
throw new UsernameNotFoundException("User not found with email: " + email);
}
}
}
@m-assila
Copy link

m-assila commented Oct 2, 2019

why exactly : "$2a$10$slYQmyNdGzTn7ZLBXBChFOC9f6kFjAqPhccnP6DxlWXx2lPk1C3G6" ?

@Odilio
Copy link
Author

Odilio commented Oct 3, 2019

Because in this example I am not using the database so I simulated the repository bringing an encrypted password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment