Skip to content

Instantly share code, notes, and snippets.

@rajj6
Created February 6, 2021 16:36
Show Gist options
  • Save rajj6/47a94e51431240b1228343045fb44e39 to your computer and use it in GitHub Desktop.
Save rajj6/47a94e51431240b1228343045fb44e39 to your computer and use it in GitHub Desktop.
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