Hello, I came here to ask for help on Spring Security.
I would like to know how I can get the username of the logged in user. I use authentication with login and password but when I use the search method it returns me the login, and I need to get the username.
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();
}