1. Display Authenticated User Info

Username: anonymous
Roles: []

<!-- Display logged-in username -->
<strong sec:authentication="name">anonymous</strong>

<!-- Display user's authorities/roles -->
<span sec:authentication="principal.authorities">[]</span>
        

2. Role-Based Content Visibility

👑 Admin-Only Section

This block is ONLY visible to users with the ADMIN role.

Login as admin / password to see this.

IDNameScoreGrade

✅ User Section

This block is visible to all logged-in users (USER and ADMIN roles).

👤 Guest Section

You are not logged in. Login here to see more content.


<!-- Show only to ADMIN -->
<div sec:authorize="hasRole('ADMIN')">Admin content</div>

<!-- Show to any authenticated user -->
<div sec:authorize="isAuthenticated()">User content</div>

<!-- Show only to guests -->
<div sec:authorize="!isAuthenticated()">Guest content</div>

<!-- Show to USER or ADMIN -->
<div sec:authorize="hasAnyRole('USER','ADMIN')">Content</div>

<!-- Using Spring Security expression -->
<div sec:authorize="hasRole('ADMIN') and isFullyAuthenticated()">
    Strictly admin, no remember-me
</div>
        

3. Conditional Navigation Items