Skip to content

Commit

Permalink
[feat #191] 인증/인가 문제 확인을 위한 에러 로그 임시 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dudxo committed Jan 14, 2025
1 parent 840810d commit 7403763
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.gongmuin.security.handler;

import java.io.IOException;
import java.util.Arrays;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
Expand All @@ -20,6 +21,7 @@ public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException {

log.error("비인가 사용자 요청 -> 예외 발생 : {}", authException.getMessage());
log.error(Arrays.toString(authException.getStackTrace()));

response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); // 401 Unauthorized
response.setContentType("application/json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Component
@RequiredArgsConstructor
@Slf4j
public class CustomOauth2SuccessHandler implements AuthenticationSuccessHandler {

private final MemberRepository memberRepository;
Expand All @@ -37,15 +39,20 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
Authentication authentication) throws IOException {

CustomOauth2User customOauth2User = (CustomOauth2User)authentication.getPrincipal();
log.error("CustomOauth2User = ", customOauth2User.getEmail());

String socialEmail = customOauth2User.getEmail();
Member findmember = memberRepository.findBySocialEmail(socialEmail)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.NOT_FOUND_MEMBER));

log.error("findmember = ", findmember.toString());

String token = tokenProvider.generateAccessToken(findmember, customOauth2User, new Date());
tokenProvider.generateRefreshToken(findmember, customOauth2User, new Date());

log.error("token = ", token);
response.addCookie(cookieUtil.createCookie(token));
log.error("response = ", response.getHeader("Set-Cookie"));

if (isRoleGuest(findmember.getRole())) {
response.sendRedirect(REDIRECTION_SIGNUP);
Expand Down

0 comments on commit 7403763

Please sign in to comment.