Skip to content

Commit

Permalink
revert: not to use the filter
Browse files Browse the repository at this point in the history
  • Loading branch information
JIUNG9 committed Dec 14, 2023
1 parent 548a9c9 commit 9d03037
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 60 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-bus-kafka"
implementation 'org.springframework.data:spring-data-redis'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'redis.clients:jedis'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,65 @@
import kr.bb.apigateway.common.util.ExtractAuthorizationTokenUtil;
import kr.bb.apigateway.common.util.JwtUtil;
import kr.bb.apigateway.common.util.RedisBlackListTokenUtil;
import kr.bb.apigateway.common.valueobject.JWTAuthenticationShouldNotFilterAntMatcher;
import kr.bb.apigateway.common.valueobject.Oauth2RequestURI;
import kr.bb.apigateway.common.valueobject.SwaggerRequestURI;
import lombok.RequiredArgsConstructor;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

//@RequiredArgsConstructor
//@Component
//public class JwtValidationGatewayFilter implements GlobalFilter {
//public class JwtValidationGatewayFilterFactory extends
// AbstractGatewayFilterFactory<JwtValidationGatewayFilterFactory.Config> {
//
// private final RedisBlackListTokenUtil redisBlackListTokenUtil;
//
// @Override
// public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
// ServerHttpRequest request = exchange.getRequest();
// String requestURI = request.getURI().getPath();
// public JwtValidationGatewayFilterFactory(RedisBlackListTokenUtil redisBlackListTokenUtil) {
// this.redisBlackListTokenUtil = redisBlackListTokenUtil;
// }
//
// if (shouldNotFilter(requestURI)) {
// return chain.filter(exchange);
// } else {
// String token = ExtractAuthorizationTokenUtil.extractToken(exchange.getRequest());
// @Override
// public GatewayFilter apply(Config config) {
// return (exchange, chain) -> {
// ServerHttpRequest request = exchange.getRequest();
// String token = ExtractAuthorizationTokenUtil.extractToken(request);
// if (redisBlackListTokenUtil.isTokenBlacklisted(token)) {
// ServerHttpResponse response = exchange.getResponse();
// response.setStatusCode(HttpStatus.UNAUTHORIZED);
// return response.setComplete();
// }
//
// try {
// JwtUtil.isTokenValid(token);
// } catch (ExpiredJwtException e) {
// ServerHttpResponse response = exchange.getResponse();
// response.setStatusCode(HttpStatus.UNAUTHORIZED);
// return response.setComplete();
// return handleError(exchange, HttpStatus.UNAUTHORIZED);
// }
//
// return chain.filter(addUserIdHeaderAtRequest(exchange, JwtUtil.extractSubject(token)));
// }
// else{
// try {
// JwtUtil.isTokenValid(token);
// return chain.filter(addUserIdHeaderAtRequest(exchange, JwtUtil.extractSubject(token)));
// } catch (ExpiredJwtException e) {
// return handleError(exchange, HttpStatus.UNAUTHORIZED);
// }
// }
// };
// }
//
// private boolean shouldNotFilter(String requestURI) {
// return shouldNotFilterSwaggerURI(requestURI) ||
// shouldNotFilterSystemPolicyURI(requestURI) ||
// shouldNotFilterOauth2(requestURI);
// }
//
// private boolean shouldNotFilterSwaggerURI(String requestURI) {
// return requestURI.contains(SwaggerRequestURI.RESOURCES) ||
// requestURI.contains(SwaggerRequestURI.UI_URI) ||
// requestURI.contains(SwaggerRequestURI.WEB_JARS) ||
// requestURI.contains(SwaggerRequestURI.API_DOCS_URI) ||
// requestURI.contains(SwaggerRequestURI.FAVICON);
// private Mono<Void> handleError(ServerWebExchange exchange, HttpStatus status) {
// ServerHttpResponse response = exchange.getResponse();
// response.setStatusCode(status);
// return response.setComplete();
// }
//
// private boolean shouldNotFilterSystemPolicyURI(String requestURI) {
// return requestURI.contains(JWTAuthenticationShouldNotFilterAntMatcher.EMAIL_ANT) ||
// requestURI.contains(JWTAuthenticationShouldNotFilterAntMatcher.LOGIN_ANT) ||
// requestURI.contains(JWTAuthenticationShouldNotFilterAntMatcher.SIGNUP_ANT);
//
// private ServerWebExchange addUserIdHeaderAtRequest(ServerWebExchange exchange, String userId) {
// }
//
// private boolean shouldNotFilterOauth2(String requestURI){
// return requestURI.contains(Oauth2RequestURI.OAUTH2_REQUEST);
// }
//
// private ServerWebExchange addUserIdHeaderAtRequest(ServerWebExchange exchange, String userId) {
// ServerHttpRequest modifiedRequest = exchange.getRequest().mutate()
// .header("userId", userId)
// .build();
// public static class Config {
//
// return exchange.mutate()
// .request(modifiedRequest)
// .build();
// }
// private boolean shouldNotFilterURL;
//
// public String getShouldNotURL() {
// return shouldNotFilterURL;
// }
//
// public void setShouldNotURL(String shouldNotURL) {
// this.shouldNotFilterURL = shouldNotURL;
// }
// }
//}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kr.bb.apigateway.common.util;

import io.jsonwebtoken.Claims;
import javax.servlet.http.HttpServletRequest;
import kr.bb.apigateway.common.valueobject.SecurityPolicyStaticValue;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
Expand Down

0 comments on commit 9d03037

Please sign in to comment.