diff --git a/src/main/java/org/example/springjwt/config/SecurityConfig.java b/src/main/java/org/example/springjwt/config/SecurityConfig.java index d406695..8c39921 100644 --- a/src/main/java/org/example/springjwt/config/SecurityConfig.java +++ b/src/main/java/org/example/springjwt/config/SecurityConfig.java @@ -11,6 +11,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.web.cors.CorsConfiguration; @@ -69,7 +70,9 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { //JWTFilter 추가 http - .addFilterBefore(new JWTFilter(jwtUtil), UsernamePasswordAuthenticationFilter.class); + .addFilterBefore(new JWTFilter(jwtUtil), UsernamePasswordAuthenticationFilter.class) + .addFilterAfter(new JWTFilter(jwtUtil), OAuth2LoginAuthenticationFilter.class); + //oauth2 http diff --git a/src/main/java/org/example/springjwt/jwt/JWTFilter.java b/src/main/java/org/example/springjwt/jwt/JWTFilter.java index c8fe3df..91cc3d3 100644 --- a/src/main/java/org/example/springjwt/jwt/JWTFilter.java +++ b/src/main/java/org/example/springjwt/jwt/JWTFilter.java @@ -23,6 +23,8 @@ public JWTFilter(JWTUtil jwtUtil) { this.jwtUtil = jwtUtil; } + + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { //cookie들을 불러온 뒤 Authorization Key에 담긴 쿠키를 찾음 @@ -79,5 +81,20 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse SecurityContextHolder.getContext().setAuthentication(authToken); filterChain.doFilter(request, response); + + String requestUri = request.getRequestURI(); + + if (requestUri.matches("^\\/login(?:\\/.*)?$")) { + + filterChain.doFilter(request, response); + return; + } + if (requestUri.matches("^\\/oauth2(?:\\/.*)?$")) { + + filterChain.doFilter(request, response); + return; + } } + + } diff --git a/src/main/java/org/example/springjwt/oAuth/CustomSuccessHandler.java b/src/main/java/org/example/springjwt/oAuth/CustomSuccessHandler.java index 6b53d90..d64b426 100644 --- a/src/main/java/org/example/springjwt/oAuth/CustomSuccessHandler.java +++ b/src/main/java/org/example/springjwt/oAuth/CustomSuccessHandler.java @@ -40,7 +40,8 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo String token = jwtUtil.createJwt(username, role, 60*60*60L); response.addCookie(createCookie("Authorization", token)); - response.sendRedirect("http://localhost:3000/"); + //response.sendRedirect("http://localhost:3000/"); + response.sendRedirect("http://localhost:8080/my"); } private Cookie createCookie(String key, String value) {