Skip to content

Commit

Permalink
feat: OAuth2AuthorizationRequest 객체에 대한 에러 관련 로깅 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bflykky committed Jul 31, 2024
1 parent db874d3 commit cc6776b
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository;
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
import org.springframework.web.util.WebUtils;

@Slf4j
public class OAuth2AuthorizationRequestBasedOnCookieRepository
implements AuthorizationRequestRepository<OAuth2AuthorizationRequest> {
public final static String OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME = "OAuth2_AUTHORIZATION_REQUEST";
Expand All @@ -18,6 +20,7 @@ public class OAuth2AuthorizationRequestBasedOnCookieRepository
public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) {
String stateParameter = request.getParameter(OAuth2ParameterNames.STATE);
if (stateParameter == null) {
log.debug("loadAuthorizationRequest() - state 파라미터 부재");
return null;
}

Expand All @@ -29,9 +32,11 @@ public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest re
if (stateParameter.equals(authorizationRequest.getState())) {
return authorizationRequest;
} else {
log.debug("loadAuthorizationRequest() - state 파라미터 불일치");
return null;
}
} else {
log.debug("loadAuthorizationRequest() - OAuth2_AUTHORIZATION_REQUEST 키의 쿠키 존재하지 않음");
return null;
}
}
Expand All @@ -41,10 +46,12 @@ public void saveAuthorizationRequest(OAuth2AuthorizationRequest authorizationReq
HttpServletResponse response) {
if (authorizationRequest == null) {
removeAuthorizationRequest(request, response);
log.debug("saveAuthorizationRequest() - 파라미터로 전달된 authorizationRequest가 null");
return;
}

if (authorizationRequest.getState() == null) {
log.debug("saveAuthorizationRequest() - authorization.getState() 값 null");
throw new IllegalArgumentException("authorizationRequest.state cannot be empty");
}
CookieUtils.addCookie(response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME,
Expand All @@ -57,6 +64,8 @@ public OAuth2AuthorizationRequest removeAuthorizationRequest(HttpServletRequest
OAuth2AuthorizationRequest authorizationRequest = loadAuthorizationRequest(request);
if (authorizationRequest != null) {
CookieUtils.deleteCookie(request, response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME);
} else {
log.debug("removeAuthorizationRequest() - loadAuthorizationREquest() 리턴값 null");
}
return authorizationRequest;
}
Expand Down

0 comments on commit cc6776b

Please sign in to comment.