que he tenido éxito con lo siguiente:
<sec:authorize ifAnyGranted="ROLE_ANONYMOUS">
<td><a href="<c:url value="/login.htm"/>">Login</a></td>
</sec:authorize>
<sec:authorize ifNotGranted="ROLE_ANONYMOUS">
<td><a href="<c:url value="/j_spring_security_logout"/>">Logout</a></td>
</sec:authorize>
Nuevos roles se pueden añadir sin afectar a la lógica aquí.
Para lograr esta respuesta hasta la fecha con Spring Security 3, utilizando las expresiones isAnonymous()
y isAuthenticated()
han funcionado bien en combinación hasta ahora para lograr la misma cosa. He aquí un ejemplo:
<sec:authorize access="isAnonymous()">
<form method="POST" action="<c:url value='j_spring_security_check'/>">
Username: <input name="j_username" type="text" value="${SPRING_SECURITY_LAST_USERNAME}" />
Password: <input name="j_password" type="password" />
<input type="submit" value="Sign in" />
</form>
</sec:authorize>
<sec:authorize access="isAuthenticated()">
<a href="<c:url value="/j_spring_security_logout" />">Logout</a>
</sec:authorize>
El atributo 'ifAnyGranted' ha quedado obsoleto en Spring Security 3.0 a favor del atributo' access', por ejemplo ''. –
Josh
Gracias por la respuesta, me ayudó. Además, la biblioteca de etiquetas debe agregarse al archivo jsp: '<% @ taglib prefix =" sec "uri =" http://www.springframework.org/security/tags "%>' Si maven se utiliza, se debe agregar la siguiente dependencia al proyecto: groupId: org.springframework.security, artifactId: spring-security-taglibs –
Se suponía que se utilizaran comillas simples para evitar una impresión '>' antiestética en el navegador. Aquí está la sintaxis correcta con comillas simples: 'Click here to Logout'. De lo contrario, +1. – CodeMed