|
|
@@ -0,0 +1,40 @@
|
|
|
+package com.kede.core.shiro.filter;
|
|
|
+
|
|
|
+import com.kede.common.utils.LoggerUtils;
|
|
|
+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 javax.servlet.ServletRequest;
|
|
|
+import javax.servlet.ServletResponse;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+public class DeviceFilter extends AccessControlFilter{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ShiroFilterUtils shiroFilterUtils;
|
|
|
+
|
|
|
+
|
|
|
+ private static String mobileWebsite="m.kedexinxi.com";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
|
|
|
+ throws Exception {
|
|
|
+ if (!shiroFilterUtils.isFromAPP((HttpServletRequest)request) && shiroFilterUtils.isMobileDevice((HttpServletRequest)request)
|
|
|
+ && !request.getServerName().startsWith("m")){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
|
|
+ if (!shiroFilterUtils.isFromAPP((HttpServletRequest)request) && shiroFilterUtils.isMobileDevice((HttpServletRequest)request)
|
|
|
+ && !request.getServerName().startsWith("m")){
|
|
|
+ LoggerUtils.debug(getClass(), "当前访问为移动设备");
|
|
|
+ WebUtils.issueRedirect(request, response, mobileWebsite,null,false);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|