securityutils獲取登陸用戶名(shiro獲取登陸用戶)

首先你需要在登陸認證的過程中將獲取的到的對象傳入

//裝配認證信息
        SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
                //用戶名
                userInfo,
                //密碼
                userInfo.getPassword(),
                //salt
                ByteSource.Util.bytes(userInfo.getCredentialsSalt()),
                //realm name
                getName()
        );

其次呢,你需要如下即可獲取

Subject subject = SecurityUtils.getSubject();
Object principal = subject.getPrincipal();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章