|
@@ -1,5 +1,8 @@
|
|
|
package com.diagbot.config.security;
|
|
|
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.exception.ServiceErrorCode;
|
|
|
import com.diagbot.facade.TokenFacade;
|
|
|
import com.diagbot.util.HttpUtils;
|
|
|
import com.diagbot.util.StringUtil;
|
|
@@ -32,17 +35,28 @@ public class UrlAccessDecisionManager implements AccessDecisionManager {
|
|
|
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
|
|
|
HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();
|
|
|
String url, method;
|
|
|
+ String tokenStr = HttpUtils.getHeaders(request).get("Authorization");
|
|
|
+ //用户是否被顶掉校验
|
|
|
+ if (StringUtil.isNotEmpty(tokenStr) && !matchNotCheckUrl(request)) {
|
|
|
+ tokenStr = tokenStr.replaceFirst("Bearer ", "");
|
|
|
+ int res = tokenFacade.newVerifyToken(tokenStr, 1);
|
|
|
+ if (-1 == res) {
|
|
|
+ throw new CommonException(ServiceErrorCode.LONGIN_ERROE);
|
|
|
+ }
|
|
|
+ }
|
|
|
if (matchPermitAllUrl(request)) {
|
|
|
return;
|
|
|
}
|
|
|
if ("anonymousUser".equals(authentication.getPrincipal())) {
|
|
|
throw new AccessDeniedException("no right");
|
|
|
} else {
|
|
|
- String tokenStr = HttpUtils.getHeaders(request).get("Authorization");
|
|
|
if (StringUtil.isNotEmpty(tokenStr)) {
|
|
|
tokenStr = tokenStr.replaceFirst("Bearer ", "");
|
|
|
- Boolean res = tokenFacade.verifyToken(tokenStr, 1);
|
|
|
- if (!res) {
|
|
|
+// Boolean res = tokenFacade.verifyToken(tokenStr, 1);
|
|
|
+ int res = tokenFacade.newVerifyToken(tokenStr, 1);
|
|
|
+ if (-1 == res) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该账号在其他地方登录。");
|
|
|
+ } else if (1 != res) {
|
|
|
throw new AccountExpiredException("token expire");
|
|
|
}
|
|
|
}
|
|
@@ -334,4 +348,28 @@ public class UrlAccessDecisionManager implements AccessDecisionManager {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+ private boolean matchNotCheckUrl(HttpServletRequest request) {
|
|
|
+ if (matchers("/swagger/**", request)
|
|
|
+ || matchers("/v2/**", request)
|
|
|
+ || matchers("/swagger-ui.html/**", request)
|
|
|
+ || matchers("/swagger-resources/**", request)
|
|
|
+ || matchers("/webjars/**", request)
|
|
|
+ || matchers("/druid/**", request)
|
|
|
+ || matchers("/actuator/**", request)
|
|
|
+ || matchers("/hystrix/**", request)
|
|
|
+ || matchers("/sys/user/getJwt", request)
|
|
|
+ || matchers("/sys/user/logout", request)
|
|
|
+ || matchers("/sys/user/getCaptcha", request)
|
|
|
+ || matchers("/sys/user/getHospitalMark", request)
|
|
|
+ || matchers("/sys/user/getJwtNoPass", request)
|
|
|
+ || matchers("/sys/user/refreshJwt", request)
|
|
|
+ || matchers("/sys/dictionaryInfo/getDictionary", request)
|
|
|
+ || matchers("/sys/user/checkToken", request)
|
|
|
+ || matchers("/oauth/token", request)
|
|
|
+ || matchers("/oauth/check_token", request)
|
|
|
+ || matchers("/cache/clear", request)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|