Commits

conanca committed 7069e2f

登出弃用过滤器方式

  • Participants
  • Parent commits b454ac4

Comments (0)

Files changed (2)

File src/main/java/com/dolplay/nutzshiro/filter/LogoutFilter.java

-package com.dolplay.nutzshiro.filter;
-
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.session.SessionException;
-import org.apache.shiro.subject.Subject;
-import org.nutz.lang.Strings;
-import org.nutz.mvc.ActionContext;
-import org.nutz.mvc.ActionFilter;
-import org.nutz.mvc.View;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class LogoutFilter implements ActionFilter {
-	private static Logger logger = LoggerFactory.getLogger(LogoutFilter.class);
-
-	public static final String DEFAULT_LOGOUT_URL = "/logout";
-	private String logoutUrl = DEFAULT_LOGOUT_URL;
-
-	@Override
-	public View match(ActionContext actionContext) {
-
-		String path = actionContext.getPath();
-		if (!Strings.isEmpty(path) && path.equals(logoutUrl)) {
-
-			Subject currentUser = SecurityUtils.getSubject();
-			try {
-				currentUser.logout();
-			} catch (SessionException ise) {
-				logger.debug("Encountered session exception during logout.  This can generally safely be ignored.", ise);
-				return null;
-			}catch(Exception e){
-				logger.debug("登出发生错误",e);
-				return null;
-			}
-		}
-
-		return null;
-	}
-}

File src/main/java/com/dolplay/nutzshiro/module/SystemModule.java

 package com.dolplay.nutzshiro.module;
 
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.session.SessionException;
+import org.apache.shiro.subject.Subject;
 import org.nutz.ioc.annotation.InjectName;
 import org.nutz.ioc.loader.annotation.IocBean;
 import org.nutz.mvc.annotation.At;
 import org.nutz.mvc.annotation.By;
 import org.nutz.mvc.annotation.Filters;
 import org.nutz.mvc.annotation.Ok;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.dolplay.nutzshiro.filter.AuthenticationFilter;
-import com.dolplay.nutzshiro.filter.LogoutFilter;
 
 @IocBean
 @InjectName
+@Filters
 public class SystemModule {
+	private static Logger logger = LoggerFactory.getLogger(SystemModule.class);
 
 	@At("/login")
 	@Ok(">>:/")
 
 	@At("/logout")
 	@Ok(">>:/")
-	@Filters({ @By(type = LogoutFilter.class) })
 	public void logout() {
-
+		Subject currentUser = SecurityUtils.getSubject();
+		try {
+			currentUser.logout();
+		} catch (SessionException ise) {
+			logger.debug("Encountered session exception during logout.  This can generally safely be ignored.", ise);
+		} catch (Exception e) {
+			logger.debug("登出发生错误", e);
+		}
 	}
 }