Browse Source

Implemented a fix for a NullPointerException as reported by Pierre-Antoine Gr�goire (pa.gregoire@free.fr)

"The error comes from line 115 in AuthorizeTag....It seems there's no control
for a null value here..."

* test/net/sf/acegisecurity/taglibs/authz/AuthorizeTagTests.java:
  Added a new test to confirm the existence of the bug.

* src/net/sf/acegisecurity/taglibs/authz/AuthorizeTag.java:
  And fixed the failing test.
1.0.x
Francois Beausoleil 22 years ago
parent
commit
d5a6ea044d
  1. 4
      core/src/main/java/org/acegisecurity/taglibs/authz/AuthorizeTag.java
  2. 9
      core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagTests.java

4
core/src/main/java/org/acegisecurity/taglibs/authz/AuthorizeTag.java

@ -112,6 +112,10 @@ public class AuthorizeTag extends TagSupport { @@ -112,6 +112,10 @@ public class AuthorizeTag extends TagSupport {
Authentication currentUser = context.getAuthentication();
if (null == currentUser) {
return Collections.EMPTY_LIST;
}
Collection granted = Arrays.asList(currentUser.getAuthorities());
return granted;

9
core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagTests.java

@ -42,6 +42,15 @@ public class AuthorizeTagTests extends TestCase { @@ -42,6 +42,15 @@ public class AuthorizeTagTests extends TestCase {
//~ Methods ================================================================
public void testAlwaysReturnsUnauthorizedIfNoUserFound()
throws JspException {
context.setAuthentication(null);
authorizeTag.setIfAllGranted("ROLE_TELLER");
assertEquals("prevents request - no principal in Context",
Tag.SKIP_BODY, authorizeTag.doStartTag());
}
public void testDefaultsToNotOutputtingBodyWhenNoRequiredAuthorities()
throws JspException {
assertEquals("", authorizeTag.getIfAllGranted());

Loading…
Cancel
Save