Shiro入门教程:快速掌握Java安全框架

5星 · 超过95%的资源 需积分: 29 60 下载量 56 浏览量 更新于2024-07-21 收藏 4.16MB PDF 举报
Apache Shiro教程是一份针对Java开发者的实用指南,它专注于介绍Apache Shiro框架的基础使用,而不是深入源码分析。Shiro以其简单易用的特点区别于功能强大的Spring Security,适合那些在实际项目中寻求轻量级安全解决方案的开发者。本教程主要覆盖以下几个关键部分: 1. **SHIRO简介**:首先介绍了Shiro的基本概念,包括它的作用和优势,以及与Spring Security的对比,强调了在选择时关注实用性而非复杂性。 2. **身份验证**:这一章节详细讲解了身份验证的环境准备,登录和退出机制,以及身份认证流程,涉及到REALM(安全管理器)的概念,以及AUTHENTICATOR(身份验证器)和AUTHENTICATIONSTRATEGY(身份验证策略)的使用。 3. **授权**:讲解了不同的授权方式,包括PERMISSION(权限),并阐述了授权流程,涉及到了AUTHORIZER(授权器)、PERMISSIONRESOLVER(权限解析器)和ROLEPERMISSIONRESOLVER(角色权限解析器)的角色。 4. **INI配置**:这部分介绍了如何通过INIs(Ini格式配置文件)来配置核心对象如SECURITYMANAGER,以及如何进行具体的配置。 5. **编码/加密**:涉及密码的编码和解码,以及散列算法和加密/解密,还会提到PASSWORDSERVICE/CREDENTIALSMATCHER(密码服务/凭证匹配器)的作用。 6. **REALM及相关对象**:深入剖析了REALM(领域)和与之相关的对象,如AUTHENTICATIONTOKEN(认证令牌)、AUTHENTICATIONINFO(认证信息)、PRINCIPALCOLLECTION(主体集合)和AUTHORIZATIONINFO(授权信息)等。 7. **Web集成**:这部分讲述了如何将Shiro与Web应用集成,包括环境准备、SHIROFILTER(过滤器)的使用,以及Web INI配置。 8. **拦截器机制**:讲解拦截器的工作原理、拦截器链的构建,以及自定义拦截器的编写和默认拦截器的使用。 9. **JSP标签**:展示了如何在JSP页面中利用Shiro提供的标签进行开发。 10. **会话管理**:涉及会话的概念,会话管理器的使用,会话监听器,以及会话存储、持久化和验证。 11. **缓存机制**:讨论了REALM和SESSION(会话)缓存的应用。 12. **与Spring集成**:对于两种不同类型的Java应用(JAVASE和WEB应用),介绍了如何在Shiro中使用Spring的权限注解。 这份教程旨在帮助开发者快速上手Apache Shiro,并在实际项目中实现基本的安全功能。通过学习,开发者可以掌握Shiro的核心组件和配置方法,以提升应用程序的安全性。

SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details. Exception in thread "main" org.apache.shiro.config.ConfigurationException: Unable to instantiate class [org.apache.shiro.web.mgt.DefaultWebSecurityManager] for object named 'securityManager'. Please ensure you've specified the fully qualified class name correctly. at org.apache.shiro.config.ReflectionBuilder.createNewInstance(ReflectionBuilder.java:309) at org.apache.shiro.config.ReflectionBuilder$InstantiationStatement.doExecute(ReflectionBuilder.java:927) at org.apache.shiro.config.ReflectionBuilder$Statement.execute(ReflectionBuilder.java:887) at org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:765) at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:260) at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:167) at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:130) at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:108) at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:94) at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:46) at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:123) at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47) at com.xiu.Quickstart.main(Quickstart.java:26) Caused by: org.apache.shiro.util.UnknownClassException: Unable to load class named [org.apache.shiro.web.mgt.DefaultWebSecurityManager] from the thread context, current, or system/application ClassLoaders. All heuristics have been exhausted. Class could not be found. at org.apache.shiro.util.ClassUtils.forName(ClassUtils.java:152) at org.apache.shiro.util.ClassUtils.newInstance(ClassUtils.java:168) at org.apache.shiro.config.ReflectionBuilder.createNewInstance(ReflectionBuilder.java:302) ... 12 more

2023-06-10 上传