olá,venho aqui pedir ajuda sobre Spring Security.
gostaria de saber como consigo pegar o nome do usuario logado,eu utilizo autenticação com login e senha porém quando utilizo o metodo de busca ,ele me retorna o login,sendo que preciso pegar o nome do usuário.
desde já agradeço.
Olá:
SecurityContextHolder.getContext().authentication
Olá Rodrigo_Void .Eu criei o metodo mais ele me retorna o login ao inves do nome do usuario
public String getUsuarioLogado() {
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
usuarioLogado = (Usuario) session.getAttribute("usuarioLogado");
Authentication authentication = (Authentication) SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
authentication.getName();
}
return authentication.getName();
}
Sim, com isso vc pode buscar o usuario do banco e pegar o nome.
Outra alternativa é criar seu próprio objeto que represente o Authentication e aí nele vc pode ter oq quiser já precarregado, mas isso é bem mais loco.
Uma pequeno overview aqui:
Recomendo usar JWT, fica topster
conseguir resolver Rodrigo, era isso mesmo!!
muito obrigado,me ajudou muito…