源代码
SecurityContextHolder.getContext().getAuthentication().getPrincipal()
对于WebSecurityConfigurer中关于认证成功的 AuthenticationSuccessHandler 配置DEMO
.successHandler(new AuthenticationSuccessHandler() { @Override public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException { httpServletResponse.setContentType("application/json;charset=UTF-8"); ApiResponse retTemp = ApiResponseUtil.getRetTemp(); retTemp.setCode("200"); retTemp.setMsg("登录成功"); retTemp.setData(authentication.getPrincipal()); PrintWriter out = httpServletResponse.getWriter(); out.write(new ObjectMapper().writeValueAsString(retTemp)); out.flush(); out.close(); } })
学习资源
《SpringBoot+Vue全栈开发实战》示例源代码:https://pan.baidu.com/s/1SYxcHPFe2HfhlVoHklcB1w