Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why sec:authentication="name" show all user information?

I use Spring Boot, Spring Boot Security, thymeleaf-extras-springsecurity5. I want get information about current user and write:

<div sec:authorize="isAuthenticated()"> 
 Authenticated as <span sec:authentication="name"></span></div>

and get All User information Like that:

Authenticated as User(id=7, firstName=TOGRUL, lastName=Mamedov, patronymic=dddddd, [email protected], phone=+99477777777, password=$2a$11$txs/zdaLq.6eeBHz3uyM0e/R6uzJHs2.UIeIeRrV906y6Ia/hMOE6, enabled=true, secret=MVNSUPKHWTAVLIEQ, country=Azerbaijan, state=Baki, city=Badamdar, gender=Man, addressLine=GANJA, zipCode=2001, birthDay=01-07-2020, passportSeria=AZE, passportNumber=1234567, finCode=1234567, avatar=/resources/images/user-icon.png, mytext=null, active=0, isUsing2FA=false, roles=[Role [name=ROLE_USER][id=5]])

For base authentication I use this project. https://github.com/Baeldung/spring-security-registration

How to fix this error if it is a bug? I think password should't be shown anyway. How get username? How get other information if it possible? It is look like Array or some.property

like image 299
Togrul Sadigov Avatar asked Oct 23 '25 10:10

Togrul Sadigov


1 Answers

I see you are using thymeleaf. Try this expression and instead of "getSomeProperty()" call any get method of your user class

${#authentication.getPrincipal().getSomeProperty()}
like image 86
3asyPe Avatar answered Oct 25 '25 05:10

3asyPe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!