apache shiro 自定义过滤器及使用
2012-09-17 14:08
344 查看
public class MyFilter implements Filter { private String myLoginUrl = "/error/4031"; private final String default_content_type = "application/x-www-form-urlencoded"; public void setMyLoginUrl(String myLoginUrl) { this.myLoginUrl = myLoginUrl; } public String getMyLoginUrl() { return myLoginUrl; } @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String contentType = request.getContentType(); Subject currentUser = SecurityUtils.getSubject(); if (!currentUser.isAuthenticated()) { HttpServletResponse res = (HttpServletResponse)response; HttpServletRequest req = (HttpServletRequest)request; if(contentType == null){ res.sendRedirect(req.getContextPath() + "/xx/xx"); return; }else{ PrintWriter out = res.getWriter(); out.print("EXPIRED"); out.flush(); return; } } chain.doFilter(request, response); } @Override public void destroy() { } }
applicationContext-shiro.xml
<!-- Shiro Filter -->
<bean id="bobingFilter" class="com.hymake.bobing.util.BobingSessionTimeOut" />
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean" depends-on="myFilter"> <property name="securityManager" ref="securityManager" /> <property name="loginUrl" value="/login" /> <property name="successUrl" value="/xx/xx/" /> <property name="filters"> <map> <entry key="myFilter" value-ref="myFilter"/>//1官网说是//1 地方是不用配置的 shiro会自动添加实现了Filter接口的类 </map> </property> <property name="filterChainDefinitions"> <value> /someindex = anon /login = authc /logout = logout /static/** = anon /admin/** = user /account/** = user /some/** = myFilter </value> </property> </bean>
相关文章推荐
- Apache Shiro 权限控制 使用自定义的JdbcRealm(3)
- Apache Shiro 使用手册(一)Shiro架构介绍
- 使用Apache Shiro进行身份认证-LDAP认证
- Apache Shiro 使用手册(四)Realm 实现
- vue自定义过滤器创建和使用方法详解
- Apache Shiro 使用手册(四)Realm 实现
- Apache Shiro 使用手册(四)Realm 实现
- 使用Spring配置shiro时,自定义Realm中属性无法使用注解注入解决办法
- 使用Apache Shiro进行身份认证-Active Directory认证
- springboot集成Shiro,添加自定义filter后shiro的默认filter无法使用
- 在 Visual Studio中 使用Apache Cordova 开发安卓、iOS程序(自定义图标和闪屏)
- Apache Shiro 使用手册(二)Shiro 认证
- Apache Shiro 使用手册(五)Shiro 配置说明
- 使用shiro进行登录校验;自定义realm的实现
- apache 使用htaccess自定义路由机制
- 【Shiro】Apache Shiro架构之自定义realm
- Apache Shiro 使用手册(五)Shiro 配置说明
- JWT生成JsonWebToken登录令牌并使用自定义过滤器验证(包含跨域设置)
- Apache Shiro 使用手册(一)Shiro架构介绍
- Apache Shiro 使用手册(五)Shiro 配置说明