Advertisement
codeuniv

Thymeleaf tags for Spring Security

Apr 3rd, 2022
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.83 KB | None | 0 0
  1. add thymeleaf XML namespace to index.html
  2.  
  3. https://github.com/thymeleaf/thymeleaf-extras-springsecurity
  4. Thymeleaf Extras
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
  7.      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
  8.  
  9. <div sec:authorize="hasRole('ADMIN')">
  10.     This content is only shown to administrators.ยงยง
  11. </div>
  12.  
  13. <div sec:authorize="hasRole('USER')">
  14.     This content is only shown to users.
  15.     Content is not just hidden from view but will not be rendered when our application server returns the page to the browser.
  16. </div>
  17.    
  18.     retrieve the user's username and roles and display these in our HTML
  19.     <div>
  20.     User: <span sec:authentication="name">NOT FOUND</span>
  21.     Spring Roles: <span sec:authentication="principal.authorities">NOT FOUND</span>
  22. </div>
  23.    
  24.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement