File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
src/main/java/com/example/ai_tutor/domain/auth/application Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 11package com .example .ai_tutor .domain .auth .application ;
22
33import com .example .ai_tutor .domain .auth .dto .TokenMapping ;
4+ import com .example .ai_tutor .domain .user .domain .User ;
45import com .example .ai_tutor .global .config .security .OAuth2Config ;
56import com .example .ai_tutor .global .config .security .token .UserPrincipal ;
67import io .jsonwebtoken .*;
@@ -122,8 +123,10 @@ public String getEmailFromToken(String token) {
122123
123124 public UsernamePasswordAuthenticationToken getAuthenticationByToken (String jwtToken ) {
124125 String email = getEmailFromToken (jwtToken );
125- UserDetails userDetails = customUserDetailsService .loadUserByUsername (email );
126- return new UsernamePasswordAuthenticationToken (userDetails , null , userDetails .getAuthorities ());
126+ User user = customUserDetailsService .getUserByEmail (email );
127+ UserPrincipal userPrincipal = UserPrincipal .create (user );
128+
129+ return new UsernamePasswordAuthenticationToken (userPrincipal , null , userPrincipal .getAuthorities ());
127130 }
128131
129132 public Long getExpiration (String token ) {
Original file line number Diff line number Diff line change 44import com .example .ai_tutor .domain .user .domain .repository .UserRepository ;
55import com .example .ai_tutor .global .DefaultAssert ;
66import com .example .ai_tutor .global .config .security .token .UserPrincipal ;
7- import jakarta .transaction .Transactional ;
87import lombok .RequiredArgsConstructor ;
98import lombok .extern .slf4j .Slf4j ;
109import org .springframework .security .core .userdetails .UserDetails ;
1110import org .springframework .security .core .userdetails .UserDetailsService ;
1211import org .springframework .security .core .userdetails .UsernameNotFoundException ;
1312import org .springframework .stereotype .Service ;
13+ import org .springframework .transaction .annotation .Transactional ;
1414
1515import java .util .Optional ;
1616
@@ -31,7 +31,13 @@ public UserDetails loadUserByUsername(String email) throws UsernameNotFoundExcep
3131 return UserPrincipal .create (user );
3232 }
3333
34- @ Transactional
34+ @ Transactional (readOnly = true )
35+ public User getUserByEmail (String email ) {
36+ return userRepository .findByEmail (email )
37+ .orElseThrow (() -> new UsernameNotFoundException ("유저 정보를 찾을 수 없습니다: " + email ));
38+ }
39+
40+ @ Transactional (readOnly = true )
3541 public UserDetails loadUserById (Long id ) {
3642 log .debug ("Trying to load user by ID: {}" , id );
3743 Optional <User > user = userRepository .findById (id );
You can’t perform that action at this time.
0 commit comments