Skip to content

SEC-1900: Fixed by removing dependency to equals method in SimpleGrantedAuthority #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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);

}

}