Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring security. authorize doesn't work on jsp

I had following jsp page and that jsp compiles as expected

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>

<c:if test="${sessionScope.userName!=null}">

    ...

</c:if>

In login controller method I have following row:

session.setAttribute("userName", name);

I thought that better to rewrite it using spring security tags

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>

<sprSec:authorize access="isAuthenticated()">

  ...

</sprSec:authorize>

And now I have following error when try to acces to page:

  org.apache.jasper.JasperException: org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/*/*****.jsp at line 5

    2: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    3: <%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>
    4: 
    5: <sprSec:authorize access="isAuthenticated()">
    6: 
    7: <c:set var="profileUrl" value="#" scope="request" />
    8:  <sprSec:authorize ifAllGranted="ROLE_USER">


....

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: java.io.IOException: No visible WebSecurityExpressionHandler instance could be found in the application context. There must be at least one in order to support expressions in JSP 'authorize' tags.
..........
like image 393
gstackoverflow Avatar asked Jun 04 '26 00:06

gstackoverflow


1 Answers

This is probably a duplicate of Spring Security - No visible WebSecurityExpressionHandler instance could be found in the application context.

As pointed out there, make sure to add an use-expressions attribute set to true for your configuration's http element, i.e. write <http use-expressions="true">.

like image 135
Hille Avatar answered Jun 06 '26 12:06

Hille



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!