|
@@ -1,5 +1,7 @@
|
|
package com.qmth.teachcloud.common.util;
|
|
package com.qmth.teachcloud.common.util;
|
|
|
|
|
|
|
|
+import com.qmth.boot.api.annotation.Aac;
|
|
|
|
+import com.qmth.boot.api.annotation.BOOL;
|
|
import com.qmth.boot.core.enums.Platform;
|
|
import com.qmth.boot.core.enums.Platform;
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
import com.qmth.teachcloud.common.SignatureEntityTest;
|
|
import com.qmth.teachcloud.common.SignatureEntityTest;
|
|
@@ -16,9 +18,11 @@ import com.qmth.teachcloud.common.service.CacheService;
|
|
import org.apache.catalina.Role;
|
|
import org.apache.catalina.Role;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.web.method.HandlerMethod;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.lang.annotation.Annotation;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -38,9 +42,10 @@ public class AuthUtil {
|
|
*
|
|
*
|
|
* @param request
|
|
* @param request
|
|
* @param response
|
|
* @param response
|
|
|
|
+ * @param handler
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static boolean adminAuthInterceptor(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
|
+ public static boolean adminAuthInterceptor(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
|
String url = request.getServletPath();
|
|
String url = request.getServletPath();
|
|
cacheService = SpringContextHolder.getBean(CacheService.class);
|
|
cacheService = SpringContextHolder.getBean(CacheService.class);
|
|
List<String> privilegeUrl = cacheService.privilegeUrlCache(PrivilegePropertyEnum.NO_AUTH);
|
|
List<String> privilegeUrl = cacheService.privilegeUrlCache(PrivilegePropertyEnum.NO_AUTH);
|
|
@@ -65,7 +70,7 @@ public class AuthUtil {
|
|
SysUser sysUser = cacheService.userCache(userId);
|
|
SysUser sysUser = cacheService.userCache(userId);
|
|
request.setAttribute(SystemConstant.SESSION, tbSession);
|
|
request.setAttribute(SystemConstant.SESSION, tbSession);
|
|
request.setAttribute(SystemConstant.USER, sysUser);
|
|
request.setAttribute(SystemConstant.USER, sysUser);
|
|
- return authFootCommon(userId, SystemConstant.USER_OAUTH_CACHE, request, response);
|
|
|
|
|
|
+ return authFootCommon(userId, SystemConstant.USER_OAUTH_CACHE, request, response, handler);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -133,12 +138,14 @@ public class AuthUtil {
|
|
* @param type
|
|
* @param type
|
|
* @param request
|
|
* @param request
|
|
* @param response
|
|
* @param response
|
|
|
|
+ * @param handler
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
static boolean authFootCommon(long userId,
|
|
static boolean authFootCommon(long userId,
|
|
String type,
|
|
String type,
|
|
HttpServletRequest request,
|
|
HttpServletRequest request,
|
|
- HttpServletResponse response) {
|
|
|
|
|
|
+ HttpServletResponse response,
|
|
|
|
+ Object handler) {
|
|
String url = request.getServletPath();
|
|
String url = request.getServletPath();
|
|
//验证权限
|
|
//验证权限
|
|
AuthBean authBean = type.contains(SystemConstant.USER_OAUTH_CACHE) ? authBean = cacheService.userAuthCache(userId) : null;
|
|
AuthBean authBean = type.contains(SystemConstant.USER_OAUTH_CACHE) ? authBean = cacheService.userAuthCache(userId) : null;
|
|
@@ -159,6 +166,16 @@ public class AuthUtil {
|
|
if (sysCount > 0) {
|
|
if (sysCount > 0) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+ HandlerMethod handlerMethod = (HandlerMethod) handler;
|
|
|
|
+ Map<String, Boolean> map = new HashMap<>();
|
|
|
|
+ Aac beanTypeAac = handlerMethod.getBeanType().getAnnotation(Aac.class);
|
|
|
|
+ Aac classAac = handlerMethod.getMethodAnnotation(Aac.class);
|
|
|
|
+ map.computeIfAbsent("auth", v -> beanTypeAac.auth() == BOOL.TRUE ? true : false);
|
|
|
|
+ map.computeIfAbsent("auth", v -> classAac.auth() == BOOL.TRUE ? true : false);
|
|
|
|
+
|
|
|
|
+ if (Objects.nonNull(map.get("auth")) && !map.get("auth")) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
Set<String> urls = authBean.getUrls();
|
|
Set<String> urls = authBean.getUrls();
|
|
int privilegeCount = Objects.nonNull(urls) ? (int) urls.stream().filter(s -> s.equalsIgnoreCase(url)).count() : 0;
|
|
int privilegeCount = Objects.nonNull(urls) ? (int) urls.stream().filter(s -> s.equalsIgnoreCase(url)).count() : 0;
|
|
if (privilegeCount == 0) {
|
|
if (privilegeCount == 0) {
|