shiro认证过程,怎样做才会走realm的认证方法
时间: 2023-07-24 14:08:05 浏览: 164
在Shiro中,当一个用户尝试登录时,Shiro会将用户名和密码传递给一个被称为“Realm”的组件进行身份认证。Realm是一个可以自定义的组件,你可以根据自己的需求来实现自己的Realm,以满足不同的身份认证需求。
要使Shiro走Realm的认证方法,需要在Shiro的配置文件中配置Realm。具体步骤如下:
1. 创建自定义的Realm类,该类需要继承org.apache.shiro.realm.AuthenticatingRealm类,并实现其doGetAuthenticationInfo(AuthenticationToken token)方法,用于验证用户的身份。
2. 在shiro.ini配置文件中配置Realm,如下所示:
```
[main]
# 配置自定义的Realm
myRealm = com.example.MyRealm
# 配置SecurityManager,指定使用myRealm进行身份验证
securityManager.realms = $myRealm
```
这样配置后,当用户进行身份验证时,Shiro会根据配置的Realm进行验证,而不是默认的身份验证方式。
相关问题
鉴权 shiro realm
在Shiro中,Realm是用于验证用户身份和授权的组件。Realm是一个接口,用于定义如何从数据源(如数据库、LDAP、文件等)中获取用户身份和权限信息。Realm通常用于与后端数据源进行交互,以验证用户的身份和授权。Shiro提供了许多默认的Realm实现,例如JDBC Realm、LDAP Realm和Properties Realm等。此外,Shiro还支持自定义Realm实现,以满足特定的业务需求。在自定义Realm时,需要实现Realm接口中的方法,包括获取用户身份信息、获取用户权限信息等。通过配置Shiro安全管理器的Realm属性,可以将自定义Realm与Shiro集成,实现对用户身份和权限的验证。
shiro中的realm
在Shiro(Apache Shiro,一个开源的身份管理和权限管理框架)中,Realm是一个核心组件,它是访问控制策略的核心部分,负责实际的认证(Authentication)和授权(Authorization)。每个Realm都是一个实现了特定接口如`org.apache.shiro.authc.AuthenticationInfoProvider`或`org.apache.shiro.authorization.AuthorizationInfoProvider`的对象。
当用户尝试访问受保护的资源时,Shiro会首先通过SecurityManager找到配置的Realm并请求身份验证信息。Realm通常从数据源如数据库、文件、甚至是自定义的逻辑中获取用户的凭据(如用户名和密码),然后进行验证。如果验证成功,它将返回包含用户标识和角色等信息的`AuthenticationInfo`对象。
对于授权,Realm同样提供了一个授权决策过程,生成`AuthorizationInfo`,包括用户所拥有的权限列表。这些权限信息会被用来确定用户是否有权访问特定的资源或执行某项操作。
Shiro支持多种类型的Realm,例如BasicAuthorizingRealm、DatabaseRealm、HashingLoginModule Realm等,可以根据应用的具体需求选择合适的 Realm 实现。
阅读全文
相关推荐
















