} else {
log.info(\"Sorry, lightsaber rings are for schwartz masters only.\");
}
当然,还可以进行功能强大的实例级别的权限验证。通过它可以判断用户是否有访问特定类型实例的权限:
if ( currentUser.isPermitted( \"winnebago:drive:eagle5\" ) ) {
log.info(\"You are permitted to \'drive\' the \'winnebago\' with license plate (id) \'eagle5\'. \" +\"Here are the keys - have fun!\");
} else {
log.info(\"Sorry, you aren\'t allowed to drive the \'eagle5\' winnebago!\");
}
小菜一碟,对吧。
最后,当用户使用完毕,还可以退出应用。
currentUser.logout(); //removes all identifying information and invalidates their session too.
这些就是使用Apache Shiro开发应用的核心了,当然,Apache Shiro已将将很多复杂的东西封装在内部了,但是现在它就是这么简单。
你会有疑问吧,用户登录时,谁负责把用户信息(用户名、密码、角色、权限等)取出来,还有运行时,谁负责安全认证呢?当然由你决定了啊。通过将一个实现了Shiro中的Realm的Reaml配置到Shiro中即可。
至于如何配置很大程度上取决于你的运行时环境,比如在单应用、web应用、基于Spring或JEE 容器的应用或者组合模式中使用Shiro,配置都有所不同。如何配置已经超出QuickStart示例的范围,因为它的主要目的是帮助你熟悉Shiro的API和概念。
如果想进一步了解Shiro,可以看看Authentication Guide和Authorization Guide。也可以查看其他文档(特别是Reference Manual),这里可以解决你的各种疑问。
转自:http://www.turingbook.com/article/details/163
相关文章阅读及下载:
《Shiro1.1.0开发配置文档》
《应用Shiro到Web Application》
《Apache Shiro 使用手册》
《10分钟教会你Apache Shiro》
更多Apache Shiro文档,尽在开卷有益360