Skip to content

Commit

Permalink
fix: disable rest of filter
Browse files Browse the repository at this point in the history
  • Loading branch information
JIUNG9 committed Dec 14, 2023
1 parent e06dcb5 commit a2278ec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
2 changes: 2 additions & 0 deletions src/main/java/kr/bb/apigateway/common/LoggingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
@Slf4j
public class LoggingFilter implements GlobalFilter {

Expand Down
1 change: 0 additions & 1 deletion src/main/java/kr/bb/apigateway/common/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kr.bb.apigateway.common;


import kr.bb.apigateway.systsem.filter.SystemAdminAuthorizationGatewayFilter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Slf4j
public class SystemAdminAuthorizationGatewayFilter implements GlobalFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
String requestURI = request.getURI().toString();
log.warn("-------------requestURI :" +requestURI);

if (shouldNotFilter(requestURI)) {
return chain.filter(exchange);
}
else if (!isSystemAdmin(exchange)) {
return handleUnauthorized(exchange);
}
return chain.filter(exchange);
}

private boolean shouldNotFilter(String requestURI) {
return !requestURI.contains("/admin") || requestURI.contains("/admin/login");
}

private boolean isSystemAdmin(ServerWebExchange exchange) {
String role = ExtractAuthorizationTokenUtil.extractRole(exchange.getRequest());
return Role.ROLE_SYSTEM_ADMIN.name().equals(role);
}


private Mono<Void> handleUnauthorized(ServerWebExchange exchange) {
ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(HttpStatus.UNAUTHORIZED);
return response.setComplete();
}
}
//@Slf4j
//public class SystemAdminAuthorizationGatewayFilter implements GlobalFilter {
// @Override
// public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
// ServerHttpRequest request = exchange.getRequest();
// String requestURI = request.getURI().toString();
// log.warn("-------------requestURI :" +requestURI);
//
// if (shouldNotFilter(requestURI)) {
// return chain.filter(exchange);
// }
// else if (!isSystemAdmin(exchange)) {
// return handleUnauthorized(exchange);
// }
// return chain.filter(exchange);
// }
//
// private boolean shouldNotFilter(String requestURI) {
// return !requestURI.contains("/admin") || requestURI.contains("/admin/login");
// }
//
// private boolean isSystemAdmin(ServerWebExchange exchange) {
// String role = ExtractAuthorizationTokenUtil.extractRole(exchange.getRequest());
// return Role.ROLE_SYSTEM_ADMIN.name().equals(role);
// }
//
//
// private Mono<Void> handleUnauthorized(ServerWebExchange exchange) {
// ServerHttpResponse response = exchange.getResponse();
// response.setStatusCode(HttpStatus.UNAUTHORIZED);
// return response.setComplete();
// }
//}

0 comments on commit a2278ec

Please sign in to comment.