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 @@ - - - - - - - - - - - my_run_as_password - - - - - - - - - - - - - - - - - - - - - - - - false - - - - - - - - - - - - - - - - - false - - - - - - - - - - - - - - - - securityInterceptor - - - - - - - testService - - - - - - diff --git a/core/src/test/java/org/acegisecurity/context/Account.java b/core/src/test/java/org/acegisecurity/context/Account.java deleted file mode 100644 index 740add1c83..0000000000 --- a/core/src/test/java/org/acegisecurity/context/Account.java +++ /dev/null @@ -1,65 +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.context; - -/** - * Models a bank account. - */ -public class Account { - //~ Instance fields ======================================================== - - private Integer id; - private String owningUserName; - private float balance; - - //~ Constructors =========================================================== - - public Account(Integer id, String owningUserName) { - this.id = id; - this.owningUserName = owningUserName; - } - - public Account(int id, String owningUserName) { - this.id = new Integer(id); - this.owningUserName = owningUserName; - } - - private Account() { - super(); - } - - //~ Methods ================================================================ - - public float getBalance() { - return this.balance; - } - - public Integer getId() { - return this.id; - } - - public String getOwningUserName() { - return this.owningUserName; - } - - public void deposit(float amount) { - this.balance = this.balance + amount; - } - - public void withdraw(float amount) { - this.balance = this.balance - amount; - } -} diff --git a/core/src/test/java/org/acegisecurity/context/BankManager.java b/core/src/test/java/org/acegisecurity/context/BankManager.java deleted file mode 100644 index 0ce1b19d12..0000000000 --- a/core/src/test/java/org/acegisecurity/context/BankManager.java +++ /dev/null @@ -1,44 +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.context; - -/** - * Simple business object of an in-memory banking system. - * - *

- * We'll spare you from InsufficientFundsExceptions etc. After - * all, this is intended to test security features rather than OO design! - *

- * - * @author Ben Alex - * @version $Id$ - */ -public interface BankManager { - //~ Methods ================================================================ - - public float getBalance(Integer accountNumber); - - public float getBankFundsUnderControl(); - - public void deleteAccount(Integer accountNumber); - - public Account loadAccount(Integer accountNumber); - - public void saveAccount(Account account); - - public void transferFunds(Integer fromAccountNumber, - Integer toAccountNumber, float amount); -} diff --git a/core/src/test/java/org/acegisecurity/context/BankManagerImpl.java b/core/src/test/java/org/acegisecurity/context/BankManagerImpl.java deleted file mode 100644 index f12e55aaeb..0000000000 --- a/core/src/test/java/org/acegisecurity/context/BankManagerImpl.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.context; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - - -/** - * Implementation of {@link BankManager}. - * - * @author Ben Alex - * @version $Id$ - */ -public class BankManagerImpl implements BankManager { - //~ Instance fields ======================================================== - - private Map accounts = new HashMap(); - - //~ Methods ================================================================ - - public float getBalance(Integer accountNumber) { - Account account = this.loadAccount(accountNumber); - - return account.getBalance(); - } - - public float getBankFundsUnderControl() { - float total = 0; - Iterator iter = this.accounts.keySet().iterator(); - - while (iter.hasNext()) { - Integer account = (Integer) iter.next(); - total = total + this.getBalance(account); - } - - return total; - } - - public void deleteAccount(Integer accountNumber) { - this.accounts.remove(accountNumber); - } - - public Account loadAccount(Integer accountNumber) { - return (Account) accounts.get(accountNumber); - } - - public void saveAccount(Account account) { - this.accounts.put(account.getId(), account); - } - - public void transferFunds(Integer fromAccountNumber, - Integer toAccountNumber, float amount) { - Account from = this.loadAccount(fromAccountNumber); - Account to = this.loadAccount(toAccountNumber); - from.withdraw(amount); - to.deposit(amount); - this.saveAccount(from); - this.saveAccount(to); - } -} diff --git a/core/src/test/java/org/acegisecurity/context/ContextTests.java b/core/src/test/java/org/acegisecurity/context/ContextTests.java deleted file mode 100644 index db570205e2..0000000000 --- a/core/src/test/java/org/acegisecurity/context/ContextTests.java +++ /dev/null @@ -1,128 +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.context; - -import junit.framework.TestCase; - -import net.sf.acegisecurity.providers.TestingAuthenticationToken; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - - -/** - * Tests context objects. - * - * @author Ben Alex - * @version $Id$ - */ -public class ContextTests extends TestCase { - //~ Instance fields ======================================================== - - private ClassPathXmlApplicationContext ctx; - - //~ Constructors =========================================================== - - public ContextTests() { - super(); - } - - public ContextTests(String arg0) { - super(arg0); - } - - //~ Methods ================================================================ - - public final void setUp() throws Exception { - super.setUp(); - ctx = new ClassPathXmlApplicationContext( - "/net/sf/acegisecurity/context/applicationContext.xml"); - } - - public static void main(String[] args) { - junit.textui.TestRunner.run(ContextTests.class); - } - - public void testContextInterceptorDetectsEmptyContexts() - throws Exception { - Account ben = new Account(1, "ben"); - BankManager bank = (BankManager) ctx.getBean("bankManager"); - - try { - bank.saveAccount(ben); - fail("Should have thrown ContextHolderEmptyException"); - } catch (ContextHolderEmptyException expected) { - assertTrue(true); - } - - Context context = new ContextImpl(); - ContextHolder.setContext(context); - - Account marissa = new Account(2, "marissa"); - bank.saveAccount(marissa); - - ContextHolder.setContext(null); - } - - public void testContextInterceptorProcessesValidations() - throws Exception { - ExoticContext context = new ExoticContext(); - ContextHolder.setContext(context); - - Account ben = new Account(1, "ben"); - BankManager bank = (BankManager) ctx.getBean("bankManager"); - - try { - bank.saveAccount(ben); - fail( - "Should have thrown ContextInvalidException (magic number is incorrect)"); - } catch (ContextInvalidException expected) { - assertTrue(true); - } - - context.setMagicNumber(7); - ContextHolder.setContext(context); - - Account marissa = new Account(2, "marissa"); - bank.saveAccount(marissa); - - ContextHolder.setContext(null); - } - - public void testContextInterceptorValidatesASecureContext() - throws Exception { - SecureContext context = new SecureContextImpl(); - ContextHolder.setContext((Context) context); - - Account ben = new Account(1, "ben"); - BankManager bank = (BankManager) ctx.getBean("bankManager"); - - try { - bank.saveAccount(ben); - fail( - "Should have thrown ContextInvalidException (no authentication object)"); - } catch (ContextInvalidException expected) { - assertTrue(true); - } - - context.setAuthentication(new TestingAuthenticationToken("a", "b", null)); - ContextHolder.setContext((Context) context); - - Account marissa = new Account(2, "marissa"); - bank.saveAccount(marissa); - - ContextHolder.setContext(null); - } -} diff --git a/core/src/test/java/org/acegisecurity/context/ExoticContext.java b/core/src/test/java/org/acegisecurity/context/ExoticContext.java deleted file mode 100644 index 56e7a2a050..0000000000 --- a/core/src/test/java/org/acegisecurity/context/ExoticContext.java +++ /dev/null @@ -1,49 +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.context; - -/** - * Exotic implementation of a {@link Context}. - * - *

- * Requires the context to be set with a magicNumber of 7. Tests - * validation in the unit tests. - *

- * - * @author Ben Alex - * @version $Id$ - */ -public class ExoticContext implements Context { - //~ Instance fields ======================================================== - - private int magicNumber; - - //~ Methods ================================================================ - - public void setMagicNumber(int magicNumber) { - this.magicNumber = magicNumber; - } - - public int getMagicNumber() { - return magicNumber; - } - - public void validate() throws ContextInvalidException { - if (magicNumber != 7) { - throw new ContextInvalidException("Magic number is not 7"); - } - } -} diff --git a/core/src/test/java/org/acegisecurity/context/applicationContext.xml b/core/src/test/java/org/acegisecurity/context/applicationContext.xml deleted file mode 100644 index c36c11e3f9..0000000000 --- a/core/src/test/java/org/acegisecurity/context/applicationContext.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - net.sf.acegisecurity.context.BankManager - - - contextInterceptor - bankManagerTarget - - - - - diff --git a/core/src/test/java/org/acegisecurity/providers/dao/memory/applicationContext.xml b/core/src/test/java/org/acegisecurity/providers/dao/memory/applicationContext.xml deleted file mode 100644 index 78230a5149..0000000000 --- a/core/src/test/java/org/acegisecurity/providers/dao/memory/applicationContext.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - my_run_as_password - - - - - - - - - - marissa=koala,ROLE_TELLER,ROLE_SUPERVISOR - dianne=emu,disabled,ROLE_TELLER - scott=wombat,ACCOUNT_45 - peter=opal,ACCOUNT_77 - someone=password - someoneelse= - - - - - - - - false - true - - - - - my_run_as_password - - - - - - - - - - - - - - - - - - - - - - - - false - - - - - - - - - - - - - - - - - - net.sf.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR - net.sf.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER - net.sf.acegisecurity.context.BankManager.loadAccount=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER - net.sf.acegisecurity.context.BankManager.saveAccount=ROLE_TELLER,ROLE_SUPERVISOR - net.sf.acegisecurity.context.BankManager.transferFunds=ROLE_SUPERVISOR - - - - - - - - - - - net.sf.acegisecurity.context.BankManager - - - bankManagerSecurity - bankManagerTarget - - - - - diff --git a/core/src/test/java/org/acegisecurity/runas/BankManagerPublicFacade.java b/core/src/test/java/org/acegisecurity/runas/BankManagerPublicFacade.java deleted file mode 100644 index fe55e7a1ae..0000000000 --- a/core/src/test/java/org/acegisecurity/runas/BankManagerPublicFacade.java +++ /dev/null @@ -1,83 +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 net.sf.acegisecurity.context.Account; -import net.sf.acegisecurity.context.BankManager; - -import org.springframework.beans.factory.InitializingBean; - - -/** - * Acts as the "public facade" to a 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 @@ - - - - - - - - - - - my_run_as_password - - - - - - - - - - marissa=koala,ROLE_TELLER,ROLE_SUPERVISOR - dianne=emu,disabled,ROLE_TELLER - scott=wombat,ACCOUNT_45 - peter=opal,ACCOUNT_77 - someone=password - someoneelse= - - - - - - - - false - true - - - - - my_run_as_password - - - - - - - - - - - - - - - - - - - - - - - false - - - - - - - - - - - - - - - - - - net.sf.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR,RUN_AS_SERVER - net.sf.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER - net.sf.acegisecurity.context.BankManager.loadAccount=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER - net.sf.acegisecurity.context.BankManager.saveAccount=ROLE_TELLER,ROLE_SUPERVISOR - net.sf.acegisecurity.context.BankManager.transferFunds=ROLE_SUPERVISOR,RUN_AS_SERVER - - - - - - - - - - - - net.sf.acegisecurity.context.BankManager.delete*=ROLE_RUN_AS_SERVER - net.sf.acegisecurity.context.BankManager.getBalance=ROLE_RUN_AS_SERVER - net.sf.acegisecurity.context.BankManager.loadAccount=ROLE_RUN_AS_SERVER - net.sf.acegisecurity.context.BankManager.saveAccount=ROLE_RUN_AS_SERVER - net.sf.acegisecurity.context.BankManager.transferFunds=ROLE_RUN_AS_SERVER - - - - - - - - net.sf.acegisecurity.context.BankManager - - - publicBankManagerSecurity - publicBankManagerTarget - - - - - - - - - - net.sf.acegisecurity.context.BankManager - - - backendBankManagerSecurity - backendBankManagerTarget - - - - - - -