diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index e199f7c..8fa9732 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -178,5 +178,4 @@ - \ No newline at end of file diff --git a/fizz-plugin/src/main/java/we/plugin/dedicatedline/auth/DedicatedLineApiAuthPluginFilter.java b/fizz-plugin/src/main/java/we/plugin/dedicatedline/auth/DedicatedLineApiAuthPluginFilter.java index 962fa16..830ca9c 100644 --- a/fizz-plugin/src/main/java/we/plugin/dedicatedline/auth/DedicatedLineApiAuthPluginFilter.java +++ b/fizz-plugin/src/main/java/we/plugin/dedicatedline/auth/DedicatedLineApiAuthPluginFilter.java @@ -19,19 +19,13 @@ package we.plugin.dedicatedline.auth; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; - import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; - import we.dedicated_line.DedicatedLineService; - - import we.plugin.FizzPluginFilter; import we.plugin.FizzPluginFilterChain; import we.util.ReactorUtils; @@ -41,62 +35,52 @@ import javax.annotation.Resource; import java.util.Map; /** - * * @author Francis Dong - * */ @Component(DedicatedLineApiAuthPluginFilter.DEDICATED_LINE_API_AUTH_PLUGIN_FILTER) public class DedicatedLineApiAuthPluginFilter implements FizzPluginFilter { - private static final Logger log = LoggerFactory.getLogger(DedicatedLineApiAuthPluginFilter.class); + private static final Logger log = LoggerFactory.getLogger(DedicatedLineApiAuthPluginFilter.class); + @Resource + private DedicatedLineService dedicatedLineService; + public static final String DEDICATED_LINE_API_AUTH_PLUGIN_FILTER = "dedicatedLineApiAuthPlugin"; - @Resource - private DedicatedLineService dedicatedLineService; - - public static final String DEDICATED_LINE_API_AUTH_PLUGIN_FILTER = "dedicatedLineCodecPlugin"; - - - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public Mono filter(ServerWebExchange exchange, Map config) { - String traceId = WebUtils.getTraceId(exchange); - try { - - String dedicatedLineId = WebUtils.getDedicatedLineId(exchange); - String service = WebUtils.getClientService(exchange); - String path = WebUtils.getClientReqPath(exchange); - HttpMethod method = exchange.getRequest().getMethod(); - if (dedicatedLineService.auth(dedicatedLineId, method, service, path)) { - - // Go to next plugin - Mono next = FizzPluginFilterChain.next(exchange); - return next.defaultIfEmpty(ReactorUtils.NULL).flatMap(nil -> { - doAfter(); - return Mono.empty(); - }); - } else { - // Auth failed - ServerHttpResponse response = exchange.getResponse(); - response.setStatusCode(HttpStatus.UNAUTHORIZED); - response.getHeaders().setCacheControl("no-store"); - response.getHeaders().setExpires(0); - String respJson = WebUtils.jsonRespBody(HttpStatus.UNAUTHORIZED.value(), - HttpStatus.UNAUTHORIZED.getReasonPhrase(), traceId); - return WebUtils.response(exchange, HttpStatus.UNAUTHORIZED, null, respJson); - } - } catch (Exception e) { - log.error("{} {} exception", traceId, DEDICATED_LINE_API_AUTH_PLUGIN_FILTER, e); - String respJson = WebUtils.jsonRespBody(HttpStatus.INTERNAL_SERVER_ERROR.value(), - HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), traceId); - return WebUtils.response(exchange, HttpStatus.INTERNAL_SERVER_ERROR, null, respJson); - } - } - - public void doAfter() { - - } + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public Mono filter(ServerWebExchange exchange, Map config) { + String traceId = WebUtils.getTraceId(exchange); + try { + String dedicatedLineId = WebUtils.getDedicatedLineId(exchange); + String service = WebUtils.getClientService(exchange); + String path = WebUtils.getClientReqPath(exchange); + HttpMethod method = exchange.getRequest().getMethod(); + if (dedicatedLineService.auth(dedicatedLineId, method, service, path)) { + // Go to next plugin + Mono next = FizzPluginFilterChain.next(exchange); + return next.defaultIfEmpty(ReactorUtils.NULL).flatMap(nil -> { + doAfter(); + return Mono.empty(); + }); + } else { + // Auth failed + ServerHttpResponse response = exchange.getResponse(); + response.setStatusCode(HttpStatus.UNAUTHORIZED); + response.getHeaders().setCacheControl("no-store"); + response.getHeaders().setExpires(0); + String respJson = WebUtils.jsonRespBody(HttpStatus.UNAUTHORIZED.value(), + HttpStatus.UNAUTHORIZED.getReasonPhrase(), traceId); + return WebUtils.response(exchange, HttpStatus.UNAUTHORIZED, null, respJson); + } + } catch (Exception e) { + log.error("{} {} exception", traceId, DEDICATED_LINE_API_AUTH_PLUGIN_FILTER, e); + String respJson = WebUtils.jsonRespBody(HttpStatus.INTERNAL_SERVER_ERROR.value(), + HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), traceId); + return WebUtils.response(exchange, HttpStatus.INTERNAL_SERVER_ERROR, null, respJson); + } + } + public void doAfter() { + } } diff --git a/pom.xml b/pom.xml index b4cea25..0810719 100644 --- a/pom.xml +++ b/pom.xml @@ -439,7 +439,6 @@ hutool-crypto 5.7.16 -