SEC-1013: Refactored out use of ConfigAttributeDefinition from remaining interfaces
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.security;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -28,13 +29,10 @@ import java.util.Iterator;
|
||||
public class MockAccessDecisionManager implements AccessDecisionManager {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)
|
||||
throws AccessDeniedException {
|
||||
Iterator iter = config.getConfigAttributes().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConfigAttribute attr = (ConfigAttribute) iter.next();
|
||||
public void decide(Authentication authentication, Object object, List<ConfigAttribute> configAttributes)
|
||||
throws AccessDeniedException {
|
||||
|
||||
for(ConfigAttribute attr : configAttributes) {
|
||||
if (this.supports(attr)) {
|
||||
for (int i = 0; i < authentication.getAuthorities().length; i++) {
|
||||
if (attr.getAttribute().equals(authentication.getAuthorities()[i].getAuthority())) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.security;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,9 +28,9 @@ import java.util.Iterator;
|
||||
public class MockAfterInvocationManager implements AfterInvocationManager {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config,
|
||||
public Object decide(Authentication authentication, Object object, List<ConfigAttribute> config,
|
||||
Object returnedObject) throws AccessDeniedException {
|
||||
Iterator iter = config.getConfigAttributes().iterator();
|
||||
Iterator iter = config.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConfigAttribute attr = (ConfigAttribute) iter.next();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.security;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -28,8 +29,8 @@ import java.util.Iterator;
|
||||
public class MockRunAsManager implements RunAsManager {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public Authentication buildRunAs(Authentication authentication, Object object, ConfigAttributeDefinition config) {
|
||||
Iterator iter = config.getConfigAttributes().iterator();
|
||||
public Authentication buildRunAs(Authentication authentication, Object object, List<ConfigAttribute> config) {
|
||||
Iterator iter = config.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConfigAttribute attr = (ConfigAttribute) iter.next();
|
||||
|
||||
+10
-14
@@ -15,23 +15,19 @@
|
||||
|
||||
package org.springframework.security.afterinvocation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link AfterInvocationProviderManager}.
|
||||
@@ -62,11 +58,11 @@ public class AfterInvocationProviderManagerTests extends TestCase {
|
||||
assertEquals(list, manager.getProviders());
|
||||
manager.afterPropertiesSet();
|
||||
|
||||
ConfigAttributeDefinition attr1 = new ConfigAttributeDefinition(new String[] {"GIVE_ME_SWAP1"});
|
||||
ConfigAttributeDefinition attr2 = new ConfigAttributeDefinition(new String[] {"GIVE_ME_SWAP2"});
|
||||
ConfigAttributeDefinition attr3 = new ConfigAttributeDefinition(new String[] {"GIVE_ME_SWAP3"});
|
||||
ConfigAttributeDefinition attr2and3 = new ConfigAttributeDefinition(new String[] {"GIVE_ME_SWAP2","GIVE_ME_SWAP3"});
|
||||
ConfigAttributeDefinition attr4 = new ConfigAttributeDefinition(new String[] {"NEVER_CAUSES_SWAP"});
|
||||
List<ConfigAttribute> attr1 = SecurityConfig.createList(new String[] {"GIVE_ME_SWAP1"});
|
||||
List<ConfigAttribute> attr2 = SecurityConfig.createList(new String[] {"GIVE_ME_SWAP2"});
|
||||
List<ConfigAttribute> attr3 = SecurityConfig.createList(new String[] {"GIVE_ME_SWAP3"});
|
||||
List<ConfigAttribute> attr2and3 = SecurityConfig.createList(new String[] {"GIVE_ME_SWAP2","GIVE_ME_SWAP3"});
|
||||
List<ConfigAttribute> attr4 = SecurityConfig.createList(new String[] {"NEVER_CAUSES_SWAP"});
|
||||
|
||||
assertEquals("swap1", manager.decide(null, new SimpleMethodInvocation(), attr1, "content-before-swapping"));
|
||||
|
||||
@@ -162,7 +158,7 @@ public class AfterInvocationProviderManagerTests extends TestCase {
|
||||
this.configAttribute = configAttribute;
|
||||
}
|
||||
|
||||
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config,
|
||||
public Object decide(Authentication authentication, Object object, List<ConfigAttribute> config,
|
||||
Object returnedObject) throws AccessDeniedException {
|
||||
if (config.contains(configAttribute)) {
|
||||
return forceReturnObject;
|
||||
|
||||
+15
-17
@@ -15,23 +15,22 @@
|
||||
|
||||
package org.springframework.security.afterinvocation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.AuthorizationServiceException;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.MockAclManager;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.acl.AclEntry;
|
||||
import org.springframework.security.acl.AclManager;
|
||||
import org.springframework.security.acl.basic.MockAclObjectIdentity;
|
||||
import org.springframework.security.acl.basic.SimpleAclEntry;
|
||||
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link BasicAclEntryAfterInvocationCollectionFilteringProvider}.
|
||||
@@ -73,10 +72,10 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests extend
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("scott", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_READ");
|
||||
|
||||
// Filter
|
||||
List filteredList = (List) provider.decide(auth, new SimpleMethodInvocation(), attr, list);
|
||||
List filteredList = (List) provider.decide(auth, new SimpleMethodInvocation(),
|
||||
SecurityConfig.createList("AFTER_ACL_COLLECTION_READ"), list);
|
||||
|
||||
assertEquals(0, filteredList.size());
|
||||
}
|
||||
@@ -106,7 +105,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests extend
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("scott", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_COLLECTION_READ");
|
||||
|
||||
// Filter
|
||||
List filteredList = (List) provider.decide(auth, new SimpleMethodInvocation(), attr, list);
|
||||
@@ -140,7 +139,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests extend
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_COLLECTION_READ");
|
||||
|
||||
// Filter
|
||||
List filteredList = (List) provider.decide(auth, new SimpleMethodInvocation(), attr, list);
|
||||
@@ -175,7 +174,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests extend
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_COLLECTION_READ");
|
||||
|
||||
// Filter
|
||||
String[] filteredList = (String[]) provider.decide(auth, new SimpleMethodInvocation(), attr, list);
|
||||
@@ -201,7 +200,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests extend
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_COLLECTION_READ");
|
||||
|
||||
// Filter
|
||||
try {
|
||||
@@ -229,7 +228,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests extend
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_COLLECTION_READ");
|
||||
|
||||
// Filter
|
||||
List filteredList = (List) provider.decide(auth, new SimpleMethodInvocation(), attr, null);
|
||||
@@ -262,14 +261,13 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests extend
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_COLLECTION_READ");
|
||||
|
||||
// As no matching config attrib, ensure provider doesn't change list
|
||||
assertEquals(4, ((List) provider.decide(auth, new SimpleMethodInvocation(), attr, list)).size());
|
||||
|
||||
// Filter, this time with the conf attrib provider setup to answer
|
||||
attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_ADMIN");
|
||||
//attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_COLLECTION_ADMIN"));
|
||||
attr = SecurityConfig.createList("AFTER_ACL_COLLECTION_ADMIN");
|
||||
|
||||
List filteredList = (List) provider.decide(auth, new SimpleMethodInvocation(), attr, list);
|
||||
|
||||
@@ -303,7 +301,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests extend
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_COLLECTION_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_COLLECTION_READ");
|
||||
|
||||
// Filter
|
||||
List filteredList = (List) provider.decide(auth, new SimpleMethodInvocation(), attr, list);
|
||||
|
||||
+11
-7
@@ -15,11 +15,15 @@
|
||||
|
||||
package org.springframework.security.afterinvocation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.MockAclManager;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.acl.AclEntry;
|
||||
import org.springframework.security.acl.AclManager;
|
||||
import org.springframework.security.acl.basic.MockAclObjectIdentity;
|
||||
@@ -54,7 +58,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("scott", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_READ");
|
||||
|
||||
try {
|
||||
provider.decide(auth, new SimpleMethodInvocation(), attr, "belmont");
|
||||
@@ -81,7 +85,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("scott", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_READ");
|
||||
|
||||
try {
|
||||
provider.decide(auth, new SimpleMethodInvocation(), attr, "belmont");
|
||||
@@ -109,7 +113,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_READ");
|
||||
|
||||
// Filter
|
||||
assertEquals("belmont", provider.decide(auth, new SimpleMethodInvocation(), attr, "belmont"));
|
||||
@@ -132,7 +136,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_READ");
|
||||
|
||||
// Filter
|
||||
assertNull(provider.decide(auth, new SimpleMethodInvocation(), attr, null));
|
||||
@@ -156,13 +160,13 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_READ");
|
||||
|
||||
// As no matching config attrib, ensure provider returns original obj
|
||||
assertEquals("sydney", provider.decide(auth, new SimpleMethodInvocation(), attr, "sydney"));
|
||||
|
||||
// Filter, this time with the conf attrib provider setup to answer
|
||||
attr = new ConfigAttributeDefinition("AFTER_ACL_ADMIN");
|
||||
attr = SecurityConfig.createList("AFTER_ACL_ADMIN");
|
||||
assertEquals("sydney", provider.decide(auth, new SimpleMethodInvocation(), attr, "sydney"));
|
||||
}
|
||||
|
||||
@@ -184,7 +188,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
|
||||
// Create the Authentication and Config Attribs we'll be presenting
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("rod", "NOT_USED");
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("AFTER_ACL_READ");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("AFTER_ACL_READ");
|
||||
|
||||
// Filter
|
||||
assertEquals("sydney", provider.decide(auth, new SimpleMethodInvocation(), attr, "sydney"));
|
||||
|
||||
-1
@@ -12,7 +12,6 @@ import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
|
||||
/**
|
||||
* @author Luke Taylor
|
||||
|
||||
-1
@@ -22,7 +22,6 @@ import junit.framework.TestCase;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
+1
-2
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.springframework.mock.web.MockFilterChain;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.intercept.web.DefaultFilterInvocationDefinitionSource;
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
|
||||
+7
-4
@@ -1,7 +1,12 @@
|
||||
package org.springframework.security.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.security.config.ConfigTestUtils.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.security.config.ConfigTestUtils.AUTH_PROVIDER_XML;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Iterator;
|
||||
@@ -10,14 +15,12 @@ import java.util.List;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.AbstractXmlApplicationContext;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.MockAuthenticationEntryPoint;
|
||||
import org.springframework.security.MockFilterChain;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
+12
-11
@@ -1,24 +1,25 @@
|
||||
package org.springframework.security.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.afterinvocation.AfterInvocationProvider;
|
||||
|
||||
public class MockAfterInvocationProvider implements AfterInvocationProvider {
|
||||
|
||||
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Object returnedObject)
|
||||
throws AccessDeniedException {
|
||||
return returnedObject;
|
||||
}
|
||||
public Object decide(Authentication authentication, Object object, List<ConfigAttribute> config, Object returnedObject)
|
||||
throws AccessDeniedException {
|
||||
return returnedObject;
|
||||
}
|
||||
|
||||
public boolean supports(ConfigAttribute attribute) {
|
||||
return true;
|
||||
}
|
||||
public boolean supports(ConfigAttribute attribute) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
return true;
|
||||
}
|
||||
public boolean supports(Class clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-35
@@ -15,11 +15,9 @@
|
||||
|
||||
package org.springframework.security.event.authorization;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.AuthenticationCredentialsNotFoundException;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
|
||||
|
||||
@@ -29,42 +27,22 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationCredentialsNotFoundEventTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AuthenticationCredentialsNotFoundEventTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AuthenticationCredentialsNotFoundEventTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
public class AuthenticationCredentialsNotFoundEventTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls() {
|
||||
try {
|
||||
new AuthenticationCredentialsNotFoundEvent(null, new ConfigAttributeDefinition(new String[] {}),
|
||||
new AuthenticationCredentialsNotFoundEvent(null, SecurityConfig.createList("TEST"),
|
||||
new AuthenticationCredentialsNotFoundException("test"));
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(), null,
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls2() {
|
||||
new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(), null,
|
||||
new AuthenticationCredentialsNotFoundException("test"));
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(), new ConfigAttributeDefinition(new String[] {}),
|
||||
null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls3() {
|
||||
new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(), SecurityConfig.createList("TEST"), null);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-51
@@ -15,15 +15,10 @@
|
||||
|
||||
package org.springframework.security.event.authorization;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
|
||||
import org.springframework.security.event.authorization.AuthorizationFailureEvent;
|
||||
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
|
||||
|
||||
@@ -33,54 +28,29 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthorizationFailureEventTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AuthorizationFailureEventTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AuthorizationFailureEventTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(AuthorizationFailureEventTests.class);
|
||||
}
|
||||
public class AuthorizationFailureEventTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls() {
|
||||
try {
|
||||
new AuthorizationFailureEvent(null, ConfigAttributeDefinition.NO_ATTRIBUTES,
|
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), new AccessDeniedException("error"));
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
new AuthorizationFailureEvent(null, SecurityConfig.createList("TEST"),
|
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), new AccessDeniedException("error"));
|
||||
}
|
||||
|
||||
try {
|
||||
new AuthorizationFailureEvent(new SimpleMethodInvocation(), null,
|
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), new AccessDeniedException("error"));
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls2() {
|
||||
new AuthorizationFailureEvent(new SimpleMethodInvocation(), null,
|
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), new AccessDeniedException("error"));
|
||||
}
|
||||
|
||||
try {
|
||||
new AuthorizationFailureEvent(new SimpleMethodInvocation(), ConfigAttributeDefinition.NO_ATTRIBUTES, null,
|
||||
new AccessDeniedException("error"));
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls3() {
|
||||
new AuthorizationFailureEvent(new SimpleMethodInvocation(), SecurityConfig.createList("TEST"), null,
|
||||
new AccessDeniedException("error"));
|
||||
}
|
||||
|
||||
try {
|
||||
new AuthorizationFailureEvent(new SimpleMethodInvocation(), ConfigAttributeDefinition.NO_ATTRIBUTES,
|
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls4() {
|
||||
new AuthorizationFailureEvent(new SimpleMethodInvocation(), SecurityConfig.createList("TEST"),
|
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), null);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-37
@@ -15,12 +15,9 @@
|
||||
|
||||
package org.springframework.security.event.authorization;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
|
||||
|
||||
@@ -30,41 +27,21 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthorizedEventTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AuthorizedEventTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AuthorizedEventTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
public class AuthorizedEventTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls() {
|
||||
try {
|
||||
new AuthorizedEvent(null, ConfigAttributeDefinition.NO_ATTRIBUTES,
|
||||
new UsernamePasswordAuthenticationToken("foo", "bar"));
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
new AuthorizedEvent(null, SecurityConfig.createList("TEST"), new UsernamePasswordAuthenticationToken("foo", "bar"));
|
||||
}
|
||||
|
||||
try {
|
||||
new AuthorizedEvent(new SimpleMethodInvocation(), null,
|
||||
new UsernamePasswordAuthenticationToken("foo", "bar"));
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls2() {
|
||||
|
||||
try {
|
||||
new AuthorizedEvent(new SimpleMethodInvocation(), ConfigAttributeDefinition.NO_ATTRIBUTES, null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
new AuthorizedEvent(new SimpleMethodInvocation(), null, new UsernamePasswordAuthenticationToken("foo", "bar"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNulls3() {
|
||||
new AuthorizedEvent(new SimpleMethodInvocation(), SecurityConfig.createList("TEST"), null);
|
||||
}
|
||||
}
|
||||
|
||||
+23
-13
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.annotation.ExpressionProtectedBusinessServiceImpl;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
@@ -40,43 +40,53 @@ public class MethodExpressionVoterTests {
|
||||
|
||||
@Test
|
||||
public void hasRoleExpressionAllowsUserWithRole() throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new PreInvocationExpressionConfigAttribute(null, null, "hasRole('blah')"));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, miStringArgs, cad));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, miStringArgs, createAttributes(new PreInvocationExpressionConfigAttribute(null, null, "hasRole('blah')"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasRoleExpressionDeniesUserWithoutRole() throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new PreInvocationExpressionConfigAttribute(null, null, "hasRole('joedoesnt')"));
|
||||
List<ConfigAttribute> cad = new ArrayList<ConfigAttribute>(1);
|
||||
cad.add(new PreInvocationExpressionConfigAttribute(null, null, "hasRole('joedoesnt')"));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_DENIED, am.vote(joe, miStringArgs, cad));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchingArgAgainstAuthenticationNameIsSuccessful() throws Exception {
|
||||
// userName is an argument name of this method
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new PreInvocationExpressionConfigAttribute(null, null, "(#userName == principal) and (principal == 'joe')"));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, miStringArgs, cad));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED,
|
||||
am.vote(joe, miStringArgs, createAttributes(new PreInvocationExpressionConfigAttribute(null, null, "(#userName == principal) and (principal == 'joe')"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessIsGrantedIfNoPreAuthorizeAttributeIsUsed() throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new PreInvocationExpressionConfigAttribute("(filterObject == 'jim')", "someList", null));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, miListArg, cad));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED,
|
||||
am.vote(joe, miListArg, createAttributes(new PreInvocationExpressionConfigAttribute("(filterObject == 'jim')", "someList", null))));
|
||||
// All objects should have been removed, because the expression is always false
|
||||
assertEquals(0, listArg.size());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void arraysCannotBePrefiltered() throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new PreInvocationExpressionConfigAttribute("(filterObject == 'jim')", "someArray", null));
|
||||
am.vote(joe, miArrayArg, cad);
|
||||
am.vote(joe, miArrayArg,
|
||||
createAttributes(new PreInvocationExpressionConfigAttribute("(filterObject == 'jim')", "someArray", null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listPreFilteringIsSuccessful() throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new PreInvocationExpressionConfigAttribute("(filterObject == 'joe' or filterObject == 'sam')", "someList", null));
|
||||
am.vote(joe, miListArg, cad);
|
||||
am.vote(joe, miListArg,
|
||||
createAttributes(new PreInvocationExpressionConfigAttribute("(filterObject == 'joe' or filterObject == 'sam')", "someList", null)));
|
||||
assertEquals("joe and sam should still be in the list", 2, listArg.size());
|
||||
assertEquals("joe", listArg.get(0));
|
||||
assertEquals("sam", listArg.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ruleDefinedInAClassMethodIsApplied() throws Exception {
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, miStringArgs,
|
||||
createAttributes(new PreInvocationExpressionConfigAttribute(null, null, "new org.springframework.security.expression.support.SecurityRules().isJoe(#userName)"))));
|
||||
}
|
||||
|
||||
private List<ConfigAttribute> createAttributes(ConfigAttribute... attributes) {
|
||||
return Arrays.asList(attributes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-30
@@ -15,13 +15,17 @@
|
||||
|
||||
package org.springframework.security.intercept;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
import java.util.List;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,39 +34,17 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InterceptorStatusTokenTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public InterceptorStatusTokenTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InterceptorStatusTokenTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testNoArgConstructorDoesntExist() {
|
||||
Class clazz = InterceptorStatusToken.class;
|
||||
|
||||
try {
|
||||
clazz.getDeclaredConstructor((Class[]) null);
|
||||
fail("Should have thrown NoSuchMethodException");
|
||||
} catch (NoSuchMethodException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
public class InterceptorStatusTokenTests {
|
||||
|
||||
@Test
|
||||
public void testOperation() {
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("FOO");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("FOO");
|
||||
MethodInvocation mi = new SimpleMethodInvocation();
|
||||
|
||||
InterceptorStatusToken token = new InterceptorStatusToken(new UsernamePasswordAuthenticationToken("rod",
|
||||
"koala"), true, attr, mi);
|
||||
|
||||
assertTrue(token.isContextHolderRefreshRequired());
|
||||
assertEquals(attr, token.getAttr());
|
||||
assertEquals(attr, token.getAttributes());
|
||||
assertEquals(mi, token.getSecureObject());
|
||||
assertEquals("rod", token.getAuthentication().getPrincipal());
|
||||
}
|
||||
|
||||
+7
-10
@@ -15,24 +15,21 @@
|
||||
|
||||
package org.springframework.security.intercept.method;
|
||||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.ITargetObject;
|
||||
import org.springframework.security.MockJoinPoint;
|
||||
import org.springframework.security.OtherTargetObject;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.TargetObject;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link MethodDefinitionSourceEditor} and its associated {@link MapBasedMethodDefinitionSource}.
|
||||
@@ -149,7 +146,7 @@ public class MethodDefinitionSourceEditorTests extends TestCase {
|
||||
"org.springframework.security.TargetObject.countLength=ROLE_ONE,ROLE_TWO,RUN_AS_ENTRY\r\norg.springframework.security.TargetObject.make*=ROLE_NINE,ROLE_SUPERVISOR");
|
||||
|
||||
MapBasedMethodDefinitionSource map = (MapBasedMethodDefinitionSource) editor.getValue();
|
||||
Iterator iter = map.getConfigAttributeDefinitions().iterator();
|
||||
Iterator iter = map.getAllConfigAttributes().iterator();
|
||||
int counter = 0;
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
||||
+6
-8
@@ -15,18 +15,16 @@
|
||||
|
||||
package org.springframework.security.intercept.method;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -64,7 +62,7 @@ public class MockMethodDefinitionSource implements MethodDefinitionSource {
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public Collection<List<? extends ConfigAttribute>> getConfigAttributeDefinitions() {
|
||||
public Collection<List<? extends ConfigAttribute>> getAllConfigAttributes() {
|
||||
if (returnACollection) {
|
||||
return list;
|
||||
} else {
|
||||
|
||||
+10
-17
@@ -15,8 +15,14 @@
|
||||
|
||||
package org.springframework.security.intercept.method.aopalliance;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.security.AccessDecisionManager;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.AfterInvocationManager;
|
||||
@@ -24,7 +30,6 @@ import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationCredentialsNotFoundException;
|
||||
import org.springframework.security.AuthenticationException;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.ITargetObject;
|
||||
@@ -33,24 +38,12 @@ import org.springframework.security.MockAfterInvocationManager;
|
||||
import org.springframework.security.MockAuthenticationManager;
|
||||
import org.springframework.security.MockRunAsManager;
|
||||
import org.springframework.security.RunAsManager;
|
||||
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
|
||||
import org.springframework.security.intercept.method.MethodDefinitionSource;
|
||||
import org.springframework.security.intercept.method.MockMethodDefinitionSource;
|
||||
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
import org.springframework.security.runas.RunAsManagerImpl;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link MethodSecurityInterceptor}.
|
||||
@@ -409,7 +402,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockAccessDecisionManagerWhichOnlySupportsStrings implements AccessDecisionManager {
|
||||
public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)
|
||||
public void decide(Authentication authentication, Object object, List<ConfigAttribute> configAttributes)
|
||||
throws AccessDeniedException {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
@@ -428,7 +421,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockAfterInvocationManagerWhichOnlySupportsStrings implements AfterInvocationManager {
|
||||
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config,
|
||||
public Object decide(Authentication authentication, Object object, List<ConfigAttribute> config,
|
||||
Object returnedObject) throws AccessDeniedException {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
@@ -447,7 +440,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockObjectDefinitionSourceWhichOnlySupportsStrings implements MethodDefinitionSource {
|
||||
public Collection<List<? extends ConfigAttribute>> getConfigAttributeDefinitions() {
|
||||
public Collection<List<? extends ConfigAttribute>> getAllConfigAttributes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -469,7 +462,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockRunAsManagerWhichOnlySupportsStrings implements RunAsManager {
|
||||
public Authentication buildRunAs(Authentication authentication, Object object, ConfigAttributeDefinition config) {
|
||||
public Authentication buildRunAs(Authentication authentication, Object object, List<ConfigAttribute> config) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.intercept.web;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link DefaultFilterInvocationDefinitionSource}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AbstractFilterInvocationDefinitionSourceTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AbstractFilterInvocationDefinitionSourceTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AbstractFilterInvocationDefinitionSourceTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testDoesNotSupportAnotherObject() {
|
||||
MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(false, true);
|
||||
assertFalse(mfis.supports(String.class));
|
||||
}
|
||||
|
||||
public void testGetAttributesForANonFilterInvocation() {
|
||||
MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(false, true);
|
||||
|
||||
try {
|
||||
mfis.getAttributes(new String());
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetAttributesForANullObject() {
|
||||
MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(false, true);
|
||||
|
||||
try {
|
||||
mfis.getAttributes(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetAttributesForFilterInvocationSuccess() {
|
||||
MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(false, true);
|
||||
|
||||
try {
|
||||
mfis.getAttributes(new FilterInvocation(new MockHttpServletRequest(null, null),
|
||||
new MockHttpServletResponse(), new MockFilterChain()));
|
||||
fail("Should have thrown UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testSupportsFilterInvocation() {
|
||||
MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(false, true);
|
||||
assertTrue(mfis.supports(FilterInvocation.class));
|
||||
}
|
||||
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockFilterChain implements FilterChain {
|
||||
public void doFilter(ServletRequest arg0, ServletResponse arg1)
|
||||
throws IOException, ServletException {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-38
@@ -16,7 +16,6 @@
|
||||
package org.springframework.security.intercept.web;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -30,7 +29,6 @@ import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.MockFilterChain;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.util.AntUrlPathMatcher;
|
||||
import org.springframework.security.util.InMemoryXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Tests parts of {@link DefaultFilterInvocationDefinitionSource} not tested by {@link
|
||||
@@ -136,14 +134,14 @@ public class DefaultFilterInvocationDefinitionSourceTests {
|
||||
@Test
|
||||
public void httpMethodSpecificUrlTakesPrecedence() {
|
||||
// Even though this is added before the method-specific def, the latter should match
|
||||
List<? extends ConfigAttribute> allMethodDef = def;
|
||||
map.addSecureUrl("/**", null, def);
|
||||
List<ConfigAttribute> allMethodDef = def;
|
||||
map.addSecureUrl("/**", null, allMethodDef);
|
||||
|
||||
List<? extends ConfigAttribute> postOnlyDef = SecurityConfig.createList("ROLE_TWO");
|
||||
List<ConfigAttribute> postOnlyDef = SecurityConfig.createList("ROLE_TWO");
|
||||
map.addSecureUrl("/somepage**", "POST", postOnlyDef);
|
||||
|
||||
FilterInvocation fi = createFilterInvocation("/somepage", "POST");
|
||||
List<? extends ConfigAttribute> attrs = map.getAttributes(fi);
|
||||
List<ConfigAttribute> attrs = map.getAttributes(fi);
|
||||
assertEquals(postOnlyDef, attrs);
|
||||
}
|
||||
|
||||
@@ -165,38 +163,6 @@ public class DefaultFilterInvocationDefinitionSourceTests {
|
||||
assertEquals(def, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlMapConfigurationIsSuccessful() {
|
||||
InMemoryXmlApplicationContext context = new InMemoryXmlApplicationContext(
|
||||
"<b:bean id='fids' class='org.springframework.security.intercept.web.DefaultFilterInvocationDefinitionSource'>" +
|
||||
" <b:constructor-arg>" +
|
||||
" <b:bean class='org.springframework.security.util.AntUrlPathMatcher'/>" +
|
||||
" </b:constructor-arg>" +
|
||||
" <b:constructor-arg>" +
|
||||
" <b:map>" +
|
||||
" <b:entry>" +
|
||||
" <b:key>" +
|
||||
" <b:bean class='org.springframework.security.intercept.web.RequestKey'>" +
|
||||
" <b:constructor-arg index='0' value='/**'/>" +
|
||||
" <b:constructor-arg index='1' value='GET'/>" +
|
||||
" </b:bean>" +
|
||||
" </b:key>" +
|
||||
" <b:bean class='org.springframework.security.ConfigAttributeDefinition'>" +
|
||||
" <b:constructor-arg value='ROLE_A'/>" +
|
||||
" </b:bean>" +
|
||||
" </b:entry>" +
|
||||
" </b:map>" +
|
||||
" </b:constructor-arg>" +
|
||||
"</b:bean>"
|
||||
);
|
||||
|
||||
DefaultFilterInvocationDefinitionSource fids = (DefaultFilterInvocationDefinitionSource) context.getBean("fids");
|
||||
List<? extends ConfigAttribute> cad = fids.lookupAttributes("/anything", "GET");
|
||||
assertNotNull(cad);
|
||||
assertEquals(1, cad.size());
|
||||
context.close();
|
||||
}
|
||||
|
||||
private FilterInvocation createFilterInvocation(String path, String method) {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setRequestURI(null);
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ public class FilterInvocationDefinitionSourceEditorTests extends TestCase {
|
||||
editor.setAsText("\\A/secure/super.*\\Z=ROLE_WE_DONT_HAVE\r\n\\A/secure/.*\\Z=ROLE_SUPERVISOR,ROLE_TELLER");
|
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue();
|
||||
Iterator iter = map.getConfigAttributeDefinitions().iterator();
|
||||
Iterator iter = map.getAllConfigAttributes().iterator();
|
||||
int counter = 0;
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
||||
+26
-28
@@ -15,30 +15,7 @@
|
||||
|
||||
package org.springframework.security.intercept.web;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.AccessDecisionManager;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.MockAccessDecisionManager;
|
||||
import org.springframework.security.MockAuthenticationManager;
|
||||
import org.springframework.security.MockRunAsManager;
|
||||
import org.springframework.security.RunAsManager;
|
||||
import org.springframework.security.MockApplicationEventPublisher;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.util.AntUrlPathMatcher;
|
||||
import org.springframework.security.util.RegexUrlPathMatcher;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -48,6 +25,27 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.security.AccessDecisionManager;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.MockAccessDecisionManager;
|
||||
import org.springframework.security.MockApplicationEventPublisher;
|
||||
import org.springframework.security.MockAuthenticationManager;
|
||||
import org.springframework.security.MockRunAsManager;
|
||||
import org.springframework.security.RunAsManager;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.util.AntUrlPathMatcher;
|
||||
import org.springframework.security.util.RegexUrlPathMatcher;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link FilterSecurityInterceptor}.
|
||||
@@ -92,7 +90,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)
|
||||
public void decide(Authentication authentication, Object object, List<ConfigAttribute> configAttributes)
|
||||
throws AccessDeniedException {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
@@ -124,7 +122,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
}
|
||||
|
||||
public Authentication buildRunAs(Authentication authentication, Object object,
|
||||
ConfigAttributeDefinition config) {
|
||||
List<ConfigAttribute> config) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
});
|
||||
@@ -221,9 +219,9 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
|
||||
public void testNotLoadedFromApplicationContext() throws Exception {
|
||||
LinkedHashMap reqMap = new LinkedHashMap();
|
||||
reqMap.put(new RequestKey("/secure/**", null), new ConfigAttributeDefinition(new String[] {"ROLE_USER"}));
|
||||
reqMap.put(new RequestKey("/secure/**", null), SecurityConfig.createList("ROLE_USER"));
|
||||
DefaultFilterInvocationDefinitionSource fids
|
||||
= new DefaultFilterInvocationDefinitionSource(new AntUrlPathMatcher());
|
||||
= new DefaultFilterInvocationDefinitionSource(new AntUrlPathMatcher(), reqMap);
|
||||
|
||||
FilterSecurityInterceptor filter = new FilterSecurityInterceptor();
|
||||
filter.setObjectDefinitionSource(fids);
|
||||
@@ -278,7 +276,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<List<? extends ConfigAttribute>> getConfigAttributeDefinitions() {
|
||||
public Collection<List<? extends ConfigAttribute>> getAllConfigAttributes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.intercept.web;
|
||||
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.util.AntUrlPathMatcher;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* Mock for {@link FilterInvocationDefinitionSource}
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MockFilterInvocationDefinitionSource extends DefaultFilterInvocationDefinitionSource {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private List list;
|
||||
private boolean returnAnIterator;
|
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public MockFilterInvocationDefinitionSource(boolean includeInvalidAttributes, boolean returnAnIteratorWhenRequested) {
|
||||
super(new AntUrlPathMatcher()); // doesn't matter
|
||||
returnAnIterator = returnAnIteratorWhenRequested;
|
||||
list = new Vector();
|
||||
|
||||
ConfigAttributeDefinition def1 = new ConfigAttributeDefinition("MOCK_LOWER");
|
||||
list.add(def1);
|
||||
|
||||
if (includeInvalidAttributes) {
|
||||
ConfigAttributeDefinition def2 = new ConfigAttributeDefinition(new String[] {"MOCK_LOWER", "INVALID_ATTRIBUTE"});
|
||||
list.add(def2);
|
||||
}
|
||||
|
||||
ConfigAttributeDefinition def3 = new ConfigAttributeDefinition(new String[] {"MOCK_UPPER","RUN_AS"});
|
||||
list.add(def3);
|
||||
|
||||
if (includeInvalidAttributes) {
|
||||
ConfigAttributeDefinition def4 = new ConfigAttributeDefinition(new String[] {"MOCK_SOMETHING","ANOTHER_INVALID"});
|
||||
list.add(def4);
|
||||
}
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public Collection<List<? extends ConfigAttribute>> getConfigAttributeDefinitions() {
|
||||
if (returnAnIterator) {
|
||||
return list;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ConfigAttribute> lookupAttributes(String url, String method) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,10 @@ package org.springframework.security.runas;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.RunAsManager;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
|
||||
@@ -34,46 +32,23 @@ import org.springframework.security.providers.UsernamePasswordAuthenticationToke
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RunAsManagerImplTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public RunAsManagerImplTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public RunAsManagerImplTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(RunAsManagerImplTests.class);
|
||||
}
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testAlwaysSupportsClass() {
|
||||
RunAsManagerImpl runAs = new RunAsManagerImpl();
|
||||
assertTrue(runAs.supports(String.class));
|
||||
}
|
||||
|
||||
public void testDoesNotReturnAdditionalAuthoritiesIfCalledWithoutARunAsSetting()
|
||||
throws Exception {
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition("SOMETHING_WE_IGNORE");
|
||||
public void testDoesNotReturnAdditionalAuthoritiesIfCalledWithoutARunAsSetting() throws Exception {
|
||||
UsernamePasswordAuthenticationToken inputToken = new UsernamePasswordAuthenticationToken("Test", "Password",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
|
||||
|
||||
RunAsManagerImpl runAs = new RunAsManagerImpl();
|
||||
runAs.setKey("my_password");
|
||||
|
||||
Authentication resultingToken = runAs.buildRunAs(inputToken, new Object(), def);
|
||||
Authentication resultingToken = runAs.buildRunAs(inputToken, new Object(), SecurityConfig.createList("SOMETHING_WE_IGNORE"));
|
||||
assertEquals(null, resultingToken);
|
||||
}
|
||||
|
||||
public void testRespectsRolePrefix() throws Exception {
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition("RUN_AS_SOMETHING");
|
||||
UsernamePasswordAuthenticationToken inputToken = new UsernamePasswordAuthenticationToken("Test", "Password",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ONE"), new GrantedAuthorityImpl("TWO")});
|
||||
|
||||
@@ -81,7 +56,7 @@ public class RunAsManagerImplTests extends TestCase {
|
||||
runAs.setKey("my_password");
|
||||
runAs.setRolePrefix("FOOBAR_");
|
||||
|
||||
Authentication resultingToken = runAs.buildRunAs(inputToken, new Object(), def);
|
||||
Authentication resultingToken = runAs.buildRunAs(inputToken, new Object(), SecurityConfig.createList("RUN_AS_SOMETHING"));
|
||||
|
||||
if (!(resultingToken instanceof RunAsUserToken)) {
|
||||
fail("Should have returned a RunAsUserToken");
|
||||
@@ -98,14 +73,13 @@ public class RunAsManagerImplTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testReturnsAdditionalGrantedAuthorities() throws Exception {
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition("RUN_AS_SOMETHING");
|
||||
UsernamePasswordAuthenticationToken inputToken = new UsernamePasswordAuthenticationToken("Test", "Password",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
|
||||
|
||||
RunAsManagerImpl runAs = new RunAsManagerImpl();
|
||||
runAs.setKey("my_password");
|
||||
|
||||
Authentication resultingToken = runAs.buildRunAs(inputToken, new Object(), def);
|
||||
Authentication resultingToken = runAs.buildRunAs(inputToken, new Object(), SecurityConfig.createList("RUN_AS_SOMETHING"));
|
||||
|
||||
if (!(resultingToken instanceof RunAsUserToken)) {
|
||||
fail("Should have returned a RunAsUserToken");
|
||||
|
||||
+5
-10
@@ -18,7 +18,6 @@ package org.springframework.security.securechannel;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.MockFilterChain;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
@@ -95,7 +94,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition("xyz");
|
||||
List<ConfigAttribute> cad = SecurityConfig.createList("xyz");
|
||||
|
||||
cdm.decide(fi, cad);
|
||||
assertTrue(fi.getResponse().isCommitted());
|
||||
@@ -114,9 +113,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new String[]{"abc", "ANY_CHANNEL"});
|
||||
|
||||
cdm.decide(fi, cad);
|
||||
cdm.decide(fi, SecurityConfig.createList(new String[]{"abc", "ANY_CHANNEL"}));
|
||||
assertFalse(fi.getResponse().isCommitted());
|
||||
}
|
||||
|
||||
@@ -135,9 +132,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition("SOME_ATTRIBUTE_NO_PROCESSORS_SUPPORT");
|
||||
|
||||
cdm.decide(fi, cad);
|
||||
cdm.decide(fi, SecurityConfig.createList("SOME_ATTRIBUTE_NO_PROCESSORS_SUPPORT"));
|
||||
assertFalse(fi.getResponse().isCommitted());
|
||||
}
|
||||
|
||||
@@ -192,9 +187,9 @@ public class ChannelDecisionManagerImplTests extends TestCase {
|
||||
this.failIfCalled = failIfCalled;
|
||||
}
|
||||
|
||||
public void decide(FilterInvocation invocation, ConfigAttributeDefinition config)
|
||||
public void decide(FilterInvocation invocation, List<ConfigAttribute> config)
|
||||
throws IOException, ServletException {
|
||||
Iterator iter = config.getConfigAttributes().iterator();
|
||||
Iterator iter = config.iterator();
|
||||
|
||||
if (failIfCalled) {
|
||||
fail("Should not have called this channel processor: " + configAttribute);
|
||||
|
||||
+2
-3
@@ -18,7 +18,6 @@ package org.springframework.security.securechannel;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
@@ -208,7 +207,7 @@ public class ChannelProcessingFilterTests extends TestCase {
|
||||
this.supportAttribute = supportAttribute;
|
||||
}
|
||||
|
||||
public void decide(FilterInvocation invocation, ConfigAttributeDefinition config)
|
||||
public void decide(FilterInvocation invocation, List<ConfigAttribute> config)
|
||||
throws IOException, ServletException {
|
||||
if (commitAResponse) {
|
||||
invocation.getHttpResponse().sendRedirect("/redirected");
|
||||
@@ -267,7 +266,7 @@ public class ChannelProcessingFilterTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<List<? extends ConfigAttribute>> getConfigAttributeDefinitions() {
|
||||
public Collection<List<? extends ConfigAttribute>> getAllConfigAttributes() {
|
||||
if (!provideIterator) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+5
-21
@@ -17,14 +17,11 @@ package org.springframework.security.securechannel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.MockFilterChain;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.security.MockFilterChain;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,19 +31,8 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InsecureChannelProcessorTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(InsecureChannelProcessorTests.class);
|
||||
}
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testDecideDetectsAcceptableChannel() throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new String[]{"SOME_IGNORED_ATTRIBUTE", "REQUIRES_INSECURE_CHANNEL"});
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setQueryString("info=true");
|
||||
request.setServerName("localhost");
|
||||
@@ -60,15 +46,13 @@ public class InsecureChannelProcessorTests extends TestCase {
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
|
||||
InsecureChannelProcessor processor = new InsecureChannelProcessor();
|
||||
processor.decide(fi, cad);
|
||||
processor.decide(fi, SecurityConfig.createList("SOME_IGNORED_ATTRIBUTE", "REQUIRES_INSECURE_CHANNEL"));
|
||||
|
||||
assertFalse(fi.getResponse().isCommitted());
|
||||
}
|
||||
|
||||
public void testDecideDetectsUnacceptableChannel()
|
||||
throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new String[]{"SOME_IGNORED_ATTRIBUTE", "REQUIRES_INSECURE_CHANNEL"});
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setQueryString("info=true");
|
||||
request.setServerName("localhost");
|
||||
@@ -83,7 +67,7 @@ public class InsecureChannelProcessorTests extends TestCase {
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
|
||||
InsecureChannelProcessor processor = new InsecureChannelProcessor();
|
||||
processor.decide(fi, cad);
|
||||
processor.decide(fi, SecurityConfig.createList(new String[]{"SOME_IGNORED_ATTRIBUTE", "REQUIRES_INSECURE_CHANNEL"}));
|
||||
|
||||
assertTrue(fi.getResponse().isCommitted());
|
||||
}
|
||||
|
||||
+5
-12
@@ -17,14 +17,11 @@ package org.springframework.security.securechannel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.MockFilterChain;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.security.MockFilterChain;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
|
||||
|
||||
/**
|
||||
@@ -37,8 +34,6 @@ public class SecureChannelProcessorTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testDecideDetectsAcceptableChannel() throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new String[]{"SOME_IGNORED_ATTRIBUTE", "REQUIRES_SECURE_CHANNEL"});
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setQueryString("info=true");
|
||||
request.setServerName("localhost");
|
||||
@@ -53,14 +48,12 @@ public class SecureChannelProcessorTests extends TestCase {
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
|
||||
SecureChannelProcessor processor = new SecureChannelProcessor();
|
||||
processor.decide(fi, cad);
|
||||
processor.decide(fi, SecurityConfig.createList("SOME_IGNORED_ATTRIBUTE", "REQUIRES_SECURE_CHANNEL"));
|
||||
|
||||
assertFalse(fi.getResponse().isCommitted());
|
||||
}
|
||||
|
||||
public void testDecideDetectsUnacceptableChannel() throws Exception {
|
||||
ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new String[]{"SOME_IGNORED_ATTRIBUTE", "REQUIRES_SECURE_CHANNEL"});
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setQueryString("info=true");
|
||||
request.setServerName("localhost");
|
||||
@@ -74,7 +67,7 @@ public class SecureChannelProcessorTests extends TestCase {
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
|
||||
SecureChannelProcessor processor = new SecureChannelProcessor();
|
||||
processor.decide(fi, cad);
|
||||
processor.decide(fi, SecurityConfig.createList(new String[]{"SOME_IGNORED_ATTRIBUTE", "REQUIRES_SECURE_CHANNEL"}));
|
||||
|
||||
assertTrue(fi.getResponse().isCommitted());
|
||||
}
|
||||
|
||||
@@ -15,29 +15,26 @@
|
||||
|
||||
package org.springframework.security.util;
|
||||
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.MockFilterConfig;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.context.HttpSessionContextIntegrationFilter;
|
||||
import org.springframework.security.intercept.web.MockFilterInvocationDefinitionSource;
|
||||
import org.springframework.security.intercept.web.DefaultFilterInvocationDefinitionSource;
|
||||
import org.springframework.security.intercept.web.RequestKey;
|
||||
import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import org.springframework.security.MockFilterConfig;
|
||||
import org.springframework.security.context.HttpSessionContextIntegrationFilter;
|
||||
import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
|
||||
|
||||
/**
|
||||
* Tests {@link FilterChainProxy}.
|
||||
@@ -63,31 +60,6 @@ public class FilterChainProxyTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testDetectsFilterInvocationDefinitionSourceThatDoesNotReturnAllConfigAttributes() throws Exception {
|
||||
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
||||
filterChainProxy.setApplicationContext(new StaticApplicationContext());
|
||||
|
||||
filterChainProxy.setFilterInvocationDefinitionSource(new MockFilterInvocationDefinitionSource(false, false));
|
||||
filterChainProxy.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testDetectsIfConfigAttributeDoesNotReturnValueForGetAttributeMethod() throws Exception {
|
||||
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
||||
filterChainProxy.setApplicationContext(new StaticApplicationContext());
|
||||
|
||||
LinkedHashMap map = new LinkedHashMap();
|
||||
map.put(new RequestKey("/**"), SecurityConfig.createList(null));
|
||||
DefaultFilterInvocationDefinitionSource fids =
|
||||
new DefaultFilterInvocationDefinitionSource(new AntUrlPathMatcher(), map);
|
||||
|
||||
filterChainProxy.setFilterInvocationDefinitionSource(fids);
|
||||
|
||||
filterChainProxy.afterPropertiesSet();
|
||||
filterChainProxy.init(new MockFilterConfig());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsMissingFilterInvocationDefinitionSource() throws Exception {
|
||||
FilterChainProxy filterChainProxy = new FilterChainProxy();
|
||||
|
||||
+2
-3
@@ -20,7 +20,6 @@ import junit.framework.TestCase;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import java.util.List;
|
||||
@@ -162,7 +161,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockDecisionManagerImpl extends AbstractAccessDecisionManager {
|
||||
public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)
|
||||
public void decide(Authentication authentication, Object object, List<ConfigAttribute> configAttributes)
|
||||
throws AccessDeniedException {
|
||||
return;
|
||||
}
|
||||
@@ -181,7 +180,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {
|
||||
public int vote(Authentication authentication, Object object, List<ConfigAttribute> attributes) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link AffirmativeBased}.
|
||||
@@ -34,29 +34,14 @@ import java.util.Vector;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AffirmativeBasedTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AffirmativeBasedTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AffirmativeBasedTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(AffirmativeBasedTests.class);
|
||||
}
|
||||
public class AffirmativeBasedTests {
|
||||
|
||||
private AffirmativeBased makeDecisionManager() {
|
||||
AffirmativeBased decisionManager = new AffirmativeBased();
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
DenyVoter denyForSureVoter = new DenyVoter();
|
||||
DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
|
||||
List voters = new Vector();
|
||||
List voters = new ArrayList();
|
||||
voters.add(roleVoter);
|
||||
voters.add(denyForSureVoter);
|
||||
voters.add(denyAgainForSureVoter);
|
||||
@@ -70,85 +55,55 @@ public class AffirmativeBasedTests extends TestCase {
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_1"), new GrantedAuthorityImpl("ROLE_2")});
|
||||
}
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteGrantsAccess()
|
||||
throws Exception {
|
||||
@Test
|
||||
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteGrantsAccess() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
AffirmativeBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "DENY_FOR_SURE"});
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList(new String[]{"ROLE_1", "DENY_FOR_SURE"}));
|
||||
}
|
||||
|
||||
public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess()
|
||||
throws Exception {
|
||||
@Test
|
||||
public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
AffirmativeBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_2");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("ROLE_2"));
|
||||
}
|
||||
|
||||
public void testOneDenyVoteTwoAbstainVotesDeniesAccess()
|
||||
throws Exception {
|
||||
@Test(expected=AccessDeniedException.class)
|
||||
public void testOneDenyVoteTwoAbstainVotesDeniesAccess() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
AffirmativeBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_WE_DO_NOT_HAVE");
|
||||
|
||||
try {
|
||||
mgr.decide(auth, new Object(), config);
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
} catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("ROLE_WE_DO_NOT_HAVE"));
|
||||
}
|
||||
|
||||
public void testThreeAbstainVotesDeniesAccessWithDefault()
|
||||
throws Exception {
|
||||
@Test(expected=AccessDeniedException.class)
|
||||
public void testThreeAbstainVotesDeniesAccessWithDefault() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
AffirmativeBased mgr = makeDecisionManager();
|
||||
|
||||
assertTrue(!mgr.isAllowIfAllAbstainDecisions()); // check default
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("IGNORED_BY_ALL");
|
||||
|
||||
try {
|
||||
mgr.decide(auth, new Object(), config);
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
} catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("IGNORED_BY_ALL"));
|
||||
}
|
||||
|
||||
public void testThreeAbstainVotesGrantsAccessWithoutDefault()
|
||||
throws Exception {
|
||||
@Test
|
||||
public void testThreeAbstainVotesGrantsAccessWithoutDefault() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
AffirmativeBased mgr = makeDecisionManager();
|
||||
mgr.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mgr.isAllowIfAllAbstainDecisions()); // check changed
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("IGNORED_BY_ALL");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("IGNORED_BY_ALL"));
|
||||
}
|
||||
|
||||
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess()
|
||||
throws Exception {
|
||||
@Test
|
||||
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
AffirmativeBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "ROLE_2"});
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("ROLE_1", "ROLE_2"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,15 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.providers.anonymous.AnonymousAuthenticationToken;
|
||||
import org.springframework.security.providers.rememberme.RememberMeAuthenticationToken;
|
||||
@@ -35,17 +36,6 @@ import org.springframework.security.providers.rememberme.RememberMeAuthenticatio
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticatedVoterTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AuthenticatedVoterTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AuthenticatedVoterTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
private Authentication createAnonymous() {
|
||||
return new AnonymousAuthenticationToken("ignored", "ignored",
|
||||
@@ -62,17 +52,9 @@ public class AuthenticatedVoterTests extends TestCase {
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ignored")});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(AuthenticatedVoterTests.class);
|
||||
}
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testAnonymousWorks() {
|
||||
AuthenticatedVoter voter = new AuthenticatedVoter();
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition(AuthenticatedVoter.IS_AUTHENTICATED_ANONYMOUSLY);
|
||||
List<ConfigAttribute> def = SecurityConfig.createList(AuthenticatedVoter.IS_AUTHENTICATED_ANONYMOUSLY);
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(createAnonymous(), null, def));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(createRememberMe(), null, def));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(createFullyAuthenticated(), null, def));
|
||||
@@ -80,7 +62,7 @@ public class AuthenticatedVoterTests extends TestCase {
|
||||
|
||||
public void testFullyWorks() {
|
||||
AuthenticatedVoter voter = new AuthenticatedVoter();
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition(AuthenticatedVoter.IS_AUTHENTICATED_FULLY);
|
||||
List<ConfigAttribute> def = SecurityConfig.createList(AuthenticatedVoter.IS_AUTHENTICATED_FULLY);
|
||||
assertEquals(AccessDecisionVoter.ACCESS_DENIED, voter.vote(createAnonymous(), null, def));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_DENIED, voter.vote(createRememberMe(), null, def));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(createFullyAuthenticated(), null, def));
|
||||
@@ -88,7 +70,7 @@ public class AuthenticatedVoterTests extends TestCase {
|
||||
|
||||
public void testRememberMeWorks() {
|
||||
AuthenticatedVoter voter = new AuthenticatedVoter();
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition(AuthenticatedVoter.IS_AUTHENTICATED_REMEMBERED);
|
||||
List<ConfigAttribute> def = SecurityConfig.createList(AuthenticatedVoter.IS_AUTHENTICATED_REMEMBERED);
|
||||
assertEquals(AccessDecisionVoter.ACCESS_DENIED, voter.vote(createAnonymous(), null, def));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(createRememberMe(), null, def));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(createFullyAuthenticated(), null, def));
|
||||
|
||||
@@ -15,10 +15,15 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.springframework.security.AuthorizationServiceException;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.MockAclManager;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.acl.AclEntry;
|
||||
@@ -27,10 +32,6 @@ import org.springframework.security.acl.basic.MockAclObjectIdentity;
|
||||
import org.springframework.security.acl.basic.SimpleAclEntry;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Tests {@link BasicAclEntryVoter}.
|
||||
@@ -93,7 +94,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||
voter.afterPropertiesSet();
|
||||
|
||||
// Wire up an invocation to be voted on
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
|
||||
// Setup a MockMethodInvocation, so voter can retrieve domainObject
|
||||
MethodInvocation mi = getMethodInvocation(domainObject);
|
||||
@@ -213,7 +214,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||
voter.afterPropertiesSet();
|
||||
|
||||
// Wire up an invocation to be voted on
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("A_DIFFERENT_ATTRIBUTE");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("A_DIFFERENT_ATTRIBUTE");
|
||||
|
||||
// Setup a MockMethodInvocation, so voter can retrieve domainObject
|
||||
MethodInvocation mi = getMethodInvocation(domainObject);
|
||||
@@ -245,7 +246,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||
voter.afterPropertiesSet();
|
||||
|
||||
// Wire up an invocation to be voted on
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
|
||||
// Setup a MockMethodInvocation, so voter can retrieve domainObject
|
||||
MethodInvocation mi = getMethodInvocation(domainObject);
|
||||
@@ -276,7 +277,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||
voter.afterPropertiesSet();
|
||||
|
||||
// Wire up an invocation to be voted on
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
|
||||
// Setup a MockMethodInvocation, so voter can retrieve domainObject
|
||||
MethodInvocation mi = getMethodInvocation(domainObject);
|
||||
@@ -307,7 +308,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||
voter.afterPropertiesSet();
|
||||
|
||||
// Wire up an invocation to be voted on
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
|
||||
// Setup a MockMethodInvocation, so voter can retrieve domainObject
|
||||
MethodInvocation mi = getMethodInvocation(domainObject);
|
||||
@@ -342,7 +343,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||
voter.afterPropertiesSet();
|
||||
|
||||
// Wire up an invocation to be voted on
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
|
||||
// Setup a MockMethodInvocation, so voter can retrieve domainObject
|
||||
// (well actually it will access domainObject.getParent())
|
||||
@@ -376,7 +377,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||
voter.afterPropertiesSet();
|
||||
|
||||
// Wire up an invocation to be voted on
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
|
||||
// Setup a MockMethodInvocation, so voter can retrieve domainObject
|
||||
// (well actually it will access domainObject.getParent())
|
||||
@@ -413,7 +414,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||
voter.afterPropertiesSet();
|
||||
|
||||
// Wire up an invocation to be voted on
|
||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
List<ConfigAttribute> attr = SecurityConfig.createList("FOO_ADMIN_OR_WRITE_ACCESS");
|
||||
|
||||
// Setup a MockMethodInvocation that doesn't provide SomeDomainObject arg
|
||||
Class clazz = String.class;
|
||||
|
||||
@@ -15,15 +15,17 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
|
||||
|
||||
@@ -33,98 +35,77 @@ import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ConsensusBasedTests extends TestCase {
|
||||
|
||||
//~ Methods ================================================================
|
||||
public class ConsensusBasedTests {
|
||||
|
||||
@Test(expected=AccessDeniedException.class)
|
||||
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteDeniesAccessWithoutDefault() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
mgr.setAllowIfEqualGrantedDeniedDecisions(false);
|
||||
assertTrue(!mgr.isAllowIfEqualGrantedDeniedDecisions()); // check changed
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "DENY_FOR_SURE"});
|
||||
List<ConfigAttribute> config = SecurityConfig.createList(new String[]{"ROLE_1", "DENY_FOR_SURE"});
|
||||
|
||||
try {
|
||||
mgr.decide(auth, new Object(), config);
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
} catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
mgr.decide(auth, new Object(), config);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteGrantsAccessWithDefault() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
|
||||
assertTrue(mgr.isAllowIfEqualGrantedDeniedDecisions()); // check default
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "DENY_FOR_SURE"});
|
||||
List<ConfigAttribute> config = SecurityConfig.createList(new String[]{"ROLE_1", "DENY_FOR_SURE"});
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_2");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("ROLE_2"));
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test(expected=AccessDeniedException.class)
|
||||
public void testOneDenyVoteTwoAbstainVotesDeniesAccess() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_WE_DO_NOT_HAVE");
|
||||
|
||||
try {
|
||||
mgr.decide(auth, new Object(), config);
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
} catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("ROLE_WE_DO_NOT_HAVE"));
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
}
|
||||
|
||||
@Test(expected=AccessDeniedException.class)
|
||||
public void testThreeAbstainVotesDeniesAccessWithDefault() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
|
||||
assertTrue(!mgr.isAllowIfAllAbstainDecisions()); // check default
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("IGNORED_BY_ALL");
|
||||
|
||||
try {
|
||||
mgr.decide(auth, new Object(), config);
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
} catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("IGNORED_BY_ALL"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThreeAbstainVotesGrantsAccessWithoutDefault() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
mgr.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mgr.isAllowIfAllAbstainDecisions()); // check changed
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("IGNORED_BY_ALL");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("IGNORED_BY_ALL"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "ROLE_2"});
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList(new String[]{"ROLE_1", "ROLE_2"}));
|
||||
}
|
||||
|
||||
private ConsensusBased makeDecisionManager() {
|
||||
|
||||
@@ -17,9 +17,9 @@ package org.springframework.security.vote;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of an {@link AccessDecisionVoter} for unit testing.
|
||||
@@ -35,34 +35,34 @@ import java.util.Iterator;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DenyAgainVoter implements AccessDecisionVoter {
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
|
||||
public boolean supports(ConfigAttribute attribute) {
|
||||
if ("DENY_AGAIN_FOR_SURE".equals(attribute.getAttribute())) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public boolean supports(ConfigAttribute attribute) {
|
||||
if ("DENY_AGAIN_FOR_SURE".equals(attribute.getAttribute())) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
return true;
|
||||
}
|
||||
public boolean supports(Class clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {
|
||||
Iterator iter = config.getConfigAttributes().iterator();
|
||||
public int vote(Authentication authentication, Object object, List<ConfigAttribute> attributes) {
|
||||
Iterator iter = attributes.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConfigAttribute attribute = (ConfigAttribute) iter.next();
|
||||
while (iter.hasNext()) {
|
||||
ConfigAttribute attribute = (ConfigAttribute) iter.next();
|
||||
|
||||
if (this.supports(attribute)) {
|
||||
return ACCESS_DENIED;
|
||||
}
|
||||
}
|
||||
if (this.supports(attribute)) {
|
||||
return ACCESS_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
return ACCESS_ABSTAIN;
|
||||
}
|
||||
return ACCESS_ABSTAIN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ package org.springframework.security.vote;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -45,8 +45,8 @@ public class DenyVoter implements AccessDecisionVoter {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {
|
||||
Iterator iter = config.getConfigAttributes().iterator();
|
||||
public int vote(Authentication authentication, Object object, List<ConfigAttribute> attributes) {
|
||||
Iterator iter = attributes.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConfigAttribute attribute = (ConfigAttribute) iter.next();
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
import org.springframework.security.userdetails.hierarchicalroles.RoleHierarchyImpl;
|
||||
|
||||
public class RoleHierarchyVoterTests {
|
||||
|
||||
@Test
|
||||
public void hierarchicalRoleIsIncludedInDecision() {
|
||||
@Test
|
||||
public void hierarchicalRoleIsIncludedInDecision() {
|
||||
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
|
||||
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B");
|
||||
|
||||
// User has role A, role B is required
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("user", "password", "ROLE_A");
|
||||
RoleHierarchyVoter voter = new RoleHierarchyVoter(roleHierarchyImpl);
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_B");
|
||||
|
||||
assertEquals(RoleHierarchyVoter.ACCESS_GRANTED, voter.vote(auth, new Object(), config));
|
||||
}
|
||||
|
||||
assertEquals(RoleHierarchyVoter.ACCESS_GRANTED, voter.vote(auth, new Object(), SecurityConfig.createList("ROLE_B")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
|
||||
package org.springframework.security.vote;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link UnanimousBased}.
|
||||
@@ -86,7 +86,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "DENY_FOR_SURE"});
|
||||
List<ConfigAttribute> config = SecurityConfig.createList(new String[]{"ROLE_1", "DENY_FOR_SURE"});
|
||||
|
||||
try {
|
||||
mgr.decide(auth, new Object(), config);
|
||||
@@ -100,7 +100,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_2");
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("ROLE_2");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
@@ -110,7 +110,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_WE_DO_NOT_HAVE");
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("ROLE_WE_DO_NOT_HAVE");
|
||||
|
||||
try {
|
||||
mgr.decide(auth, new Object(), config);
|
||||
@@ -124,7 +124,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
TestingAuthenticationToken auth = makeTestTokenWithFooBarPrefix();
|
||||
UnanimousBased mgr = makeDecisionManagerWithFooBarPrefix();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"FOOBAR_1", "FOOBAR_2"});
|
||||
List<ConfigAttribute> config = SecurityConfig.createList(new String[]{"FOOBAR_1", "FOOBAR_2"});
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
@@ -136,7 +136,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
|
||||
assertTrue(!mgr.isAllowIfAllAbstainDecisions()); // check default
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("IGNORED_BY_ALL");
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("IGNORED_BY_ALL");
|
||||
|
||||
try {
|
||||
mgr.decide(auth, new Object(), config);
|
||||
@@ -152,7 +152,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
mgr.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mgr.isAllowIfAllAbstainDecisions()); // check changed
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition("IGNORED_BY_ALL");
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("IGNORED_BY_ALL");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
@@ -162,7 +162,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "ROLE_2"});
|
||||
List<ConfigAttribute> config = SecurityConfig.createList(new String[]{"ROLE_1", "ROLE_2"});
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
|
||||
Reference in New Issue
Block a user