diff --git a/samples/attributes/.cvsignore b/samples/attributes/.cvsignore deleted file mode 100644 index 7b85662386..0000000000 --- a/samples/attributes/.cvsignore +++ /dev/null @@ -1,4 +0,0 @@ -classes -generated -reports -target diff --git a/samples/attributes/pom.xml b/samples/attributes/pom.xml deleted file mode 100644 index cdd40b9176..0000000000 --- a/samples/attributes/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - 4.0.0 - - org.springframework.security - spring-security-samples - 2.0-SNAPSHOT - - spring-security-sample-attributes - Spring Security - Attributes sample - - - xdoclet - xjavadoc - 1.0.2 - - - commons-collections - commons-collections - 3.1 - - - commons-attributes - commons-attributes-compiler - 2.1 - - - commons-attributes - commons-attributes-api - 2.1 - - - commons-attributes - commons-attributes-plugin - 2.1 - plugin - - - - diff --git a/samples/attributes/src/main/java/sample/attributes/BankService.java b/samples/attributes/src/main/java/sample/attributes/BankService.java deleted file mode 100644 index da05d364d9..0000000000 --- a/samples/attributes/src/main/java/sample/attributes/BankService.java +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.attributes; - -/** - * DOCUMENT ME! - * - * @author Cameron Braid - * @author Ben Alex - * @version $Id$ - * - */ -public interface BankService { - //~ Methods ======================================================================================================== - - /** - * The SecurityConfig below will be merged with the interface-level SecurityConfig above by Commons Attributes. - * ie: this is equivalent to defining BankService=ROLE_TELLER,ROLE_PERMISSION_BALANACE in the bean context. - * - * @return DOCUMENT ME! - * - * @@net.sf.acegisecurity.SecurityConfig("ROLE_PERMISSION_BALANCE") - */ - float balance(String accountNumber); - - /** - * The SecurityConfig below will be merged with the interface-level SecurityConfig above by Commons Attributes. - * ie: this is equivalent to defining BankService=ROLE_TELLER,ROLE_PERMISSION_LIST in the bean context. - * - * @return DOCUMENT ME! - * - * @@net.sf.acegisecurity.SecurityConfig("ROLE_PERMISSION_LIST") - */ - String[] listAccounts(); -} diff --git a/samples/attributes/src/main/java/sample/attributes/BankServiceImpl.java b/samples/attributes/src/main/java/sample/attributes/BankServiceImpl.java deleted file mode 100644 index b16d4e0b70..0000000000 --- a/samples/attributes/src/main/java/sample/attributes/BankServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.attributes; - -/** - * DOCUMENT ME! - * - * @author Cameron Braid - * @author Ben Alex - * @version $Id$ - */ -public class BankServiceImpl implements BankService { - //~ Methods ======================================================================================================== - - public float balance(String accountNumber) { - return 42000000; - } - - public String[] listAccounts() { - return new String[] {"1", "2", "3"}; - } -} diff --git a/samples/attributes/src/main/java/sample/attributes/Main.java b/samples/attributes/src/main/java/sample/attributes/Main.java deleted file mode 100644 index 3f4098f0ec..0000000000 --- a/samples/attributes/src/main/java/sample/attributes/Main.java +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.attributes; - -import org.acegisecurity.AccessDeniedException; -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.GrantedAuthorityImpl; - -import org.acegisecurity.context.SecurityContextHolder; -import org.acegisecurity.context.SecurityContextImpl; - -import org.acegisecurity.providers.TestingAuthenticationToken; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - - -/** - * DOCUMENT ME! - * - * @author Cameron Braid - * @author Ben Alex - * @version $Id$ - */ -public class Main { - //~ Methods ======================================================================================================== - - /** - * This can be done in a web app by using a filter or SpringMvcIntegrationInterceptor. - */ - private static void createSecureContext() { - TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test", - new GrantedAuthority[] { - new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl("ROLE_PERMISSION_LIST") - }); - - SecurityContextHolder.getContext().setAuthentication(auth); - } - - private static void destroySecureContext() { - SecurityContextHolder.setContext(new SecurityContextImpl()); - } - - public static void main(String[] args) throws Exception { - createSecureContext(); - - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); - BankService service = (BankService) context.getBean("bankService"); - - // will succeed - service.listAccounts(); - - // will fail - try { - System.out.println( - "We expect an AccessDeniedException now, as we do not hold the ROLE_PERMISSION_BALANCE granted authority, and we're using a unanimous access decision manager... "); - service.balance("1"); - } catch (AccessDeniedException e) { - e.printStackTrace(); - } - - destroySecureContext(); - } -} diff --git a/samples/attributes/src/main/resources/applicationContext.xml b/samples/attributes/src/main/resources/applicationContext.xml deleted file mode 100644 index 864185deb1..0000000000 --- a/samples/attributes/src/main/resources/applicationContext.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - my_run_as_password - - - - - - - - - - - - - - - - - - - - - - - - false - - - - - - - - - - - - - - - - - false - - - - - - - - - - - - - - - - - diff --git a/samples/attributes/src/test/java/sample/attributes/BankTests.java b/samples/attributes/src/test/java/sample/attributes/BankTests.java deleted file mode 100644 index 4449d30936..0000000000 --- a/samples/attributes/src/test/java/sample/attributes/BankTests.java +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.attributes; - -import junit.framework.TestCase; - -import org.acegisecurity.AccessDeniedException; -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.GrantedAuthorityImpl; - -import org.acegisecurity.context.SecurityContextHolder; -import org.acegisecurity.context.SecurityContextImpl; - -import org.acegisecurity.providers.TestingAuthenticationToken; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - - -/** - * Tests security objects. - * - * @author Ben Alex - * @version $Id$ - */ -public class BankTests extends TestCase { - //~ Instance fields ================================================================================================ - - private BankService service; - private ClassPathXmlApplicationContext ctx; - - //~ Constructors =================================================================================================== - - public BankTests() { - } - - public BankTests(String arg0) { - super(arg0); - } - - //~ Methods ======================================================================================================== - - public final void setUp() throws Exception { - super.setUp(); - ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); - service = (BankService) ctx.getBean("bankService"); - } - - public void tearDown() { - SecurityContextHolder.clearContext(); - } - - private static void createSecureContext() { - TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test", - new GrantedAuthority[] { - new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl("ROLE_PERMISSION_LIST") - }); - - SecurityContextHolder.getContext().setAuthentication(auth); - } - - private static void destroySecureContext() { - SecurityContextHolder.setContext(new SecurityContextImpl()); - } - - public void testDeniedAccess() throws Exception { - createSecureContext(); - - try { - service.balance("1"); - fail("Should have thrown AccessDeniedException"); - } catch (AccessDeniedException expected) { - assertTrue(true); - } - - destroySecureContext(); - } - - public void testListAccounts() throws Exception { - createSecureContext(); - service.listAccounts(); - destroySecureContext(); - } -}