首先你需要在登陸認證的過程中將獲取的到的對象傳入
//裝配認證信息
SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
//用戶名
userInfo,
//密碼
userInfo.getPassword(),
//salt
ByteSource.Util.bytes(userInfo.getCredentialsSalt()),
//realm name
getName()
);
其次呢,你需要如下即可獲取
Subject subject = SecurityUtils.getSubject(); Object principal = subject.getPrincipal();