|
|
@@ -7,6 +7,7 @@ import com.usoftchina.smartschool.auth.jwt.JwtInfo;
|
|
|
import com.usoftchina.smartschool.context.BaseContextHolder;
|
|
|
import com.usoftchina.smartschool.exception.BizException;
|
|
|
import com.usoftchina.smartschool.exception.ExceptionCode;
|
|
|
+import com.usoftchina.smartschool.utils.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -38,9 +39,10 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|
|
@Override
|
|
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
|
|
try {
|
|
|
- // 鉴别身份信息
|
|
|
- /* String token = getAuthToken(exchange.getRequest());
|
|
|
- JwtInfo jwt = null;
|
|
|
+ // 鉴别身份信息
|
|
|
+ String token = getAuthToken(exchange.getRequest());
|
|
|
+ JwtInfo jwt = null;
|
|
|
+ if (token != null) {
|
|
|
try {
|
|
|
jwt = JwtHelper.getInfoFromToken(token, authConfig.getPublicKey());
|
|
|
} catch (BizException e) {
|
|
|
@@ -49,11 +51,13 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|
|
BaseContextHolder.setAppId(jwt.getAppId());
|
|
|
BaseContextHolder.setUserId(jwt.getUserId());
|
|
|
BaseContextHolder.setUserName(jwt.getUserName());
|
|
|
+ BaseContextHolder.setSchoolId(jwt.getSchool_id());
|
|
|
BaseContextHolder.setToken(token);
|
|
|
AccountDTO accountDTO = accountApi.findByMobile(jwt.getUserName()).getData();
|
|
|
if (null == accountDTO) {
|
|
|
throw new BizException(ExceptionCode.USER_NOT_EXIST);
|
|
|
- }*/
|
|
|
+ }
|
|
|
+ }
|
|
|
return chain.filter(exchange);
|
|
|
} finally {
|
|
|
BaseContextHolder.remove();
|
|
|
@@ -62,10 +66,10 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|
|
|
|
|
private String getAuthToken(ServerHttpRequest request) {
|
|
|
List<String> headers = request.getHeaders().get(authConfig.getAuthHeader());
|
|
|
- if (headers.isEmpty()) {
|
|
|
- throw new BizException(ExceptionCode.JWT_ILLEGAL_ARGUMENT);
|
|
|
+ if (!CollectionUtils.isEmpty(headers)) {
|
|
|
+ return headers.get(0).trim();
|
|
|
}
|
|
|
- return headers.get(0).trim();
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Override
|