shiro 獲取已經登錄的用戶


//shiro 獲取登錄的用戶信息
TUser user = (TUser)SecurityUtils.getSubject().getPrincipal();

//前提是需要的在登錄的認證的方法中存入已經登錄的用戶如下

 

 代碼如下

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
System.out.println("-------身份認證方法--------");
String userName = (String) authenticationToken.getPrincipal();
String userPwd = new String((char[]) authenticationToken.getCredentials());
QueryWrapper<TUser> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("username",userName);
TUser one = userService.getOne(queryWrapper);//根據用戶名從數據庫獲取密碼
if(one==null){
throw new AccountException("用戶不正確");
}
if (!userPwd.equals(one.getPassword() )) {
throw new IncorrectCredentialsException("密碼不正確");
}
//用戶存入shiro 緩存
SimpleAuthenticationInfo info =new SimpleAuthenticationInfo(one, one.getPassword(),getName());
return info;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM