Tidying up and removing compiler warnings.
This commit is contained in:
@@ -34,7 +34,7 @@ import org.springframework.security.userdetails.UserDetails;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface GrantedAuthority extends Serializable, Comparable {
|
||||
public interface GrantedAuthority extends Serializable, Comparable<GrantedAuthority> {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,11 +22,11 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Basic concrete implementation of a {@link GrantedAuthority}.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Stores a <code>String</code> representation of an authority granted to the {@link Authentication} object.
|
||||
* <p>
|
||||
* If compared to a custom authority which returns null from {@link #getAuthority}, the <tt>compareTo</tt>
|
||||
* If compared to a custom authority which returns null from {@link #getAuthority}, the <tt>compareTo</tt>
|
||||
* method will return -1, so the custom authority will take precedence.
|
||||
*
|
||||
* @author Ben Alex
|
||||
@@ -73,14 +73,14 @@ public class GrantedAuthorityImpl implements GrantedAuthority, Serializable {
|
||||
return this.role;
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
if (o != null && o instanceof GrantedAuthority) {
|
||||
String rhsRole = ((GrantedAuthority) o).getAuthority();
|
||||
|
||||
public int compareTo(GrantedAuthority ga) {
|
||||
if (ga != null) {
|
||||
String rhsRole = ga.getAuthority();
|
||||
|
||||
if (rhsRole == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return role.compareTo(rhsRole);
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -15,13 +15,12 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Simple concrete implementation of {@link org.springframework.security.AccessDecisionManager} that grants access if any
|
||||
@@ -44,11 +43,9 @@ public class AffirmativeBased extends AbstractAccessDecisionManager {
|
||||
*/
|
||||
public void decide(Authentication authentication, Object object, List<ConfigAttribute> configAttributes)
|
||||
throws AccessDeniedException {
|
||||
Iterator iter = this.getDecisionVoters().iterator();
|
||||
int deny = 0;
|
||||
|
||||
while (iter.hasNext()) {
|
||||
AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();
|
||||
for (AccessDecisionVoter voter : getDecisionVoters()) {
|
||||
int result = voter.vote(authentication, object, configAttributes);
|
||||
|
||||
switch (result) {
|
||||
|
||||
@@ -15,16 +15,14 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationTrustResolver;
|
||||
import org.springframework.security.AuthenticationTrustResolverImpl;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Votes if a {@link ConfigAttribute#getAttribute()} of <code>IS_AUTHENTICATED_FULLY</code> or
|
||||
|
||||
@@ -14,21 +14,17 @@
|
||||
*/
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* <p>This Acl voter will evaluate methods based on labels applied to incoming arguments. It will only check
|
||||
@@ -57,7 +53,7 @@ public class LabelBasedAclVoter extends AbstractAclVoter {
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private Map labelMap = null;
|
||||
private Map<String, List<String>> labelMap = null;
|
||||
private String attributeIndicatingLabeledOperation = null;
|
||||
private boolean allowAccessIfNoAttributesAreLabeled = true;
|
||||
|
||||
@@ -136,7 +132,7 @@ public class LabelBasedAclVoter extends AbstractAclVoter {
|
||||
* @param labelMap a map structured as in the above example.
|
||||
*
|
||||
*/
|
||||
public void setLabelMap(Map labelMap) {
|
||||
public void setLabelMap(Map<String, List<String>> labelMap) {
|
||||
this.labelMap = labelMap;
|
||||
}
|
||||
|
||||
@@ -144,10 +140,6 @@ public class LabelBasedAclVoter extends AbstractAclVoter {
|
||||
* This acl voter will only evaluate labeled methods if they are marked in the security interceptor's
|
||||
* configuration with the attribute stored in attributeIndicatingLabeledOperation.
|
||||
*
|
||||
* @param attribute DOCUMENT ME!
|
||||
*
|
||||
* @return DOCUMENT ME!
|
||||
*
|
||||
* @see org.springframework.security.vote.AbstractAclVoter
|
||||
* @see org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor
|
||||
*/
|
||||
@@ -166,8 +158,7 @@ public class LabelBasedAclVoter extends AbstractAclVoter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote on whether or not the user has all the labels necessary to match the method argument's labeled
|
||||
* data.
|
||||
* Vote on whether or not the user has all the labels necessary to match the method argument's labeled data.
|
||||
*
|
||||
* @return ACCESS_ABSTAIN, ACCESS_GRANTED, or ACCESS_DENIED.
|
||||
*/
|
||||
@@ -178,13 +169,13 @@ public class LabelBasedAclVoter extends AbstractAclVoter {
|
||||
logger.debug("==========================================================");
|
||||
}
|
||||
|
||||
if (this.supports((ConfigAttribute) attributes.iterator().next())) {
|
||||
if (this.supports(attributes.iterator().next())) {
|
||||
result = ACCESS_DENIED;
|
||||
|
||||
/* Parse out the user's labels by examining the security context, and checking
|
||||
* for matches against the label map.
|
||||
*/
|
||||
List userLabels = new Vector();
|
||||
List<String> userLabels = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < authentication.getAuthorities().size(); i++) {
|
||||
String userLabel = authentication.getAuthorities().get(i).getAuthority();
|
||||
@@ -211,19 +202,15 @@ public class LabelBasedAclVoter extends AbstractAclVoter {
|
||||
logger.debug("Argument[" + j + "/" + invocation.getArguments()[j].getClass().getName()
|
||||
+ "] has a data label of " + argumentDataLabel);
|
||||
|
||||
List validDataLabels = new Vector();
|
||||
List<String> validDataLabels = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < userLabels.size(); i++) {
|
||||
validDataLabels.addAll((List) labelMap.get(userLabels.get(i)));
|
||||
validDataLabels.addAll(labelMap.get(userLabels.get(i)));
|
||||
}
|
||||
|
||||
logger.debug("The valid labels for user label " + userLabels + " are " + validDataLabels);
|
||||
|
||||
Iterator dataLabelIter = validDataLabels.iterator();
|
||||
|
||||
while (dataLabelIter.hasNext()) {
|
||||
String validDataLabel = (String) dataLabelIter.next();
|
||||
|
||||
for (String validDataLabel : validDataLabels) {
|
||||
if (argumentDataLabel.equals(validDataLabel)) {
|
||||
logger.debug(userLabels + " maps to " + validDataLabel + " which matches the argument");
|
||||
matched = true;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<!--
|
||||
XSL to manipulate trang's output XSD file. Contributed by Brian Ewins.
|
||||
|
||||
$Id$
|
||||
$Id$
|
||||
-->
|
||||
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
|
||||
@@ -20,19 +20,19 @@
|
||||
<xsl:for-each select="/xs:schema/xs:element[@name=substring-after(current()/@ref, ':')]">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="$node/@*[local-name() != 'ref']"/>
|
||||
<xsl:apply-templates select="@*|*"/>
|
||||
<xsl:apply-templates select="@*|*"/>
|
||||
</xsl:copy>
|
||||
</xsl:for-each>
|
||||
</xsl:for-each>
|
||||
</xsl:when>
|
||||
<!-- Ignore global elements which have been inlined -->
|
||||
<xsl:when test="contains($elts-to-inline, concat(',',@name,','))">
|
||||
</xsl:when>
|
||||
|
||||
|
||||
<xsl:otherwise>
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="@*|*"/>
|
||||
</xsl:copy>
|
||||
</xsl:otherwise>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
@@ -42,5 +42,5 @@
|
||||
<xsl:apply-templates select="text()|@*|*"/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.Test;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class GrantedAuthorityImplTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void equalsBehavesAsExpected() throws Exception {
|
||||
GrantedAuthorityImpl auth1 = new GrantedAuthorityImpl("TEST");
|
||||
@@ -62,32 +62,32 @@ public class GrantedAuthorityImplTests {
|
||||
@Test
|
||||
public void compareToGrantedAuthorityWithSameValueReturns0() {
|
||||
assertEquals(0, new GrantedAuthorityImpl("TEST").compareTo(new MockGrantedAuthority("TEST")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareToNullReturnsNegativeOne() {
|
||||
assertEquals(-1, new GrantedAuthorityImpl("TEST").compareTo(null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* SEC-899 */
|
||||
@Test
|
||||
public void compareToHandlesCustomAuthorityWhichReturnsNullFromGetAuthority() {
|
||||
assertEquals(-1, new GrantedAuthorityImpl("TEST").compareTo(new MockGrantedAuthority()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockGrantedAuthority implements GrantedAuthority {
|
||||
private String role;
|
||||
|
||||
public MockGrantedAuthority() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public MockGrantedAuthority(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
public int compareTo(GrantedAuthority o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,34 +15,37 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.AuthenticationManager;
|
||||
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.AuthenticationManager;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LabelBasedAclVoterTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
@ContextConfiguration(locations={"/org/springframework/security/vote/labelBasedSecurityApplicationContext.xml"})
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class LabelBasedAclVoterTests {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@Autowired
|
||||
private SampleService sampleService = null;
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
@Autowired
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] {"org/springframework/security/vote/labelBasedSecurityApplicationContext.xml"};
|
||||
}
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public SampleService getSampleService() {
|
||||
return sampleService;
|
||||
@@ -54,11 +57,10 @@ public class LabelBasedAclVoterTests extends AbstractDependencyInjectionSpringCo
|
||||
|
||||
private void setupContext(String username, String password) {
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
|
||||
AuthenticationManager authenticationManager = (AuthenticationManager) applicationContext.getBean(
|
||||
"authenticationManager");
|
||||
SecurityContextHolder.getContext().setAuthentication(authenticationManager.authenticate(token));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoingSomethingForBlueUser() {
|
||||
setupContext("blueuser", "password");
|
||||
|
||||
@@ -98,6 +100,7 @@ public class LabelBasedAclVoterTests extends AbstractDependencyInjectionSpringCo
|
||||
sampleService.doSomethingOnThis(block3, block3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoingSomethingForMultiUser() {
|
||||
setupContext("multiuser", "password4");
|
||||
|
||||
@@ -115,6 +118,7 @@ public class LabelBasedAclVoterTests extends AbstractDependencyInjectionSpringCo
|
||||
sampleService.doSomethingOnThis(block3, block3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoingSomethingForOrangeUser() {
|
||||
setupContext("orangeuser", "password3");
|
||||
|
||||
@@ -154,6 +158,7 @@ public class LabelBasedAclVoterTests extends AbstractDependencyInjectionSpringCo
|
||||
sampleService.doSomethingOnThis(block3, block3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoingSomethingForSuperUser() {
|
||||
setupContext("superuser", "password2");
|
||||
|
||||
@@ -171,6 +176,7 @@ public class LabelBasedAclVoterTests extends AbstractDependencyInjectionSpringCo
|
||||
sampleService.doSomethingOnThis(block3, block3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSampleBlockOfDataPOJO() {
|
||||
SampleBlockOfData block = new SampleBlockOfData();
|
||||
block.setId("ID-ABC");
|
||||
|
||||
Reference in New Issue
Block a user