From ea0e6b25770082ea6b63740289136a7bb759516f Mon Sep 17 00:00:00 2001 From: Francois Beausoleil Date: Fri, 2 Apr 2004 20:59:16 +0000 Subject: [PATCH] * test/net/sf/acegisecurity/taglibs/authz/AuthorizeTagAttributeTests.java, src/net/sf/acegisecurity/taglibs/authz/AuthorizeTag.java: Added three new tests to assert that whitespace is ignored in the attribute's content. --- .../taglibs/authz/AuthorizeTag.java | 2 +- .../authz/AuthorizeTagAttributeTests.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/acegisecurity/taglibs/authz/AuthorizeTag.java b/core/src/main/java/org/acegisecurity/taglibs/authz/AuthorizeTag.java index 198fc972e8..87c9b453ae 100644 --- a/core/src/main/java/org/acegisecurity/taglibs/authz/AuthorizeTag.java +++ b/core/src/main/java/org/acegisecurity/taglibs/authz/AuthorizeTag.java @@ -124,7 +124,7 @@ public class AuthorizeTag extends TagSupport { while (tokenizer.hasMoreTokens()) { String role = tokenizer.nextToken(); - requiredAuthorities.add(new GrantedAuthorityImpl(role)); + requiredAuthorities.add(new GrantedAuthorityImpl(role.trim())); } return requiredAuthorities; diff --git a/core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagAttributeTests.java b/core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagAttributeTests.java index 2356aa171b..cef5a96933 100644 --- a/core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagAttributeTests.java +++ b/core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagAttributeTests.java @@ -63,6 +63,30 @@ public class AuthorizeTagAttributeTests extends TestCase { Tag.SKIP_BODY, authorizeTag.doStartTag()); } + public void testAssertsIfNotGrantedIgnoresWhitespaceInAttribute() + throws JspException { + authorizeTag.setIfAnyGranted( + "\tROLE_SUPERVISOR \t, \r\n\t ROLE_TELLER "); + assertEquals("allows request - principal has ROLE_SUPERVISOR", + Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag()); + } + + public void testIfAllGrantedIgnoresWhitespaceInAttribute() + throws JspException { + authorizeTag.setIfAllGranted( + "\nROLE_SUPERVISOR\t,ROLE_RESTRICTED\t\n\r "); + assertEquals("allows request - principal has ROLE_RESTRICTED " + + "and ROLE_SUPERVISOR", Tag.EVAL_BODY_INCLUDE, + authorizeTag.doStartTag()); + } + + public void testIfNotGrantedIgnoresWhitespaceInAttribute() + throws JspException { + authorizeTag.setIfNotGranted(" \t ROLE_TELLER \r"); + assertEquals("allows request - principal does not have ROLE_TELLER", + Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag()); + } + protected void setUp() throws Exception { super.setUp();