SpringSececurity以及Apache Shiro 獲取當前登錄用戶的方法

1.apache shiro獲取當前登錄用戶的方法是

User user = (User) SecurityUtils.getSubject().getPrincipal();
// 這裏獲取的當前登錄的整個用戶實體,得到後直接就是實體數據,可以直接使用user.getId(),user.getName()等方法;

2.springsecurity獲取當前登錄用戶的方法是

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
使用 authentication.getName() 獲取用戶id;
或者使用 authentication.getPrincipal()  獲取用戶id;

 

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