Modifications consistent with changes to the objects being tested.
This commit is contained in:
parent
a278db8df9
commit
1b1d119836
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue