Apache Shiro入门教程:简单介绍与配置

版权申诉
0 下载量 66 浏览量 更新于2024-07-06 收藏 815KB PPTX 举报
Apache Shiro是一个全面的、易于理解的安全框架,它专注于身份验证、授权、会话管理和加密等核心功能。这个框架的设计理念是简洁和易用,使得开发者可以快速地集成到现有项目中,无论项目规模大小。以下是对Shiro关键概念和功能的详细说明: 1. **身份验证(Authentication)**:这是用户登录的过程,Shiro提供了接口和实现来验证用户的身份。开发者可以通过自定义凭证匹配器(CredentialsMatcher)和 Realm(用户数据源)来适配各种认证策略,如用户名+密码、数字证书等。 2. **授权(Authorization)**:授权是确定用户是否有权限执行特定操作或访问特定资源。Shiro支持基于角色的访问控制(RBAC),可以轻松检查用户是否拥有特定角色(如“admin”)或权限。此外,还可以通过注解、配置文件等方式进行细粒度的权限控制。 3. **会话管理(Session Management)**:Shiro不仅支持Web环境下的会话管理,还能在非Web环境中(如Java桌面应用)使用。它允许跨域共享会话,解决CS(客户端-服务器)程序中的会话一致性问题。 4. **加密(Cryptography)**:Shiro封装了复杂的加密算法,提供了一套简单易用的API,包括密码加密、消息摘要等,确保敏感数据的安全性。 5. **单点登录(Single Sign-On, SSO)**:Shiro支持单点登录功能,用户在一个系统登录后,可以在其他关联的系统中自动登录,无需再次输入凭证。 6. **Remember Me服务**:类似于购物车功能,Remember Me服务可以在用户选择记住登录状态后,下次访问时自动登录用户,提高用户体验。Shiro官方建议开启此功能。 7. **其他扩展功能**:Shiro还提供了Web支持,如过滤器实现Web安全控制;缓存管理,提升性能;并发处理,适应多线程环境;测试工具,便于单元测试;以及“RunAs”机制,允许用户暂时以其他身份进行操作。 8. **Subject与SecurityManager**:Subject是Shiro的中心概念,代表了当前用户,是用户与Shiro框架交互的接口。SecurityManager则是Shiro的核心组件,负责管理所有的Subject并协调它们与其他组件之间的交互。在实际应用中,我们主要通过Subject进行操作,而SecurityManager在后台默默地处理Subject的请求。 通过这些特性,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 上传