|  |  | package com.example.gateway.filter; | 
|  |  |  | 
|  |  | import com.alibaba.fastjson.JSON; | 
|  |  | import com.alibaba.fastjson.JSONArray; | 
|  |  | import com.alibaba.fastjson.JSONObject; | 
|  |  | import com.example.gateway.model.PERMISSION; | 
|  |  | import com.example.gateway.model.ROLE; | 
|  |  | import com.example.gateway.model.ResponseBean; | 
|  |  | import com.example.gateway.model.USERS; | 
|  |  | import com.example.gateway.util.JsonToBean; | 
|  |  | import lombok.extern.slf4j.Slf4j; | 
|  |  | import org.reactivestreams.Publisher; | 
|  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|  |  | import org.springframework.cloud.gateway.filter.GatewayFilterChain; | 
| ... | ... | @@ -27,17 +25,15 @@ import org.springframework.util.AntPathMatcher; | 
|  |  | import org.springframework.web.server.ServerWebExchange; | 
|  |  | import reactor.core.publisher.Flux; | 
|  |  | import reactor.core.publisher.Mono; | 
|  |  |  | 
|  |  | import javax.management.relation.Role; | 
|  |  | import java.nio.charset.Charset; | 
|  |  | import java.util.ArrayList; | 
|  |  | import java.util.List; | 
|  |  |  | 
|  |  | /** | 
|  |  | * @author | 
|  |  | * @author MRZ | 
|  |  | * @time 2019-09-09 12:13 | 
|  |  | */ | 
|  |  | @Component | 
|  |  | @Slf4j | 
|  |  | public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { | 
|  |  |  | 
|  |  | private static final String LOGIN = "user-center/login"; | 
| ... | ... | @@ -94,7 +90,7 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { | 
|  |  | /** | 
|  |  | * 测试返回中文乱码 | 
|  |  | */ | 
|  |  | ServerHttpResponseDecorator decoratedResponse = new ServerHttpResponseDecorator(response) { | 
|  |  | ServerHttpResponseDecorator decoratedResponseWindows = new ServerHttpResponseDecorator(response) { | 
|  |  | @Override | 
|  |  | public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { | 
|  |  | if (HttpStatus.OK.equals(getStatusCode()) && body instanceof Flux) { | 
| ... | ... | @@ -126,7 +122,7 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { | 
|  |  | return super.writeWith(body); | 
|  |  | } | 
|  |  | }; | 
|  |  | return chain.filter(exchange.mutate().response(decoratedResponse).build()); | 
|  |  | return chain.filter(exchange.mutate().response(decoratedResponseWindows).build()); | 
|  |  | // | 
|  |  | //        return chain.filter(exchange); | 
|  |  | } | 
| ... | ... | @@ -149,19 +145,26 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { | 
|  |  | if(rqHeader.containsKey("Authorization")){ | 
|  |  | token = rqHeader.get("Authorization").toString(); | 
|  |  | token = token.substring(1, token.length() - 1); | 
|  |  | log.info("[TOKEN]-Request Authorization INFO is:[{}]",token); | 
|  |  | } | 
|  |  | } | 
|  |  | String redisKey = token.replace("Bearer ", ""); | 
|  |  | log.info("[REDIS-KEY]-is:[{}]",redisKey); | 
|  |  | String json = stringRedisTemplate.opsForValue().get(redisKey); | 
|  |  | if (json != null) { | 
|  |  | List<PERMISSION> permissionList = JsonToBean.jsonToUser(json); | 
|  |  | for (PERMISSION permission : permissionList) { | 
|  |  | log.trace("访问url:[{}]<->权限[{}]",request.getPath().toString(),permission.getUrl()); | 
|  |  | if (pathMatcher.match(permission.getUrl(), request.getPath().toString())) { | 
|  |  | log.info("[FILTER]-[URL:{}]->鉴权成功",request.getPath().toString()); | 
|  |  | flag = true; | 
|  |  | break; | 
|  |  | } | 
|  |  | } | 
|  |  | }else { | 
|  |  | log.info("[FILTER]-没有对应token的redis缓存,鉴权失败"); | 
|  |  | } | 
|  |  | log.info("[FILTER]-[URL:{}]->鉴权失败",request.getPath().toString()); | 
|  |  | return flag; | 
|  |  | } | 
|  |  |  | 
| ... | ... | @@ -189,12 +192,13 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { | 
|  |  | } | 
|  |  | } | 
|  |  | }catch (Exception e){ | 
|  |  | e.printStackTrace(); | 
|  |  | log.error("[ANONYMOUS-FILTER]匿名者过滤规则审核出错->{}",e.toString()); | 
|  |  | return false; | 
|  |  | } | 
|  |  |  | 
|  |  |  | 
|  |  | } | 
|  |  | log.info("[ANONYMOUS-FILTER]-匿名者过滤器为适配到符合条件的规则-PATH:[{}]",request.getPath().toString()); | 
|  |  | return false; | 
|  |  | } | 
|  |  | } | 
... | ... |  |