Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.mm.MBlog.security.services;
- import org.mm.MBlog.security.models.User;
- import org.mm.MBlog.security.repository.UserRepository;
- 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;
- import org.springframework.transaction.annotation.Transactional;
- @Service
- public class UserDetailsServiceImpl implements UserDetailsService {
- @Autowired
- UserRepository userRepository;
- // @Transactional means that if we add something to a DB and its successfull it will be saved, if not successfull it will be roled back
- @Override
- @Transactional
- public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
- User user = userRepository.findByUsername(username).orElseThrow(() -> new UsernameNotFoundException("User Not Found with username: " + username));
- return UserDetailsImpl.build(user);
- }
- }
Add Comment
Please, Sign In to add comment