File tree Expand file tree Collapse file tree
src/main/java/com/dev/springdemo/auth/user Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .dev .springdemo .auth .user ;
22
3+ import lombok .extern .log4j .Log4j2 ;
34import org .springframework .beans .factory .annotation .Autowired ;
5+ import org .springframework .cache .annotation .CacheConfig ;
6+ import org .springframework .cache .annotation .Cacheable ;
47import org .springframework .security .core .userdetails .UserDetails ;
58import org .springframework .security .core .userdetails .UserDetailsService ;
69import org .springframework .security .core .userdetails .UsernameNotFoundException ;
912import java .util .Optional ;
1013
1114@ Service
15+ @ CacheConfig (cacheNames = "users" )
16+ @ Log4j2
1217public class UserService implements UserDetailsService {
1318
1419 @ Autowired
1520 private UserRepository userRepository ;
1621
1722
1823 @ Override
24+ @ Cacheable (condition = "#result?.id" )
1925 public UserDetails loadUserByUsername (String username ) throws UsernameNotFoundException {
26+ log .info ("Fetching user details for {}" , username );
2027 Optional <User > userByEmail = userRepository .findUserByEmail (username );
2128 return userByEmail .orElseThrow (() -> new UsernameNotFoundException ("User not found." ));
2229 }
You can’t perform that action at this time.
0 commit comments