package com.nmuzychuk.blog.services;

import com.nmuzychuk.blog.model.User;
import com.nmuzychuk.blog.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 java.util.Collections;

/**
 * Service which loads user-specific data.
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userRepository.findByUsername(username);

        if (user != null) {
            return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(),
                    Collections.emptyList());
        } else {
            throw new UsernameNotFoundException(String.format("Could not find user %s", username));
        }
    }

}

@@ -620,32 +620,137 @@
     
-@Autowired%0A    private U
+private UserRepository userRepository;%0A%0A    @Autowired%0A    UserDetailsServiceImpl(UserRepository userRepository) %7B%0A        this.u
 serR
@@ -750,32 +750,34 @@
 s.userRepository
+ =
  userRepository;
@@ -772,24 +772,30 @@
 rRepository;
+%0A    %7D
 %0A%0A    @Overr

Fix UserRepository injection