Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ public boolean authorizeUsingGrantedAuthorities() {
final Collection<? extends GrantedAuthority> granted = getPrincipalAuthorities();

if (hasTextAllGranted) {
if (!granted.containsAll(toAuthorities(getIfAllGranted()))) {
return false;
}
Set<String> grantedRoles = authoritiesToRoles(granted);
Set<String> requiredRoles = authoritiesToRoles(toAuthorities(getIfAllGranted()));
if (!grantedRoles.containsAll(requiredRoles)) {
return false;
}
}

if (hasTextAnyGranted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,28 @@ public String getAuthority() {
assertTrue("expected", true);
}
}

/**
* Tests that it is possible to use the authorize tag with any authorization
* object that implements GrantedAuthority.
* @throws JspException on tag failures (not supposed to happen in this test case)
*/
@Test
public void testAuthorizeUsingGrantedAuthorities() throws JspException {
authorizeTag.setIfAnyGranted(null);
authorizeTag.setIfNotGranted(null);
authorizeTag.setIfAllGranted("ROLE_TEST");
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new GrantedAuthority() {
public String getAuthority() {
return "ROLE_TEST";
}
});
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
int testResult = authorizeTag.doStartTag();
Assert.assertEquals("Not authorized even though having correct authorities.",
Tag.EVAL_BODY_INCLUDE, testResult);

}

}