
如上圖,我先通過loadUserByUsername方法回傳了一個自定義的UserDetails物件,這個物件包含了組織部門,用戶ID等額外資訊;我想在controller中通過Authentication物件獲取這些資訊該怎么獲取,直接強制型別轉換不行,如下圖
uj5u.com熱心網友回復:
直接將authentication.getPricipal強轉成userdetailuj5u.com熱心網友回復:
強制轉就報錯,authentication.getPrincipal回傳的是String型別
uj5u.com熱心網友回復:
那我覺得你沒認證成功
public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
}看看能你程式能到這里嗎
uj5u.com熱心網友回復:
應該是認證成功了,認證token也取得了,也能通過token訪問其他資源,就是獲取不到UserDetails物件轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/101815.html
標籤:Web 開發
