package org.fjorum.model.service;

import org.fjorum.model.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
public class CurrentUserDetailsService implements UserDetailsService {
    private final UserService userService;

    @Autowired
    public CurrentUserDetailsService(UserService userService) {
        this.userService = userService;
    }

    @Override
    @Transactional
    public CurrentUser loadUserByUsername(String nameOrEmail) throws UsernameNotFoundException {
        User user = userService.getUserByNameOrEmail(nameOrEmail)
                .orElseThrow(() ->
                        new UsernameNotFoundException(String.format(
                                "User with name or email '%s' was not found", nameOrEmail)));
        return new CurrentUser(user);
    }
}
@@ -332,21 +332,34 @@
 ce;%0A
-%0A
 import 
-javax
+org.springframework
 .tra
@@ -367,16 +367,27 @@
 saction.
+annotation.
 Transact
@@ -394,16 +394,17 @@
 ional;%0A%0A
+%0A
 @Service
@@ -677,16 +677,33 @@
 actional
+(readOnly = true)
 %0A    pub

use readonly transaction