Commit bc68fb13 by zhanghj

V1.0.0--修复用户登录超时请求用户中心,没返回状态码bug

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@18458 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent ae417d50
...@@ -22,6 +22,7 @@ import org.springframework.context.annotation.Bean; ...@@ -22,6 +22,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.glsx.usercenter.constants.Constants; import com.glsx.usercenter.constants.Constants;
import com.glsx.usercenter.filter.AuthFilter;
import com.glsx.usercenter.shiro.UserRealm; import com.glsx.usercenter.shiro.UserRealm;
/** /**
...@@ -92,9 +93,12 @@ public class ShiroConfig { ...@@ -92,9 +93,12 @@ public class ShiroConfig {
// Shiro的核心安全接口,这个属性是必须的 // Shiro的核心安全接口,这个属性是必须的
shiroFilterFactoryBean.setSecurityManager(securityManager); shiroFilterFactoryBean.setSecurityManager(securityManager);
// 身份认证失败,则跳转到登录页面的配置 // 身份认证失败,则跳转到登录页面的配置
shiroFilterFactoryBean.setLoginUrl(unauthorizedUrl); //shiroFilterFactoryBean.setLoginUrl(unauthorizedUrl);
// 权限认证失败,则跳转到指定页面 // 权限认证失败,则跳转到指定页面
shiroFilterFactoryBean.setUnauthorizedUrl(unauthorizedUrl); //shiroFilterFactoryBean.setUnauthorizedUrl(unauthorizedUrl);
Map<String,Filter> filters = shiroFilterFactoryBean.getFilters();
filters.put("authc", new AuthFilter());
shiroFilterFactoryBean.setFilters(filters);
// Shiro连接约束配置,即过滤链的定义 // Shiro连接约束配置,即过滤链的定义
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
...@@ -122,7 +126,7 @@ public class ShiroConfig { ...@@ -122,7 +126,7 @@ public class ShiroConfig {
// 系统权限列表 // 系统权限列表
// filterChainDefinitionMap.putAll(SpringUtils.getBean(IMenuService.class).selectPermsAll()); // filterChainDefinitionMap.putAll(SpringUtils.getBean(IMenuService.class).selectPermsAll());
Map<String, Filter> filters = new LinkedHashMap<>(); //Map<String, Filter> filters = new LinkedHashMap<>();
// 注销成功,则跳转到指定页面 // 注销成功,则跳转到指定页面
//filters.put("logout", logoutFilter()); //filters.put("logout", logoutFilter());
//shiroFilterFactoryBean.setFilters(filters); //shiroFilterFactoryBean.setFilters(filters);
......
package com.glsx.usercenter.filter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.shiro.web.filter.authc.UserFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.glsx.usercenter.constants.ResultCodeEnum;
/**
*
* @Title AuthFilter.java
* @Package com.glsx.usercenter.filter
* @Description TODO shiro用户登录超时拦截器
* @author zhanghj
* @date 2019年3月12日 下午5:27:22
* @version 1.0.0
*/
public class AuthFilter extends UserFilter{
private Logger logger = LoggerFactory.getLogger(AuthFilter.class);
@Override
protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
PrintWriter out = null;
Map<String, Object> result = new HashMap<String, Object>();
result.put("code", ResultCodeEnum.NOT_LOGIN.getCode());
result.put("msg", ResultCodeEnum.NOT_LOGIN.getMsg());
try {
response.setContentType("application/json;charset=utf-8");
out = response.getWriter();
out.print(JSON.toJSON(result));
} catch (IOException e) {
logger.error("shiro用户登录超时拦截器,获取PrintWriter异常", e);
} finally{
if(out != null){
out.close();
}
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!