Last active
October 20, 2020 01:40
-
-
Save Odilio/d38f5aeec867a15566e71159e84000c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because in this example I am not using the database so I simulated the repository bringing an encrypted password