wanghui пре 7 година
родитељ
комит
b57461ec1b

+ 44 - 0
src/main/java/com/goafanti/core/shiro/filter/DeviceFilter.java

@@ -0,0 +1,44 @@
+package com.goafanti.core.shiro.filter;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+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.goafanti.common.utils.LoggerUtils;
+
+
+public class DeviceFilter extends  AccessControlFilter{
+
+	@Autowired
+	private ShiroFilterUtils shiroFilterUtils;
+	
+	@Value(value = "${app.mobile.website}")
+	private String mobileWebsite;
+	
+	@Override
+	protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
+			throws Exception {
+		// TODO Auto-generated method stub
+		if (shiroFilterUtils.isMobileDevice((HttpServletRequest)request) || request.getServerName().indexOf("m.") > 0){
+			return false;
+		}
+		return true;
+	}
+
+	@Override
+	protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
+		// TODO Auto-generated method stub
+		if (shiroFilterUtils.isMobileDevice((HttpServletRequest)request) || request.getServerName().indexOf("m.") > 0){
+			LoggerUtils.debug(getClass(), "当前访问为移动设备");
+			WebUtils.issueRedirect(request, response, mobileWebsite,null,false);
+		}
+		return false;
+	}
+
+	
+}

+ 1 - 7
src/main/java/com/goafanti/core/shiro/filter/PermissionFilter.java

@@ -21,9 +21,6 @@ public class PermissionFilter extends AccessControlFilter {
 
 	@Autowired
 	private ShiroFilterUtils shiroFilterUtils;
-	
-	@Value("app.mobile.website")
-	private String mobileWebsite;
 
 	@Override
 	protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
@@ -48,10 +45,7 @@ public class PermissionFilter extends AccessControlFilter {
 	@Override
 	protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
 		Subject subject = getSubject(request, response);
-		if (shiroFilterUtils.isMobileDevice((HttpServletRequest)request) || request.getServerName().indexOf("m.") > 0){
-			LoggerUtils.debug(getClass(), "当前访问为移动设备");
-			WebUtils.issueRedirect(request, response, mobileWebsite);
-		}else if (shiroFilterUtils.isAjax((HttpServletRequest) request)) {
+		if (shiroFilterUtils.isAjax((HttpServletRequest) request)) {
 			LoggerUtils.debug(getClass(), "当前用户权限不够,并且是Ajax请求!");
 			shiroFilterUtils.out((HttpServletResponse) response, new Result().error(new Error("", "403", "当前用户权限不够!")));
 		} else if (null == subject.getPrincipal()) {

+ 1 - 1
src/main/java/com/goafanti/core/shiro/filter/ShiroFilterUtils.java

@@ -42,7 +42,7 @@ public class ShiroFilterUtils {
         if(request.getHeader("User-Agent") != null){
         	String agent = request.getHeader("User-Agent");
         	for(int i = 0; i<deviceArray.length; i++){
-        		if(agent.indexOf(deviceArray[i]) >0 ){
+        		if(agent.toLowerCase().indexOf(deviceArray[i]) >0 ){
         			return true;
         		}
         	} 	

+ 1 - 1
src/main/resources/props/config_local.properties

@@ -52,7 +52,7 @@ session.timeout=12000000
 session.validate.timespan=18000000
 
 app.name=AFT
-app.mobile.website=m.kedexinxi.com
+app.mobile.website=http://m.kedexinxi.com
 template.cacheable=false
 
 static.host=//sclient.jishutao.com/client/1.0.0

+ 1 - 1
src/main/resources/props/config_test.properties

@@ -53,7 +53,7 @@ session.timeout=12000000
 session.validate.timespan=18000000
 
 app.name=AFT
-app.mobile.website=m.kedexinxi.com
+app.mobile.website=http://m.kedexinxi.com
 template.cacheable=false
 
 static.host=//statics.jishutao.com/client/1.0.0

+ 2 - 2
src/main/resources/shiro_base_auth.ini

@@ -1,5 +1,5 @@
 [base_auth]
-/=anon
+/=device
 /index=anon
 /login=anon
 /user/login.html=anon
@@ -16,7 +16,7 @@
 /open/**=anon
 /favicon.ico=anon
 /static/**=anon
-/portal/**=anon
+/portal/**=device
 /api/portal/**=anon
 /api/admin/**=admin
 /api/user/**=login

+ 3 - 0
src/main/resources/spring/spring-shiro.xml

@@ -160,6 +160,9 @@
 						<property name="loginUrl" value="/admin/login" />
 					</bean>
 				</entry>
+				<entry key="device">
+					<bean id="device" class="com.goafanti.core.shiro.filter.DeviceFilter"></bean>
+				</entry>
 			</util:map>
 		</property>
 	</bean>

Разлика између датотеке није приказан због своје велике величине
+ 1 - 1
src/main/webapp/WEB-INF/views/portal/aboutUs.html