日期:2014-05-16  浏览次数:20922 次

Apache Shiro 标签模式授权

Apache Shiro 标签方式授权

Shiro提供了一套JSP标签库来实现页面级的授权控制。?

在使用Shiro标签库前,首先需要在JSP引入shiro标签:?

<%@?taglib?prefix="shiro"?uri="http://shiro.apache.org/tags"?%>

下面一一介绍Shiro的标签:?

guest标签?

验证当前用户是否为“访客”,即未认证(包含未记住)的用户。

<shiro:guest>??

Hi?there!??Please?<a?href="login.jsp">Login</a>?or?<a?href="signup.jsp">Signup</a>?today!??

</shiro:guest>

?

user标签?

认证通过或已记住的用户。

<shiro:user>??

????Welcome?back?John!??Not?John??Click?<a?href="login.jsp">here<a>?to?login.??

</shiro:user>

?

authenticated标签?

已认证通过的用户。不包含已记住的用户,这是与user标签的区别所在。?

<shiro:authenticated>??

????<a?href="updateAccount.jsp">Update?your?contact?information</a>.??

</shiro:authenticated>

?

notAuthenticated标签?

未认证通过用户,与authenticated标签相对应。与guest标签的区别是,该标签包含已记住用户。?

<shiro:notAuthenticated>??

????Please?<a?href="login.jsp">login</a>?in?order?to?update?your?credit?card?information.??

</shiro:notAuthenticated>

?

principal?标签?

输出