shiro登錄

shiro登錄
1.獲取當前的Subject,調用SecurityUtils.getSubject();
2.判斷當前用戶是否被認證(登錄),調用Subject的isAuthenticated();
3.沒有認證,把用戶名和密碼封裝爲UsernamePasswordToken對象;
   3.1創建表單頁面;
   3.2將請求提交到springmvc的handle;
   3.3獲取用戶名和密碼
4.執行登錄調用Subject的login(AuthenticationToken token)
5.自定義的Realm的方法,從數據庫中獲取對應的記錄,給shiro
   5.1繼承org.apache.shiro.realm.AuthorizingRealm類;
   5.2實現doGetAuthenticationInfo(AuthenticationToken token)方法;
6.由shiro完成密碼的比對;
    通過AuthenticationToken中的CredentialsMatcher屬性來進行密碼比對;
shiro 加密
1.如何把一個字符串加密;new SimpleHash("MD5", credential, ByteSource.Util.bytes(salt), 1024);
2.提供當前Reaml的CredentialsMatcher屬性,直接使用HashedCredentialsMatcher對象,並設置加密算法即可.
鹽值加密:
1.爲什麼要使用鹽值加密
2.如何做到:
   1.在doGetAuthenticationInfo方法返回SimpleAuthenticationInfo對象時,
    使用new SimpleAuthenticationInfo(principal, hashedCredentials, credentialsSalt, realmName)構造器;
   2.使用ByteSource.Util.bytes(salt)來計算鹽值;
   3.鹽值要唯一:一般爲隨機字符串或用戶名
   4.使用new SimpleAuthenticationInfo(principal, hashedCredentials, credentialsSalt, realmName);來計算鹽值加密後的結果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章