how to conditionally show jsp content to logged in users with Spring security

前端 未结 8 1987
旧时难觅i
旧时难觅i 2020-12-07 12:59

I want to show content to any user that is logged in and to hide if they are not logged in. I\'m using jsp\'s and spring security.

Obviously a home grown solution i

相关标签:
8条回答
  • 2020-12-07 13:25

    How 'bout this? - Spring 2.5 compliant ;-)

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
    
    <security:authorize ifAllGranted="ROLE_USER">
       Welcome <%= request.getUserPrincipal().getName() %>
       <a href="<c:url value="/j_spring_security_logout"/>">Logout</a><br/>
    </security:authorize>
    
    0 讨论(0)
  • 2020-12-07 13:26

    you can use this inside jsp spring security tag

    request.getUserPrincipal().getName()
    
    0 讨论(0)
提交回复
热议问题