Skip to content

Commit

Permalink
Merge pull request #88 from SSU-Plector/issue/87-refactor-error
Browse files Browse the repository at this point in the history
♻️ [Refactor] 비정상 코드로 접근시 예외처리 / 인증없이 접근시 예외처리
  • Loading branch information
88dldl authored May 15, 2024
2 parents 6c17818 + 33b05c2 commit 46aee04
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/main/java/ssuPlector/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
"/api/auth/kakao/login",
"api/developers/{developerId}",
"/api/developers/list",
"/api/developers",
"/api/projects/{projectId}",
"/api/projects/list",
"/api/projects")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ssuPlector.security.handler.resolver;

import java.util.Optional;

import org.springframework.core.MethodParameter;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -41,7 +39,7 @@ public Object resolveArgument(

if (authentication != null) {
if (authentication.getName().equals("anonymousUser")) {
return Optional.empty();
throw new GlobalException(GlobalErrorCode._BAD_REQUEST);
}
principal = authentication.getPrincipal();
}
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/ssuPlector/security/provider/KakaoAuthProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -39,13 +40,17 @@ public OAuthToken getAccessToken(String code) {

HttpEntity<MultiValueMap<String, String>> kakaoTokenRequest =
new HttpEntity<>(params, headers);
ResponseEntity<String> response =
restTemplate.exchange(
"https://kauth.kakao.com/oauth/token",
HttpMethod.POST,
kakaoTokenRequest,
String.class);

ResponseEntity<String> response;
try {
response =
restTemplate.exchange(
"https://kauth.kakao.com/oauth/token",
HttpMethod.POST,
kakaoTokenRequest,
String.class);
} catch (HttpClientErrorException e) {
throw new GlobalException(GlobalErrorCode._BAD_REQUEST);
}
ObjectMapper objectMapper = new ObjectMapper();
OAuthToken oAuthToken;

Expand Down

0 comments on commit 46aee04

Please sign in to comment.