Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: frontend의 host에 대하여 CORS 설정 #56

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SwaggerConfiguration {
@Bean
public OpenAPI openAPI(){
Server server = new Server();
server.setUrl("http://localhost:8080");
server.setUrl("https://khumon-edu.kro.kr");
List<Server> servers = new ArrayList<>();
servers.add(server);
return new OpenAPI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class WebConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000", "http://localhost:8080", "http://facerain-dev.iptime.org:5000")
.allowedOrigins("http://localhost:3000", "http://localhost:8080", "http://facerain-dev.iptime.org:5000", "https://khumon-study.kro.kr", "https://khumon-edu.kro.kr")
.allowedHeaders("authorization", "User-Agent", "Cache-Control", "Content-Type")
.exposedHeaders("authorization", "User-Agent", "Cache-Control", "Content-Type")
.allowedMethods("*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public WebSecurityCustomizer webSecurityCustomizer() {
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

configuration.setAllowedOrigins(List.of("http://localhost:3000", "http://localhost:8080", "http://facerain-dev.iptime.org:5000"));
configuration.setAllowedOrigins(List.of("http://localhost:3000", "http://localhost:8080", "http://facerain-dev.iptime.org:5000", "https://khumon-study.kro.kr", "https://khumon-edu.kro.kr"));
configuration.addAllowedOriginPattern("*");
configuration.addAllowedMethod("*");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1 @@
package com.teamh.khumon.security;


import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class OAuth2LoginFailureHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
ObjectMapper objectMapper = new ObjectMapper();
response.setContentType("application/json;charset=UTF-8");
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
JSONObject jsonObject = new JSONObject();
log.info("소셜 로그인 실패");
try {
jsonObject.put("message", "소셜 로그인 실패");
} catch (JSONException e) {
throw new RuntimeException(e);
}
response.getWriter().write(objectMapper.writeValueAsString(jsonObject));
}
}
package com.teamh.khumon.security;import com.fasterxml.jackson.databind.ObjectMapper;import jakarta.servlet.ServletException;import jakarta.servlet.http.HttpServletRequest;import jakarta.servlet.http.HttpServletResponse;import lombok.extern.slf4j.Slf4j;import org.json.JSONException;import org.json.JSONObject;import org.springframework.security.core.AuthenticationException;import org.springframework.security.web.authentication.AuthenticationFailureHandler;import org.springframework.stereotype.Component;import java.io.IOException;@Slf4j@Componentpublic class OAuth2LoginFailureHandler implements AuthenticationFailureHandler { @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { ObjectMapper objectMapper = new ObjectMapper(); response.setContentType("application/json;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); JSONObject jsonObject = new JSONObject(); log.info("소셜 로그인 실패"); try { jsonObject.put("message", "소셜 로그인 실패"); } catch (JSONException e) { throw new RuntimeException(e); } response.getWriter().write(objectMapper.writeValueAsString(jsonObject)); }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ private String extractUsername(Authentication authentication) {
private URI createURI() throws UnsupportedEncodingException {
return UriComponentsBuilder
.newInstance()
.scheme("http")
.host("localhost")
.port(3000)
.scheme("https")
.host("khumon-study.kro.kr")
.build()
.toUri();
}
Expand Down
Loading