shiro多realm认证(七)

                               Authenticator

•  Authenticator 的职责是验证用户帐号,是Shiro API 中身份验证核心的入口点:如果验证成功,将返回AuthenticationInfo 验证信息;此信息中包含了身份及凭证;如果验证失败将抛出相应的AuthenticationException 异 常

•  SecurityManager 接口继承了 Authenticator,另外还有一个ModularRealmAuthenticator实现,其委托给多个Realm进行

验证,验证规则通过 AuthenticationStrategy 接口指定


AuthenticationStrategy

•        AuthenticationStrategy 接口的默认实现:

•        FirstSuccessfulStrategy:只要有一个 Realm 验证成功即可,只返回第

一个 Realm 身份验证成功的认证信息,其他的忽略;

•        AtLeastOneSuccessfulStrategy:只要有一个Realm验证成功即可,和FirstSuccessfulStrategy不同,将返回所有Realm身份验证成功的认证信息;

•        AllSuccessfulStrategy:所有Realm验证成功才算成功,且返回所有

Realm身份验证成功的认证信息,如果有一个失败就失败了。

•        ModularRealmAuthenticator 默认是 AtLeastOneSuccessfulStrategy策略

 <!--  
    1. 配置 SecurityManager!
    -->     
    <bean id=" securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="cacheManager" ref="cacheManager"/>
        <property name="authenticator" ref=" authenticator"></property>
        
        <property name=" realms">
        <list>
    <ref bean=" jdbcRealm"/>
    <ref bean=" secondRealm"/>
    </list>
        </property>
        
        <property name="rememberMeManager.cookie.maxAge" value="10"></property>
    </bean>

3. 配置 Realm 
    3.1 直接配置实现了 org.apache.shiro.realm.Realm 接口的 bean
    -->     
    <bean id="jdbcRealm" class="com.atguigu.shiro.realms.ShiroRealm">
    <property name="credentialsMatcher">
    <bean class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
    <property name="hashAlgorithmName" value="MD5"></property>
    <property name="hashIterations" value="1024"></property>
    </bean>
    </property>
    </bean>
    
    <bean id="secondRealm" class="com.atguigu.shiro.realms.SecondRealm">
    <property name="credentialsMatcher">
    <bean class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
    <property name="hashAlgorithmName" value="SHA1"></property>
    <property name="hashIterations" value="1024"></property>
    </bean>
    </property>
    </bean>

<bean id="authenticator"
class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">
<property name="authenticationStrategy">
<!-- 配置认证策略 -->
<bean class="org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy"></bean>
</property>
</bean>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值