2015年1月8日 星期四

[Spring Security] Get Current User

To get the current authentication:

Method 1
      Authentication auth = SecurityContextHolder.getContext().getAuthentication();
      String name = auth.getName(); //get logged in username
 Method 2
User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String name = user.getUsername(); //get logged in username

http://www.mkyong.com/spring-security/get-current-logged-in-username-in-spring-security/

沒有留言:

張貼留言

Pixel-to-Centimeter Calculator

📐 px to cm 換算器 基於圖片實際尺寸與像素比例精準計算 1. 全圖基準設定 (Full Image Size) 圖片像素 寬 (px) ...