From 1b1d1198368c66120b728f1d8b5643a673b75738 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Fri, 2 Apr 2004 12:20:41 +0000 Subject: [PATCH] Modifications consistent with changes to the objects being tested. --- .../jboss/JbossIntegrationFilterTests.java | 14 +++--- .../MockAccessDecisionManager.java | 11 ++--- .../org/acegisecurity/MockRunAsManager.java | 8 ++-- .../HttpRequestIntegrationFilterTests.java | 5 ++- .../runas/RunAsManagerImplTests.java | 11 ++++- .../AbstractAccessDecisionManagerTests.java | 44 ++++++++++++++++--- .../vote/AffirmativeBasedTests.java | 12 ++--- .../vote/ConsensusBasedTests.java | 14 +++--- .../acegisecurity/vote/DenyAgainVoter.java | 8 ++-- .../org/acegisecurity/vote/DenyVoter.java | 8 ++-- .../vote/UnanimousBasedTests.java | 12 ++--- 11 files changed, 98 insertions(+), 49 deletions(-) diff --git a/adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/JbossIntegrationFilterTests.java b/adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/JbossIntegrationFilterTests.java index 6411bd8fba..daa9509b04 100644 --- a/adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/JbossIntegrationFilterTests.java +++ b/adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/JbossIntegrationFilterTests.java @@ -19,7 +19,7 @@ import junit.framework.TestCase; import net.sf.acegisecurity.GrantedAuthority; import net.sf.acegisecurity.GrantedAuthorityImpl; -import net.sf.acegisecurity.adapters.MockHttpServletRequest; +import net.sf.acegisecurity.MockHttpServletRequest; import net.sf.acegisecurity.adapters.MockPrincipal; import net.sf.acegisecurity.adapters.PrincipalAcegiUserToken; @@ -69,7 +69,7 @@ public class JbossIntegrationFilterTests extends TestCase { makeIntoSubject(principal))); Object result = filter.extractFromContainer(new MockHttpServletRequest( - null)); + null, null)); if (!(result instanceof PrincipalAcegiUserToken)) { fail("Should have returned PrincipalAcegiUserToken"); @@ -83,28 +83,28 @@ public class JbossIntegrationFilterTests extends TestCase { JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext( "THIS_IS_NOT_A_SUBJECT")); assertEquals(null, - filter.extractFromContainer(new MockHttpServletRequest(null))); + filter.extractFromContainer(new MockHttpServletRequest(null, null))); } public void testReturnsNullIfInitialContextHasNullPrincipal() { JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext( makeIntoSubject(null))); assertEquals(null, - filter.extractFromContainer(new MockHttpServletRequest(null))); + filter.extractFromContainer(new MockHttpServletRequest(null, null))); } public void testReturnsNullIfInitialContextHasNullSubject() { JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext( null)); assertEquals(null, - filter.extractFromContainer(new MockHttpServletRequest(null))); + filter.extractFromContainer(new MockHttpServletRequest(null, null))); } public void testReturnsNullIfInitialContextIsNull() { JbossIntegrationFilter filter = new MockJbossIntegrationFilter(null); Object result = filter.extractFromContainer(new MockHttpServletRequest( - null)); + null, null)); assertEquals(null, filter.extractFromContainer(null)); } @@ -112,7 +112,7 @@ public class JbossIntegrationFilterTests extends TestCase { JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext( makeIntoSubject(new MockPrincipal()))); assertEquals(null, - filter.extractFromContainer(new MockHttpServletRequest(null))); + filter.extractFromContainer(new MockHttpServletRequest(null, null))); } public void testTestingObjectReturnsInitialContext() diff --git a/core/src/test/java/org/acegisecurity/MockAccessDecisionManager.java b/core/src/test/java/org/acegisecurity/MockAccessDecisionManager.java index 1e082dcd20..ec1ace30dc 100644 --- a/core/src/test/java/org/acegisecurity/MockAccessDecisionManager.java +++ b/core/src/test/java/org/acegisecurity/MockAccessDecisionManager.java @@ -15,8 +15,6 @@ package net.sf.acegisecurity; -import org.aopalliance.intercept.MethodInvocation; - import java.util.Iterator; @@ -30,9 +28,8 @@ import java.util.Iterator; public class MockAccessDecisionManager implements AccessDecisionManager { //~ Methods ================================================================ - public void decide(Authentication authentication, - MethodInvocation invocation, ConfigAttributeDefinition config) - throws AccessDeniedException { + public void decide(Authentication authentication, Object object, + ConfigAttributeDefinition config) throws AccessDeniedException { Iterator iter = config.getConfigAttributes(); while (iter.hasNext()) { @@ -59,4 +56,8 @@ public class MockAccessDecisionManager implements AccessDecisionManager { return false; } } + + public boolean supports(Class clazz) { + return true; + } } diff --git a/core/src/test/java/org/acegisecurity/MockRunAsManager.java b/core/src/test/java/org/acegisecurity/MockRunAsManager.java index 6c432e9f7e..43b9523e01 100644 --- a/core/src/test/java/org/acegisecurity/MockRunAsManager.java +++ b/core/src/test/java/org/acegisecurity/MockRunAsManager.java @@ -15,8 +15,6 @@ package net.sf.acegisecurity; -import org.aopalliance.intercept.MethodInvocation; - import java.util.Iterator; @@ -31,7 +29,7 @@ public class MockRunAsManager implements RunAsManager { //~ Methods ================================================================ public Authentication buildRunAs(Authentication authentication, - MethodInvocation invocation, ConfigAttributeDefinition config) { + Object object, ConfigAttributeDefinition config) { Iterator iter = config.getConfigAttributes(); while (iter.hasNext()) { @@ -55,4 +53,8 @@ public class MockRunAsManager implements RunAsManager { return false; } } + + public boolean supports(Class clazz) { + return true; + } } diff --git a/core/src/test/java/org/acegisecurity/adapters/HttpRequestIntegrationFilterTests.java b/core/src/test/java/org/acegisecurity/adapters/HttpRequestIntegrationFilterTests.java index 4a2abe5f64..9c522008b8 100644 --- a/core/src/test/java/org/acegisecurity/adapters/HttpRequestIntegrationFilterTests.java +++ b/core/src/test/java/org/acegisecurity/adapters/HttpRequestIntegrationFilterTests.java @@ -17,6 +17,7 @@ package net.sf.acegisecurity.adapters; import junit.framework.TestCase; +import net.sf.acegisecurity.*; import net.sf.acegisecurity.GrantedAuthority; import net.sf.acegisecurity.GrantedAuthorityImpl; @@ -54,7 +55,7 @@ public class HttpRequestIntegrationFilterTests extends TestCase { "someone", "password", new GrantedAuthority[] {new GrantedAuthorityImpl("SOME_ROLE")}); Object result = filter.extractFromContainer(new MockHttpServletRequest( - principal)); + principal, null)); if (!(result instanceof PrincipalAcegiUserToken)) { fail("Should have returned PrincipalAcegiUserToken"); @@ -72,6 +73,6 @@ public class HttpRequestIntegrationFilterTests extends TestCase { public void testHandlesIfThereIsNoPrincipal() { HttpRequestIntegrationFilter filter = new HttpRequestIntegrationFilter(); assertEquals(null, - filter.extractFromContainer(new MockHttpServletRequest(null))); + filter.extractFromContainer(new MockHttpServletRequest(null, null))); } } diff --git a/core/src/test/java/org/acegisecurity/runas/RunAsManagerImplTests.java b/core/src/test/java/org/acegisecurity/runas/RunAsManagerImplTests.java index d898cf52d8..4cfa3a3f20 100644 --- a/core/src/test/java/org/acegisecurity/runas/RunAsManagerImplTests.java +++ b/core/src/test/java/org/acegisecurity/runas/RunAsManagerImplTests.java @@ -53,6 +53,11 @@ public class RunAsManagerImplTests extends TestCase { junit.textui.TestRunner.run(RunAsManagerImplTests.class); } + public void testAlwaysSupportsClass() { + RunAsManagerImpl runAs = new RunAsManagerImpl(); + assertTrue(runAs.supports(String.class)); + } + public void testDoesNotReturnAdditionalAuthoritiesIfCalledWithoutARunAsSetting() throws Exception { ConfigAttributeDefinition def = new ConfigAttributeDefinition(); @@ -65,7 +70,8 @@ public class RunAsManagerImplTests extends TestCase { RunAsManagerImpl runAs = new RunAsManagerImpl(); runAs.setKey("my_password"); - Authentication resultingToken = runAs.buildRunAs(inputToken, null, def); + Authentication resultingToken = runAs.buildRunAs(inputToken, + new Object(), def); assertEquals(null, resultingToken); } @@ -81,7 +87,8 @@ public class RunAsManagerImplTests extends TestCase { RunAsManagerImpl runAs = new RunAsManagerImpl(); runAs.setKey("my_password"); - Authentication resultingToken = runAs.buildRunAs(inputToken, null, def); + Authentication resultingToken = runAs.buildRunAs(inputToken, + new Object(), def); if (!(resultingToken instanceof RunAsUserToken)) { fail("Should have returned a RunAsUserToken"); diff --git a/core/src/test/java/org/acegisecurity/vote/AbstractAccessDecisionManagerTests.java b/core/src/test/java/org/acegisecurity/vote/AbstractAccessDecisionManagerTests.java index fc5af7f8a0..b3c4851915 100644 --- a/core/src/test/java/org/acegisecurity/vote/AbstractAccessDecisionManagerTests.java +++ b/core/src/test/java/org/acegisecurity/vote/AbstractAccessDecisionManagerTests.java @@ -23,8 +23,6 @@ import net.sf.acegisecurity.ConfigAttribute; import net.sf.acegisecurity.ConfigAttributeDefinition; import net.sf.acegisecurity.SecurityConfig; -import org.aopalliance.intercept.MethodInvocation; - import java.util.List; import java.util.Vector; @@ -64,6 +62,17 @@ public class AbstractAccessDecisionManagerTests extends TestCase { assertTrue(mock.isAllowIfAllAbstainDecisions()); // changed } + public void testDelegatesSupportsClassRequests() throws Exception { + MockDecisionManagerImpl mock = new MockDecisionManagerImpl(); + List list = new Vector(); + list.add(new DenyVoter()); + list.add(new MockStringOnlyVoter()); + mock.setDecisionVoters(list); + + assertTrue(mock.supports(new String().getClass())); + assertTrue(!mock.supports(new Integer(7).getClass())); + } + public void testDelegatesSupportsRequests() throws Exception { MockDecisionManagerImpl mock = new MockDecisionManagerImpl(); List list = new Vector(); @@ -133,6 +142,11 @@ public class AbstractAccessDecisionManagerTests extends TestCase { } } + public void testRoleVoterAlwaysReturnsTrueToSupports() { + RoleVoter rv = new RoleVoter(); + assertTrue(rv.supports(String.class)); + } + public void testWillNotStartIfDecisionVotersNotSet() throws Exception { MockDecisionManagerImpl mock = new MockDecisionManagerImpl(); @@ -148,10 +162,30 @@ public class AbstractAccessDecisionManagerTests extends TestCase { //~ Inner Classes ========================================================== private class MockDecisionManagerImpl extends AbstractAccessDecisionManager { - public void decide(Authentication authentication, - MethodInvocation invocation, ConfigAttributeDefinition config) - throws AccessDeniedException { + public void decide(Authentication authentication, Object object, + ConfigAttributeDefinition config) throws AccessDeniedException { return; } } + + private class MockStringOnlyVoter implements AccessDecisionVoter { + public boolean supports(Class clazz) { + if (String.class.isAssignableFrom(clazz)) { + return true; + } else { + return false; + } + } + + public boolean supports(ConfigAttribute attribute) { + throw new UnsupportedOperationException( + "mock method not implemented"); + } + + public int vote(Authentication authentication, Object object, + ConfigAttributeDefinition config) { + throw new UnsupportedOperationException( + "mock method not implemented"); + } + } } diff --git a/core/src/test/java/org/acegisecurity/vote/AffirmativeBasedTests.java b/core/src/test/java/org/acegisecurity/vote/AffirmativeBasedTests.java index af07f04804..acda9633e2 100644 --- a/core/src/test/java/org/acegisecurity/vote/AffirmativeBasedTests.java +++ b/core/src/test/java/org/acegisecurity/vote/AffirmativeBasedTests.java @@ -64,7 +64,7 @@ public class AffirmativeBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("ROLE_1")); // grant config.addConfigAttribute(new SecurityConfig("DENY_FOR_SURE")); // deny - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } @@ -76,7 +76,7 @@ public class AffirmativeBasedTests extends TestCase { ConfigAttributeDefinition config = new ConfigAttributeDefinition(); config.addConfigAttribute(new SecurityConfig("ROLE_2")); // grant - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } @@ -89,7 +89,7 @@ public class AffirmativeBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("ROLE_WE_DO_NOT_HAVE")); // deny try { - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); fail("Should have thrown AccessDeniedException"); } catch (AccessDeniedException expected) { assertTrue(true); @@ -107,7 +107,7 @@ public class AffirmativeBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("IGNORED_BY_ALL")); // abstain try { - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); fail("Should have thrown AccessDeniedException"); } catch (AccessDeniedException expected) { assertTrue(true); @@ -124,7 +124,7 @@ public class AffirmativeBasedTests extends TestCase { ConfigAttributeDefinition config = new ConfigAttributeDefinition(); config.addConfigAttribute(new SecurityConfig("IGNORED_BY_ALL")); // abstain - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } @@ -137,7 +137,7 @@ public class AffirmativeBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("ROLE_1")); // grant config.addConfigAttribute(new SecurityConfig("ROLE_2")); // grant - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } diff --git a/core/src/test/java/org/acegisecurity/vote/ConsensusBasedTests.java b/core/src/test/java/org/acegisecurity/vote/ConsensusBasedTests.java index 4b84d7dedc..874fac9e42 100644 --- a/core/src/test/java/org/acegisecurity/vote/ConsensusBasedTests.java +++ b/core/src/test/java/org/acegisecurity/vote/ConsensusBasedTests.java @@ -67,7 +67,7 @@ public class ConsensusBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("DENY_FOR_SURE")); // deny try { - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); fail("Should have thrown AccessDeniedException"); } catch (AccessDeniedException expected) { assertTrue(true); @@ -85,7 +85,7 @@ public class ConsensusBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("ROLE_1")); // grant config.addConfigAttribute(new SecurityConfig("DENY_FOR_SURE")); // deny - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } @@ -97,7 +97,7 @@ public class ConsensusBasedTests extends TestCase { ConfigAttributeDefinition config = new ConfigAttributeDefinition(); config.addConfigAttribute(new SecurityConfig("ROLE_2")); // grant - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } @@ -110,7 +110,7 @@ public class ConsensusBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("ROLE_WE_DO_NOT_HAVE")); // deny try { - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); fail("Should have thrown AccessDeniedException"); } catch (AccessDeniedException expected) { assertTrue(true); @@ -128,7 +128,7 @@ public class ConsensusBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("IGNORED_BY_ALL")); // abstain try { - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); fail("Should have thrown AccessDeniedException"); } catch (AccessDeniedException expected) { assertTrue(true); @@ -145,7 +145,7 @@ public class ConsensusBasedTests extends TestCase { ConfigAttributeDefinition config = new ConfigAttributeDefinition(); config.addConfigAttribute(new SecurityConfig("IGNORED_BY_ALL")); // abstain - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } @@ -158,7 +158,7 @@ public class ConsensusBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("ROLE_1")); // grant config.addConfigAttribute(new SecurityConfig("ROLE_2")); // grant - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } diff --git a/core/src/test/java/org/acegisecurity/vote/DenyAgainVoter.java b/core/src/test/java/org/acegisecurity/vote/DenyAgainVoter.java index baedd11b01..8165d06627 100644 --- a/core/src/test/java/org/acegisecurity/vote/DenyAgainVoter.java +++ b/core/src/test/java/org/acegisecurity/vote/DenyAgainVoter.java @@ -19,8 +19,6 @@ import net.sf.acegisecurity.Authentication; import net.sf.acegisecurity.ConfigAttribute; import net.sf.acegisecurity.ConfigAttributeDefinition; -import org.aopalliance.intercept.MethodInvocation; - import java.util.Iterator; @@ -50,7 +48,11 @@ public class DenyAgainVoter implements AccessDecisionVoter { } } - public int vote(Authentication authentication, MethodInvocation invocation, + public boolean supports(Class clazz) { + return true; + } + + public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) { Iterator iter = config.getConfigAttributes(); diff --git a/core/src/test/java/org/acegisecurity/vote/DenyVoter.java b/core/src/test/java/org/acegisecurity/vote/DenyVoter.java index bc79d41d92..0165dedfc4 100644 --- a/core/src/test/java/org/acegisecurity/vote/DenyVoter.java +++ b/core/src/test/java/org/acegisecurity/vote/DenyVoter.java @@ -19,8 +19,6 @@ import net.sf.acegisecurity.Authentication; import net.sf.acegisecurity.ConfigAttribute; import net.sf.acegisecurity.ConfigAttributeDefinition; -import org.aopalliance.intercept.MethodInvocation; - import java.util.Iterator; @@ -50,7 +48,11 @@ public class DenyVoter implements AccessDecisionVoter { } } - public int vote(Authentication authentication, MethodInvocation invocation, + public boolean supports(Class clazz) { + return true; + } + + public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) { Iterator iter = config.getConfigAttributes(); diff --git a/core/src/test/java/org/acegisecurity/vote/UnanimousBasedTests.java b/core/src/test/java/org/acegisecurity/vote/UnanimousBasedTests.java index 7320989fb0..9d57a758f0 100644 --- a/core/src/test/java/org/acegisecurity/vote/UnanimousBasedTests.java +++ b/core/src/test/java/org/acegisecurity/vote/UnanimousBasedTests.java @@ -65,7 +65,7 @@ public class UnanimousBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("DENY_FOR_SURE")); // deny try { - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); fail("Should have thrown AccessDeniedException"); } catch (AccessDeniedException expected) { assertTrue(true); @@ -80,7 +80,7 @@ public class UnanimousBasedTests extends TestCase { ConfigAttributeDefinition config = new ConfigAttributeDefinition(); config.addConfigAttribute(new SecurityConfig("ROLE_2")); // grant - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } @@ -93,7 +93,7 @@ public class UnanimousBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("ROLE_WE_DO_NOT_HAVE")); // deny try { - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); fail("Should have thrown AccessDeniedException"); } catch (AccessDeniedException expected) { assertTrue(true); @@ -111,7 +111,7 @@ public class UnanimousBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("IGNORED_BY_ALL")); // abstain try { - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); fail("Should have thrown AccessDeniedException"); } catch (AccessDeniedException expected) { assertTrue(true); @@ -128,7 +128,7 @@ public class UnanimousBasedTests extends TestCase { ConfigAttributeDefinition config = new ConfigAttributeDefinition(); config.addConfigAttribute(new SecurityConfig("IGNORED_BY_ALL")); // abstain - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); } @@ -141,7 +141,7 @@ public class UnanimousBasedTests extends TestCase { config.addConfigAttribute(new SecurityConfig("ROLE_1")); // grant config.addConfigAttribute(new SecurityConfig("ROLE_2")); // grant - mgr.decide(auth, null, config); + mgr.decide(auth, new Object(), config); assertTrue(true); }