AuthenticationInfo有两个作用:
1)如果Realm 是AuthenticatingRealm 子类(包括AuthorizingRealm,它继承AuthenticationRealm),则提供给AuthenticatingRealm 内部使用的CredentialsMatcher进行凭据验证;(如果没有继承它需要在自己的Realm中自己实现验证);
2)提供给SecurityManager来创建Subject(提供身份信息);
MergableAuthenticationInfo 用于提供在多Realm 时合并AuthenticationInfo 的功能,主要合并Principal、如果是其他的如credentialsSalt,会用后边的信息覆盖前边的。
比如HashedCredentialsMatcher , 在验证时会判断AuthenticationInfo 是否是SaltedAuthenticationInfo子类,来获取盐信息。
Account相当于我们之前的User,SimpleAccount是其一个实现;在IniRealm、PropertiesRealm这种静态创建帐号信息的场景中使用,这些Realm 直接继承SimpleAccountRealm,而SimpleAccountRealm 提供了相关的API 来动态维护SimpleAccount;即可以通过这些API来动态增删改查SimpleAccount;动态增删改查角色/权限信息。及如果您的帐号不是特别多,可以使用这种方式,具体请参考SimpleAccountRealm Javadoc。
其他情况一般返回SimpleAuthenticationInfo即可
Shiro认证与授权机制
本文介绍了Shiro框架中的认证与授权机制,重点讲解了AuthenticationInfo的作用及其在多Realm环境下的合并策略。此外还介绍了SimpleAccount及其在IniRealm和PropertiesRealm中的应用。
 AuthenticationInfo&spm=1001.2101.3001.5002&articleId=77512887&d=1&t=3&u=e665184d649543f39036c1821cacf559)
947

被折叠的 条评论
为什么被折叠?



