Skip to content

Commit

Permalink
feat: Filter 순서 세팅
Browse files Browse the repository at this point in the history
  • Loading branch information
devmizz committed May 31, 2024
1 parent 3a8345b commit 5547480
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 13 deletions.
10 changes: 10 additions & 0 deletions app/api/src/main/java/org/example/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package org.example.config;

import java.util.Collections;
import lombok.RequiredArgsConstructor;
import org.example.filter.ExceptionHandlerFilter;
import org.example.filter.JWTFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {

private final JWTFilter jwtFilter;
private final ExceptionHandlerFilter exceptionHandlerFilter;

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
Expand All @@ -29,6 +37,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.requestMatchers("swagger-ui/**", "/v3/api-docs/**").permitAll()
.anyRequest().permitAll()
)
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(exceptionHandlerFilter, JWTFilter.class)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.example.error;

import exception.BusinessException;
import exception.ErrorResponse;
import exception.GlobalError;
import org.example.exception.BusinessException;
import org.example.exception.ErrorResponse;
import org.example.exception.GlobalError;
import jakarta.validation.ConstraintViolationException;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.example.filter;

import com.fasterxml.jackson.databind.ObjectMapper;
import exception.BusinessException;
import exception.ErrorResponse;
import org.example.exception.BusinessException;
import org.example.exception.ErrorResponse;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.security.token;
package org.example.filter;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.FilterChain;
Expand All @@ -11,6 +11,8 @@
import org.example.security.dto.AuthenticatedUser;
import org.example.security.dto.TokenParam;
import org.example.security.dto.UserParam;
import org.example.security.token.JWTProcessor;
import org.example.security.token.RefreshTokenProcessor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.security.token;

import exception.BusinessException;
import org.example.exception.BusinessException;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.Jwts;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.security.vo;

import exception.BusinessError;
import org.example.exception.BusinessError;

public enum TokenError implements BusinessError {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import exception.BusinessException;
import org.example.exception.BusinessException;
import java.util.Date;
import java.util.UUID;
import org.example.property.TokenProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exception;
package org.example.exception;

public interface BusinessError {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exception;
package org.example.exception;

public class BusinessException extends RuntimeException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exception;
package org.example.exception;

public record ErrorResponse(
String errorId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exception;
package org.example.exception;

public enum GlobalError implements BusinessError {

Expand Down

0 comments on commit 5547480

Please sign in to comment.