Created
February 6, 2021 16:36
-
-
Save rajj6/47a94e51431240b1228343045fb44e39 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.raj.service; | |
import com.raj.model.User; | |
import com.raj.repository.UserRepository; | |
import com.raj.securingweb.UserPrincipal; | |
import org.springframework.beans.factory.annotation.Autowired; | |
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 MyUserDetailsService implements UserDetailsService { | |
@Autowired | |
private UserRepository userRepository; | |
@Override | |
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { | |
User user = userRepository.findByEmail(email); | |
if( user == null) { | |
throw new UsernameNotFoundException("User Not found 404"); | |
} | |
return new UserPrincipal(user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment