mirror of
https://gitee.com/beecue/fastbee.git
synced 2026-03-21 22:14:50 +08:00
refactor(swagger接口): 访问新增校验
This commit is contained in:
@@ -121,7 +121,7 @@ public class SecurityConfig
|
||||
.antMatchers("/goview/sys/login","/goview/project/getData").permitAll()
|
||||
// 静态资源,可匿名访问
|
||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/druid/**").permitAll()
|
||||
// 除上面外的所有请求全部需要鉴权认证
|
||||
.anyRequest().authenticated();
|
||||
})
|
||||
|
||||
@@ -22,10 +22,9 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
@@ -334,6 +333,19 @@ public class TokenService {
|
||||
*/
|
||||
private String getToken(HttpServletRequest request) {
|
||||
String token = request.getHeader(header);
|
||||
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
String uri = request.getRequestURI();
|
||||
if (uri.contains("/v2/api-docs") || uri.contains("/v3/api-docs")) {
|
||||
token = Optional.ofNullable(request.getCookies())
|
||||
.flatMap(cookies -> Arrays.stream(cookies)
|
||||
.filter(c -> "Admin-Token".equals(c.getName()))
|
||||
.map(Cookie::getValue)
|
||||
.findFirst())
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) {
|
||||
token = token.replace(Constants.TOKEN_PREFIX, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user