jpz 2024-01-09 14:35:24 +08:00
commit cd27ebde9a
6 changed files with 33 additions and 5 deletions

View File

@ -0,0 +1,13 @@
package doctor.auth.controller;
import doctor.auth.service.HealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HealthController {
// @Autowired
// private HealthService healthService;
}

View File

@ -0,0 +1,4 @@
package doctor.auth.service;
public class HealthService {
}

View File

@ -2,7 +2,7 @@ package doctor.common.core.constant;
/** /**
* TokenKey * TokenKey
* *
* @author ruoyi * @author ruoyi
*/ */
public class TokenConstants public class TokenConstants
@ -11,6 +11,7 @@ public class TokenConstants
* *
*/ */
public static final String AUTHENTICATION = "Authorization"; public static final String AUTHENTICATION = "Authorization";
public static final String SESSIONID = "SESSIONID";
/** /**
* *

View File

@ -23,7 +23,7 @@ import reactor.core.publisher.Mono;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@Component @Component
@ -46,12 +46,14 @@ public class AuthFilter implements GlobalFilter, Ordered
ServerHttpRequest.Builder mutate = request.mutate(); ServerHttpRequest.Builder mutate = request.mutate();
String url = request.getURI().getPath(); String url = request.getURI().getPath();
// 跳过不需要验证的路径 // 跳过不需要验证的路径
if (StringUtils.matches(url, ignoreWhite.getWhites())) if (StringUtils.matches(url, ignoreWhite.getWhites()))
{ {
return chain.filter(exchange); return chain.filter(exchange);
} }
String token = getToken(request); String token = getToken(request);
if (StringUtils.isEmpty(token)) if (StringUtils.isEmpty(token))
{ {
return unauthorizedResponse(exchange, "令牌不能为空"); return unauthorizedResponse(exchange, "令牌不能为空");
@ -119,6 +121,13 @@ public class AuthFilter implements GlobalFilter, Ordered
private String getToken(ServerHttpRequest request) private String getToken(ServerHttpRequest request)
{ {
String token = request.getHeaders().getFirst(TokenConstants.AUTHENTICATION); String token = request.getHeaders().getFirst(TokenConstants.AUTHENTICATION);
if (StringUtils.isNotEmpty(token))
{
token = request.getQueryParams().getFirst(TokenConstants.SESSIONID);
}
if(StringUtils.isNotEmpty(token)){
request.getHeaders().set(TokenConstants.SESSIONID,token);
}
// 如果前端设置了令牌前缀,则裁剪掉前缀 // 如果前端设置了令牌前缀,则裁剪掉前缀
if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX))
{ {
@ -132,4 +141,4 @@ public class AuthFilter implements GlobalFilter, Ordered
{ {
return -200; return -200;
} }
} }

View File

@ -75,6 +75,7 @@
<artifactId>doctor-common-swagger</artifactId> <artifactId>doctor-common-swagger</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -10,10 +10,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableCustomSwagger2 @EnableCustomSwagger2
@EnableRyFeignClients @EnableRyFeignClients
@SpringBootApplication @SpringBootApplication
public class HealthApplication { public class DoctorHealthApplication {
public static void main(String[] args) public static void main(String[] args)
{ {
SpringApplication.run(HealthApplication.class, args); SpringApplication.run(DoctorHealthApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 健康服务启动成功 ლ(´ڡ`ლ)゙ \n" + System.out.println("(♥◠‿◠)ノ゙ 健康服务启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" + " .-------. ____ __ \n" +
" | _ _ \\ \\ \\ / / \n" + " | _ _ \\ \\ \\ / / \n" +