关于Shiro的 表单认证

最近有个项目需要,采用安全认证控件。 原本想用SS,刚好看到网友在讨论一个新的安全框架。Apache Shiro,看了一下官方文档,觉得还不错。 干脆就一试。 发现,还有很多小细节,官网没有给出。可能是刚刚从JSecurity接手,也刚出到1.2,还没有太多资源。

在此,根据本项目实践。 将这个新的安全框架中遇到的问题。一一罗列。 仅供参考。

今天发现,采用Form 过滤器认证,需要采用“POST”方法,这个是启动表单认证的条件。在源码中有写到。

/**
174      * This default implementation merely returns <code>true</code> if the request is an HTTP <code>POST</code>,
175      * <code>false</code> otherwise. Can be overridden by subclasses for custom login submission detection behavior.
176      *
177      * @param request  the incoming ServletRequest
178      * @param response the outgoing ServletResponse.
179      * @return <code>true</code> if the request is an HTTP <code>POST</code>, <code>false</code> otherwise.
180      */
181     @SuppressWarnings({"UnusedDeclaration"})
182     protected boolean isLoginSubmission(ServletRequest request, ServletResponse response) {
183         return (request instanceof HttpServletRequest) && WebUtils.toHttp(request).getMethod().equalsIgnoreCase(POST_METHOD);
184     }
185 



Shiro的登录默认页为login.jsp ,成功登录跳转页面为"/",退出登录,只需要指定该路径为logout过滤器即可。 这些也可以在ini配置中修改。
[main]
authc.successUrl=/content.html
authc.loginUrl=/log.jsp
[users]
admin= admin

[urls]
/index.html = anon
/logout=logout
/** = authc

猜你喜欢

转载自westlife2011.iteye.com/blog/1542773