|
@@ -8,6 +8,7 @@ import org.aspectj.lang.JoinPoint;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.DefaultParameterNameDiscoverer;
|
|
|
import org.springframework.core.ParameterNameDiscoverer;
|
|
|
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
|
import org.springframework.web.context.request.RequestAttributes;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
@@ -15,6 +16,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -33,10 +35,15 @@ public class PermissionUtil {
|
|
|
* @param joinPoint
|
|
|
* @param sysType
|
|
|
*/
|
|
|
- public static void permissionAspect(JoinPoint joinPoint, Integer sysType) {
|
|
|
+ public static void permissionAspect(JoinPoint joinPoint, Integer sysType, List<String> ignoreUrl) {
|
|
|
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
|
|
|
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
|
|
|
HttpServletRequest request = sra.getRequest();
|
|
|
+ //忽略机制
|
|
|
+ if (matchPermitAllUrl(request,ignoreUrl)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //验证机制
|
|
|
//head里面是否有hospitalCode;
|
|
|
String hospitalCode = request.getHeader("hospitalCode");
|
|
|
if (StringUtil.isBlank(hospitalCode)) {
|
|
@@ -106,4 +113,24 @@ public class PermissionUtil {
|
|
|
put("java.lang.Char", char.class);
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+ private static Boolean matchPermitAllUrl(HttpServletRequest request, List<String> ignoreUrl) {
|
|
|
+ if (ListUtil.isNotEmpty(ignoreUrl)) {
|
|
|
+ for (String url : ignoreUrl) {
|
|
|
+ if (matchers(url, request)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Boolean matchers(String url, HttpServletRequest request) {
|
|
|
+ AntPathRequestMatcher matcher = new AntPathRequestMatcher(url);
|
|
|
+ if (matcher.matches(request)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|