修改依赖
This commit is contained in:
parent
e7dbc6e9c3
commit
a39378d266
@ -41,6 +41,10 @@
|
|||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.qiuguo.iot.base.nlp.INlp;
|
import com.qiuguo.iot.base.nlp.INlp;
|
||||||
import com.qiuguo.iot.base.nlp.Nlp;
|
import com.qiuguo.iot.base.nlp.Nlp;
|
||||||
import com.qiuguo.iot.base.nlp.NlpKey;
|
import com.qiuguo.iot.base.nlp.NlpKey;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|||||||
@ -83,7 +83,26 @@
|
|||||||
<artifactId>reactor-test</artifactId>
|
<artifactId>reactor-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>cn.123tool.chen</groupId>-->
|
||||||
|
<!-- <artifactId>commons</artifactId>-->
|
||||||
|
<!-- <version>1.0.0</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springframework</groupId>-->
|
||||||
|
<!-- <artifactId>spring-context</artifactId>-->
|
||||||
|
<!-- <version>5.0.9.RELEASE</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springframework</groupId>-->
|
||||||
|
<!-- <artifactId>spring-web</artifactId>-->
|
||||||
|
<!-- <version>5.0.9.RELEASE</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.qiuguo.iot</groupId>
|
<groupId>com.qiuguo.iot</groupId>
|
||||||
<artifactId>iot-data</artifactId>
|
<artifactId>iot-data</artifactId>
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import org.springframework.web.method.HandlerMethod;
|
|||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.WebFilter;
|
import org.springframework.web.server.WebFilter;
|
||||||
import org.springframework.web.server.WebFilterChain;
|
import org.springframework.web.server.WebFilterChain;
|
||||||
import org.springframework.web.servlet.HandlerMapping;
|
// import org.springframework.web.servlet.HandlerMapping;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,31 +38,31 @@ public class AuthFilter implements WebFilter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||||
HandlerMethod handlerMethod = exchange.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
|
// HandlerMethod handlerMethod = exchange.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
|
||||||
Object attribute = exchange.getAttribute("org.springframework.web.server.ServerWebExchange.LOG_ID");
|
Object attribute = exchange.getAttribute("org.springframework.web.server.ServerWebExchange.LOG_ID");
|
||||||
System.out.println("attribute = " + attribute);
|
System.out.println("attribute = " + attribute);
|
||||||
if (handlerMethod != null && handlerMethod.getMethod().isAnnotationPresent(Auth.class)) {
|
// if (handlerMethod != null && handlerMethod.getMethod().isAnnotationPresent(Auth.class)) {
|
||||||
// 如果请求方法上有 Auth 注解,执行登录验证逻辑
|
// // 如果请求方法上有 Auth 注解,执行登录验证逻辑
|
||||||
String api_token = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TOKEN);
|
// String api_token = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TOKEN);
|
||||||
String api_type = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TYPE);
|
// String api_type = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TYPE);
|
||||||
if (ObjectUtils.isEmpty(api_token) || ObjectUtils.isEmpty(api_type)) {
|
// if (ObjectUtils.isEmpty(api_token) || ObjectUtils.isEmpty(api_type)) {
|
||||||
return Mono.error(new RuntimeException("未登录"));
|
// return Mono.error(new RuntimeException("未登录"));
|
||||||
}
|
// }
|
||||||
String key = RedisConstans.IOT_TOKEN.concat(api_token);
|
// String key = RedisConstans.IOT_TOKEN.concat(api_token);
|
||||||
return reactiveRedisTemplate.getExpire(key).map(Duration::getSeconds).flatMap(ttl -> {
|
// return reactiveRedisTemplate.getExpire(key).map(Duration::getSeconds).flatMap(ttl -> {
|
||||||
if (ttl == -1) {
|
// if (ttl == -1) {
|
||||||
// 用户没登陆
|
// // 用户没登陆
|
||||||
return Mono.error(new RuntimeException("未登录"));
|
// return Mono.error(new RuntimeException("未登录"));
|
||||||
} else if (ttl <= 3600) {
|
// } else if (ttl <= 3600) {
|
||||||
// token 将要失效
|
// // token 将要失效
|
||||||
return reactiveRedisTemplate.expire(key, Duration.ofDays(7))
|
// return reactiveRedisTemplate.expire(key, Duration.ofDays(7))
|
||||||
.then(chain.filter(exchange));
|
// .then(chain.filter(exchange));
|
||||||
} else {
|
// } else {
|
||||||
// 正常登录
|
// // 正常登录
|
||||||
return chain.filter(exchange);
|
// return chain.filter(exchange);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user