Browse Source
Allows the result of the boolean condition granting/denying access to be stored in the page context for later use, without having to duplicate the tag.pull/1/head
11 changed files with 153 additions and 32 deletions
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> |
||||
<html> |
||||
<body> |
||||
<h1>Authorization Tag Test Page</h1> |
||||
|
||||
<sec:authorize access="hasRole('ROLE_USER')" var="allowed"> |
||||
Users can see this and 'allowed' variable is ${allowed}. |
||||
</sec:authorize> |
||||
|
||||
<sec:authorize access="hasRole('ROLE_X')" var="allowed"> |
||||
Role X users (nobody) can see this. |
||||
</sec:authorize> |
||||
|
||||
Role X expression evaluates to ${allowed}. |
||||
|
||||
|
||||
</body> |
||||
|
||||
</html> |
||||
|
||||
|
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
package org.springframework.security.integration; |
||||
|
||||
import static org.testng.Assert.*; |
||||
|
||||
import org.testng.annotations.Test; |
||||
|
||||
/** |
||||
* |
||||
* @author Luke Taylor |
||||
*/ |
||||
public final class JspTaglibTests extends AbstractWebServerIntegrationTests { |
||||
|
||||
@Override |
||||
protected String getContextConfigLocations() { |
||||
return "/WEB-INF/http-security.xml /WEB-INF/in-memory-provider.xml"; |
||||
} |
||||
|
||||
@Test |
||||
public void authenticationTagEscapingWorksCorrectly() { |
||||
beginAt("secure/authenticationTagTestPage.jsp"); |
||||
login("theescapist<>&.", "theescapistspassword"); |
||||
String response = tester.getServerResponse(); |
||||
assertTrue(response.contains("This is the unescaped authentication name: theescapist<>&.")); |
||||
assertTrue(response.contains("This is the unescaped principal.username: theescapist<>&.")); |
||||
assertTrue(response.contains("This is the authentication name: theescapist<>&.")); |
||||
assertTrue(response.contains("This is the principal.username: theescapist<>&.")); |
||||
} |
||||
|
||||
@Test |
||||
public void authorizationTagEvaluatesExpressionCorrectlyAndWritesValueToVariable() { |
||||
beginAt("secure/authorizationTagTestPage.jsp"); |
||||
login("bessie", "bessiespassword"); |
||||
String response = tester.getServerResponse(); |
||||
assertTrue(response.contains("Users can see this and 'allowed' variable is true.")); |
||||
assertFalse(response.contains("Role X users (nobody) can see this.")); |
||||
assertTrue(response.contains("Role X expression evaluates to false")); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue