Skip to content

Commit

Permalink
KNU-HAEDAL#1 feat: docs 및 권한 관련 config 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
momnpa333 committed Apr 25, 2024
1 parent cd4c616 commit 16a2b3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand All @@ -23,14 +24,18 @@

@Component
@RequiredArgsConstructor
@Slf4j
public class JwtAuthorizationFilter extends OncePerRequestFilter {
private final JwtProvider jwtProvider;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
log.info("dofilterinternal 실행");

if (request.getRequestURI().startsWith("/oauth2") || request.getRequestURI().startsWith("/refresh") ||request.getRequestURI().startsWith("/swagger-ui")||request.getRequestURI().startsWith("/api-docs")||request.getRequestURI().startsWith("/v3")) {
log.info("다음필터 실행");

if (request.getRequestURI().startsWith("/oauth2") | request.getRequestURI().startsWith("/refresh")) {
filterChain.doFilter(request, response);
return;
}
Expand All @@ -48,6 +53,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
throw new IllegalArgumentException("예상치 못한 토큰 오류");
}

log.info("다음필터 실행");
// 다음 Filter를 실행하기 위한 코드. 마지막 필터라면 필터 실행 후 리소스를 반환한다.
filterChain.doFilter(request, response);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.haedal.gifticionfunding.auth.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
Expand All @@ -21,6 +22,7 @@
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
@Slf4j
public class SecurityConfig {
private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint;
private final CustomAccessDeniedHandler customAccessDeniedHandler;
Expand All @@ -38,14 +40,15 @@ public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
log.info("필터체인 실행");
http
.csrf(AbstractHttpConfigurer::disable)
.cors(c -> c.configurationSource(corsConfigSource()))
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(authReq -> authReq
.requestMatchers(HttpMethod.OPTIONS).permitAll()
.requestMatchers("/", "/login", "/oauth2/**", "/refresh").permitAll()
.requestMatchers("/", "/login", "/oauth2/**", "/refresh","/swagger-ui/**","/api-docs","/v3/api-docs/**").permitAll()
.anyRequest().authenticated())
.exceptionHandling(e -> e
.authenticationEntryPoint(customAuthenticationEntryPoint)
Expand Down

0 comments on commit 16a2b3e

Please sign in to comment.