Ver Fonte

防止匿名访问进行过滤

RuoYi há 4 anos atrás
pai
commit
3f114ccc15

+ 2 - 3
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ShiroConfig.java

@@ -309,28 +309,27 @@ public class ShiroConfig
     /**
      * 自定义在线用户处理过滤器
      */
-    @Bean
     public OnlineSessionFilter onlineSessionFilter()
     {
         OnlineSessionFilter onlineSessionFilter = new OnlineSessionFilter();
         onlineSessionFilter.setLoginUrl(loginUrl);
+        onlineSessionFilter.setOnlineSessionDAO(sessionDAO());
         return onlineSessionFilter;
     }
 
     /**
      * 自定义在线用户同步过滤器
      */
-    @Bean
     public SyncOnlineSessionFilter syncOnlineSessionFilter()
     {
         SyncOnlineSessionFilter syncOnlineSessionFilter = new SyncOnlineSessionFilter();
+        syncOnlineSessionFilter.setOnlineSessionDAO(sessionDAO());
         return syncOnlineSessionFilter;
     }
 
     /**
      * 自定义验证码过滤器
      */
-    @Bean
     public CaptchaValidateFilter captchaValidateFilter()
     {
         CaptchaValidateFilter captchaValidateFilter = new CaptchaValidateFilter();

+ 5 - 2
ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/web/filter/online/OnlineSessionFilter.java

@@ -7,7 +7,6 @@ import org.apache.shiro.session.Session;
 import org.apache.shiro.subject.Subject;
 import org.apache.shiro.web.filter.AccessControlFilter;
 import org.apache.shiro.web.util.WebUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import com.ruoyi.common.constant.ShiroConstants;
 import com.ruoyi.common.core.domain.entity.SysUser;
@@ -29,7 +28,6 @@ public class OnlineSessionFilter extends AccessControlFilter
     @Value("${shiro.user.loginUrl}")
     private String loginUrl;
 
-    @Autowired
     private OnlineSessionDAO onlineSessionDAO;
 
     /**
@@ -93,4 +91,9 @@ public class OnlineSessionFilter extends AccessControlFilter
     {
         WebUtils.issueRedirect(request, response, loginUrl);
     }
+
+    public void setOnlineSessionDAO(OnlineSessionDAO onlineSessionDAO)
+    {
+        this.onlineSessionDAO = onlineSessionDAO;
+    }
 }

+ 5 - 2
ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/web/filter/sync/SyncOnlineSessionFilter.java

@@ -3,7 +3,6 @@ package com.ruoyi.framework.shiro.web.filter.sync;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import org.apache.shiro.web.filter.PathMatchingFilter;
-import org.springframework.beans.factory.annotation.Autowired;
 import com.ruoyi.common.constant.ShiroConstants;
 import com.ruoyi.framework.shiro.session.OnlineSession;
 import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
@@ -15,7 +14,6 @@ import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
  */
 public class SyncOnlineSessionFilter extends PathMatchingFilter
 {
-    @Autowired
     private OnlineSessionDAO onlineSessionDAO;
 
     /**
@@ -33,4 +31,9 @@ public class SyncOnlineSessionFilter extends PathMatchingFilter
         }
         return true;
     }
+
+    public void setOnlineSessionDAO(OnlineSessionDAO onlineSessionDAO)
+    {
+        this.onlineSessionDAO = onlineSessionDAO;
+    }
 }