5
Hello, I come here to ask for help about Spring Security.
I would like to know how I can get the username logged in. 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();
}
Hello! Could you pass us the code you are using to get the login? Just to have a basis of what you have tried to do. You’ll probably get the information you need on
SecurityContextHolder.getContext().getAuthentication()
.– Dherik
Thank you for Reply Dherik
– Cícero Régis Oliveira
What are the fields in the User class? The name you want is in this class?
– Dherik