diff --git a/core/src/test/java/org/acegisecurity/attribute/AttributesTests.java b/core/src/test/java/org/acegisecurity/attribute/AttributesTests.java
deleted file mode 100644
index 4e46cfc469..0000000000
--- a/core/src/test/java/org/acegisecurity/attribute/AttributesTests.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/* Copyright 2004 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 net.sf.acegisecurity.attribute;
-
-import junit.framework.TestCase;
-
-import net.sf.acegisecurity.Authentication;
-import net.sf.acegisecurity.ConfigAttribute;
-import net.sf.acegisecurity.ConfigAttributeDefinition;
-import net.sf.acegisecurity.GrantedAuthority;
-import net.sf.acegisecurity.GrantedAuthorityImpl;
-import net.sf.acegisecurity.MethodDefinitionAttributes;
-import net.sf.acegisecurity.SecurityConfig;
-import net.sf.acegisecurity.context.ContextHolder;
-import net.sf.acegisecurity.context.SecureContextImpl;
-import net.sf.acegisecurity.providers.TestingAuthenticationToken;
-
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-import java.lang.reflect.Method;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author CameronBraid
- */
-public class AttributesTests extends TestCase {
- //~ Instance fields ========================================================
-
- ClassPathXmlApplicationContext applicationContext;
-
- //~ Constructors ===========================================================
-
- /**
- *
- */
- public AttributesTests(String a) {
- super(a);
- }
-
- //~ Methods ================================================================
-
- public void testAttributesForImpl() throws Exception {
- ConfigAttributeDefinition def = getConfigAttributeDefinition(TestServiceImpl.class);
- Set set = toSet(def);
- assertTrue(set.contains(new SecurityConfig("ROLE_INTERFACE")));
- assertTrue(set.contains(new SecurityConfig("ROLE_INTERFACE_METHOD")));
-
- assertTrue(set.contains(new SecurityConfig("ROLE_CLASS")));
- assertTrue(set.contains(new SecurityConfig("ROLE_CLASS_METHOD")));
- }
-
- public void testAttributesForInterface() throws Exception {
- ConfigAttributeDefinition def = getConfigAttributeDefinition(TestService.class);
- Set set = toSet(def);
- System.out.println(set.toString());
- assertTrue(set.contains(new SecurityConfig("ROLE_INTERFACE")));
- assertTrue(set.contains(new SecurityConfig("ROLE_INTERFACE_METHOD")));
- }
-
- public void testInterceptionWithMockAttributesAndSecureContext()
- throws Exception {
- applicationContext = new ClassPathXmlApplicationContext(
- "/net/sf/acegisecurity/attribute/applicationContext.xml");
-
- TestService service = (TestService) applicationContext.getBean(
- "testService");
-
- SecureContextImpl context = new SecureContextImpl();
- ContextHolder.setContext(context);
-
- Authentication auth;
-
- auth = new TestingAuthenticationToken("test", "test",
- new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_CLASS"), new GrantedAuthorityImpl(
- "ROLE_INTERFACE"), new GrantedAuthorityImpl(
- "ROLE_CLASS_METHOD"), new GrantedAuthorityImpl(
- "ROLE_INTERFACE_METHOD")});
-
- context.setAuthentication(auth);
- service.myMethod();
-
- auth = new TestingAuthenticationToken("test", "test",
- new GrantedAuthority[] {});
- context.setAuthentication(auth);
-
- try {
- service.myMethod();
- fail(
- "security interceptor should have detected insufficient permissions");
- } catch (Exception e) {}
-
- applicationContext.close();
- ContextHolder.setContext(null);
- }
-
- private ConfigAttributeDefinition getConfigAttributeDefinition(Class clazz)
- throws Exception {
- final Method method = clazz.getMethod("myMethod", null);
- MethodDefinitionAttributes source = new MethodDefinitionAttributes();
- source.setAttributes(new TestAttributes());
-
- ConfigAttributeDefinition config = source.getAttributes(new MockMethodInvocation() {
- public Method getMethod() {
- return method;
- }
- });
-
- return config;
- }
-
- /**
- * convert a ConfigAttributeDefinition into a set of
- * ConfigAttribute
(s)
- *
- * @param def DOCUMENT ME!
- *
- * @return
- */
- private Set toSet(ConfigAttributeDefinition def) {
- Set set = new HashSet();
- Iterator i = def.getConfigAttributes();
-
- while (i.hasNext()) {
- ConfigAttribute a = (ConfigAttribute) i.next();
- set.add(a);
- }
-
- return set;
- }
-}
diff --git a/core/src/test/java/org/acegisecurity/attribute/MockAttributes.java b/core/src/test/java/org/acegisecurity/attribute/MockAttributes.java
deleted file mode 100644
index 133db50f2e..0000000000
--- a/core/src/test/java/org/acegisecurity/attribute/MockAttributes.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright 2004 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 net.sf.acegisecurity.attribute;
-
-import org.springframework.metadata.Attributes;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import java.util.Collection;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author CameronBraid
- */
-public class MockAttributes implements Attributes {
- //~ Methods ================================================================
-
- /* (non-Javadoc)
- * @see org.springframework.metadata.Attributes#getAttributes(java.lang.Class, java.lang.Class)
- */
- public Collection getAttributes(Class arg0, Class arg1) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.springframework.metadata.Attributes#getAttributes(java.lang.Class)
- */
- public Collection getAttributes(Class arg0) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Field, java.lang.Class)
- */
- public Collection getAttributes(Field arg0, Class arg1) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Field)
- */
- public Collection getAttributes(Field arg0) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Method, java.lang.Class)
- */
- public Collection getAttributes(Method arg0, Class arg1) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Method)
- */
- public Collection getAttributes(Method arg0) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-}
diff --git a/core/src/test/java/org/acegisecurity/attribute/MockMethodInvocation.java b/core/src/test/java/org/acegisecurity/attribute/MockMethodInvocation.java
deleted file mode 100644
index 55a2c53cf5..0000000000
--- a/core/src/test/java/org/acegisecurity/attribute/MockMethodInvocation.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Copyright 2004 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 net.sf.acegisecurity.attribute;
-
-import org.aopalliance.intercept.Invocation;
-import org.aopalliance.intercept.MethodInvocation;
-
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Method;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author CameronBraid
- */
-public class MockMethodInvocation implements MethodInvocation {
- //~ Methods ================================================================
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Invocation#setArgument(int, java.lang.Object)
- */
- public void setArgument(int arg0, Object arg1) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Invocation#getArgument(int)
- */
- public Object getArgument(int arg0) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Invocation#getArgumentCount()
- */
- public int getArgumentCount() {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Invocation#getArguments()
- */
- public Object[] getArguments() {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Invocation#getAttachment(java.lang.String)
- */
- public Object getAttachment(String arg0) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.MethodInvocation#getMethod()
- */
- public Method getMethod() {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Joinpoint#getStaticPart()
- */
- public AccessibleObject getStaticPart() {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Joinpoint#getThis()
- */
- public Object getThis() {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Invocation#addAttachment(java.lang.String, java.lang.Object)
- */
- public Object addAttachment(String arg0, Object arg1) {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Invocation#cloneInstance()
- */
- public Invocation cloneInstance() {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.Joinpoint#proceed()
- */
- public Object proceed() throws Throwable {
- throw new UnsupportedOperationException("mock method not implemented");
- }
-}
diff --git a/core/src/test/java/org/acegisecurity/attribute/TestAttributes.java b/core/src/test/java/org/acegisecurity/attribute/TestAttributes.java
deleted file mode 100644
index a668e58dd0..0000000000
--- a/core/src/test/java/org/acegisecurity/attribute/TestAttributes.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Copyright 2004 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 net.sf.acegisecurity.attribute;
-
-import net.sf.acegisecurity.SecurityConfig;
-
-import java.lang.reflect.Method;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author CameronBraid
- */
-public class TestAttributes extends MockAttributes {
- //~ Instance fields ========================================================
-
- List classAttributes = Arrays.asList(new SecurityConfig[] {new SecurityConfig(
- "ROLE_CLASS")});
- List classMethodAttributes = Arrays.asList(new SecurityConfig[] {new SecurityConfig(
- "ROLE_CLASS_METHOD")});
- List intrefaceAttributes = Arrays.asList(new SecurityConfig[] {new SecurityConfig(
- "ROLE_INTERFACE")});
- List intrefaceMethodAttributes = Arrays.asList(new SecurityConfig[] {new SecurityConfig(
- "ROLE_INTERFACE_METHOD")});
-
- //~ Methods ================================================================
-
- public Collection getAttributes(Class clazz) {
- // interface
- if (clazz.equals(TestServiceImpl.class)) {
- return classAttributes;
- }
-
- // class
- if (clazz.equals(TestService.class)) {
- return intrefaceAttributes;
- }
-
- return null;
- }
-
- public Collection getAttributes(Method method) {
- // interface
- if (method.getDeclaringClass().equals(TestService.class)) {
- return intrefaceMethodAttributes;
- }
-
- // class
- if (method.getDeclaringClass().equals(TestServiceImpl.class)) {
- return classMethodAttributes;
- }
-
- return null;
- }
-}
diff --git a/core/src/test/java/org/acegisecurity/attribute/TestService.java b/core/src/test/java/org/acegisecurity/attribute/TestService.java
deleted file mode 100644
index ef858c1fea..0000000000
--- a/core/src/test/java/org/acegisecurity/attribute/TestService.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright 2004 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 net.sf.acegisecurity.attribute;
-
-/**
- * DOCUMENT ME!
- *
- * @author CameronBraid
- */
-public interface TestService {
- //~ Methods ================================================================
-
- public abstract void myMethod();
-}
diff --git a/core/src/test/java/org/acegisecurity/attribute/TestServiceImpl.java b/core/src/test/java/org/acegisecurity/attribute/TestServiceImpl.java
deleted file mode 100644
index 7ba5424038..0000000000
--- a/core/src/test/java/org/acegisecurity/attribute/TestServiceImpl.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright 2004 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 net.sf.acegisecurity.attribute;
-
-/**
- * DOCUMENT ME!
- *
- * @author CameronBraid
- */
-public class TestServiceImpl implements TestService {
- //~ Methods ================================================================
-
- public void myMethod() {}
-}
diff --git a/core/src/test/java/org/acegisecurity/attribute/applicationContext.xml b/core/src/test/java/org/acegisecurity/attribute/applicationContext.xml
deleted file mode 100644
index 74abff07f5..0000000000
--- a/core/src/test/java/org/acegisecurity/attribute/applicationContext.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-
-
-
-
-
-
-
-
-
- * We'll spare you from InsufficientFundsExceptions
etc. After
- * all, this is intended to test security features rather than OO design!
- *
- * Requires the context to be set with a magicNumber
of 7. Tests
- * validation in the unit tests.
- *
BankManager
.
- *
- * - * The security configuration of this, the public facade, specifies authorities - * that should be held by the end user. The security configuration of the - * "backend", which is not accessible to the general public, specifies certain - * authorities that are granted by the RunAsManagerImpl. - *
- * - * @author Ben Alex - * @version $Id$ - */ -public class BankManagerPublicFacade implements BankManager, InitializingBean { - //~ Instance fields ======================================================== - - private BankManager backend; - - //~ Methods ================================================================ - - public void setBackend(BankManager backend) { - this.backend = backend; - } - - public BankManager getBackend() { - return backend; - } - - public float getBalance(Integer accountNumber) { - return backend.getBalance(accountNumber); - } - - public float getBankFundsUnderControl() { - return backend.getBankFundsUnderControl(); - } - - public void afterPropertiesSet() throws Exception { - if (backend == null) { - throw new IllegalArgumentException( - "A backend BankManager implementation is required"); - } - } - - public void deleteAccount(Integer accountNumber) { - backend.deleteAccount(accountNumber); - } - - public Account loadAccount(Integer accountNumber) { - return backend.loadAccount(accountNumber); - } - - public void saveAccount(Account account) { - backend.saveAccount(account); - } - - public void transferFunds(Integer fromAccountNumber, - Integer toAccountNumber, float amount) { - backend.transferFunds(fromAccountNumber, toAccountNumber, amount); - } -} diff --git a/core/src/test/java/org/acegisecurity/runas/RunAsTests.java b/core/src/test/java/org/acegisecurity/runas/RunAsTests.java deleted file mode 100644 index 1dae6d76bc..0000000000 --- a/core/src/test/java/org/acegisecurity/runas/RunAsTests.java +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright 2004 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 net.sf.acegisecurity.runas; - -import junit.framework.TestCase; - -import net.sf.acegisecurity.AccessDeniedException; -import net.sf.acegisecurity.context.Account; -import net.sf.acegisecurity.context.BankManager; -import net.sf.acegisecurity.context.Context; -import net.sf.acegisecurity.context.ContextHolder; -import net.sf.acegisecurity.context.SecureContext; -import net.sf.acegisecurity.context.SecureContextImpl; -import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - - -/** - * Tests {@link RunAsManagerImpl}. - * - * @author Ben Alex - * @version $Id$ - */ -public class RunAsTests extends TestCase { - //~ Instance fields ======================================================== - - private ClassPathXmlApplicationContext ctx; - - //~ Constructors =========================================================== - - public RunAsTests() { - super(); - } - - public RunAsTests(String arg0) { - super(arg0); - } - - //~ Methods ================================================================ - - public final void setUp() throws Exception { - super.setUp(); - ctx = new ClassPathXmlApplicationContext( - "/net/sf/acegisecurity/runas/applicationContext.xml"); - } - - public static void main(String[] args) { - junit.textui.TestRunner.run(RunAsTests.class); - } - - public void testRunAs() throws Exception { - Account account = new Account(45, "someone"); - BankManager bank = (BankManager) ctx.getBean("bankManager"); - - // Try as a user without access to the account - UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("peter", - "opal"); - SecureContext secureContext = new SecureContextImpl(); - secureContext.setAuthentication(token); - ContextHolder.setContext((Context) secureContext); - - try { - // NB: account number 45 != granted authority for account 77 - bank.loadAccount(account.getId()); - fail("Should have thrown an AccessDeniedException"); - } catch (AccessDeniedException expected) { - assertTrue(true); - } - - // Now try as user with access to account number 45 - // Proves ROLE_RUN_AS_SERVER is being allocated - token = new UsernamePasswordAuthenticationToken("scott", "wombat"); - secureContext.setAuthentication(token); - ContextHolder.setContext((Context) secureContext); - bank.loadAccount(account.getId()); - assertTrue(true); - - // Now try as user with ROLE_SUPERVISOR access to the account - // Proves ROLE_RUN_AS_SERVER is being allocated - token = new UsernamePasswordAuthenticationToken("marissa", "koala"); - secureContext.setAuthentication(token); - ContextHolder.setContext((Context) secureContext); - bank.loadAccount(account.getId()); - assertTrue(true); - - // Now try to call a method that ROLE_RUN_AS_BACKEND not granted for - token = new UsernamePasswordAuthenticationToken("marissa", "koala"); - secureContext.setAuthentication(token); - ContextHolder.setContext((Context) secureContext); - - try { - bank.saveAccount(account); - fail("Should have thrown AccessDeniedException"); - } catch (AccessDeniedException expected) { - assertTrue(true); - } - - ContextHolder.setContext(null); - } -} diff --git a/core/src/test/java/org/acegisecurity/runas/applicationContext.xml b/core/src/test/java/org/acegisecurity/runas/applicationContext.xml deleted file mode 100644 index eefbb9e47a..0000000000 --- a/core/src/test/java/org/acegisecurity/runas/applicationContext.xml +++ /dev/null @@ -1,138 +0,0 @@ - - - - -