第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

跟我學(xué)shiro這個教程上第二章中2.2那里有個問題,怎么回獲得兩個身份信息的?

跟我學(xué)shiro這個教程上第二章中2.2那里有個問題,怎么回獲得兩個身份信息的?

回首憶惘然 2019-01-17 18:58:46
原代碼: `ini配置文件(shiro-authenticator-all-success.ini) Java代碼 指定securityManager的authenticator實現(xiàn) authenticator=org.apache.shiro.authc.pam.ModularRealmAuthenticator securityManager.authenticator=$authenticator 指定securityManager.authenticator的authenticationStrategy allSuccessfulStrategy=org.apache.shiro.authc.pam.AllSuccessfulStrategy securityManager.authenticator.authenticationStrategy=$allSuccessfulStrategy Java代碼 收藏代碼myRealm1=com.github.zhangkaitao.shiro.chapter2.realm.MyRealm1 myRealm2=com.github.zhangkaitao.shiro.chapter2.realm.MyRealm2 myRealm3=com.github.zhangkaitao.shiro.chapter2.realm.MyRealm3 securityManager.realms=$myRealm1,$myRealm3 ` 2.1、首先通用化登錄邏輯 Java代碼 收藏代碼 private void login(String configFile) { //1、獲取SecurityManager工廠,此處使用Ini配置文件初始化SecurityManager Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory(configFile); //2、得到SecurityManager實例 并綁定給SecurityUtils org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); //3、得到Subject及創(chuàng)建用戶名/密碼身份驗證Token(即用戶身份/憑證) Subject subject = SecurityUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken("zhang", "123"); subject.login(token); } 2.2、測試AllSuccessfulStrategy成功: Java代碼 收藏代碼 @Test public void testAllSuccessfulStrategyWithSuccess() { login("classpath:shiro-authenticator-all-success.ini"); Subject subject = SecurityUtils.getSubject(); //得到一個身份集合,其包含了Realm驗證成功的身份信息 PrincipalCollection principalCollection = subject.getPrincipals(); Assert.assertEquals(2, principalCollection.asList().size()); } 即PrincipalCollection包含了zhang和zhang@163.com身份信息。 github上的代碼我也弄下來了,確實是兩條身份信息,但是我自己跟著寫的怎么是一條呢?沒有那個zhangsan@163.comzhe'tiao 原文鏈接 我自己的: /** * 通用化登陸邏輯 */ private void login(String configFile) { //獲取安安全管理器工廠 Factory<SecurityManager> factory = new IniSecurityManagerFactory(configFile); //得到securityManager實力并綁定給securityUtils SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); //得到subject及創(chuàng)建賬號密碼身份驗證token Subject subject = SecurityUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken("zhangsan", "123"); //登陸 subject.login(token); } /** * 測試AllSuccessfulStrategy成功 */ @Test public void testAllSuccessfulStrategyWithFail() { login("classpath:shiro-authenticator-all-success.ini"); Subject subject = SecurityUtils.getSubject(); //得到一個身份集合,其中包含了realm驗證成功的身份信息 PrincipalCollection principals = subject.getPrincipals(); List list = principals.asList(); } [main] #指定securityManager的authenticator實現(xiàn) authenticator=org.apache.shiro.authc.pam.ModularRealmAuthenticator securityManager.authenticator=$authenticator #指定securityManager.authenticator的authenticationStrategy allSuccessfulStrategy=org.apache.shiro.authc.pam.AllSuccessfulStrategy securityManager.authenticator.authenticationStrategy=$allSuccessfulStrategy myRealm1=com.rxiao.demo2.L2_MyRealm1 myRealm2=com.rxiao.demo2.L3_MyRealm2 myRealm3=com.rxiao.demo2.L4_MyRealm3 securityManager.realms=$myRealm1,$myRealm3
查看完整描述

1 回答

?
HUX布斯

TA貢獻(xiàn)1876條經(jīng)驗 獲得超6個贊

在自定義的MyRealm3中重寫的getAuthenticationInfo方法最后return new SimpleAuthenticationInfo(username + "@163.com", password, getName()); 這里如果多個realm的username相同就只返回一個,不一樣就都返回

查看完整回答
反對 回復(fù) 2019-02-12
  • 1 回答
  • 0 關(guān)注
  • 412 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號