not working Hi guys, we are trying to implement some functions for our web applic...">

Spring Security JSP Tags <sec: authorize access = "hasRole ('')"> not working

Hi guys, we are trying to implement some functions for our web application. We are using Spring Framework v4.1.1 and Spring Security v3.1.7 for web application. We use our own authentication provider for our authentication process, everything works fine, but when we try to hide some content for a specific role on the page using the JSP tag from Spring Security, it does not work.

Here is our security-conf.xml

<http pattern="/resources/**" security="none" /> <http use-expressions="true"> <form-login login-page="/login" authentication-failure-url="/loginerroneo" default-target-url="/seleccionar-empresa" always-use-default-target="true"/> <logout logout-success-url="/login" logout-url="/salir"/> <session-management invalid-session-url="/login" /> </http> <authentication-manager> <authentication-provider user-service-ref="userDetailsService"> </authentication-provider> </authentication-manager> <global-method-security pre-post-annotations="enabled"/> <beans:bean id="userDetailsService" class="com.grupo.seguridad.acceso.service.impl.UserDetailsServiceAdapater"/> 

When we use this <sec:authentication property="principal.authorities"/> on our page, we get [VENDEDOR, ADMINISTRADOR], which is correct.

but when we tried to hide some page content using the tag:

 <sec:authorize access="hasRole('ADMINISTRADOR')"> <button class="btn btn-small btnGuardar" href="#dlgGuardar" data-toggle="modal"> <i class="icon-hdd"></i> <strong>Una Opcion</strong> </button> </sec:authorize> 

This does not work.

We do not know what we are doing wrong. Thanks for your help. Best regards,

+6
source share
3 answers

try it,

  <security:authorize ifAnyGranted="ADMINISTRADOR"> <button class="btn btn-small btnGuardar" href="#dlgGuardar" data-toggle="modal"> <i class="icon-hdd"></i> <strong>Una Opcion</strong> </button> </security:authorize> 
+2
source

I am using Spring Security 4.2 and cannot use the hasRole method ... But this code works for me:

 <security:authorize access="hasAuthority('ROLE_ADMIN')"> you are an admin! <security:authorize> 
0
source
 <security:authorize access="hasAuthority('YOUR_ROLE')"> <button class="class" name="btnName" id="btnId"> Button </button><security:authorize> 
0
source

Source: https://habr.com/ru/post/976835/


All Articles