diff --git a/.classpath b/.classpath index 47869cacbf..8bd5d18703 100644 --- a/.classpath +++ b/.classpath @@ -19,5 +19,6 @@ + diff --git a/integration-test/build.xml b/integration-test/build.xml index a73b4c883f..dd2d5befc1 100644 --- a/integration-test/build.xml +++ b/integration-test/build.xml @@ -21,6 +21,7 @@ + @@ -49,6 +50,7 @@ Among the available targets are: clean --> deletes output directories unzip --> unzips each container into file system tests --> unzips each container and runs all tests +tests-all --> runs all tests (does not unzip each container) tests-jetty --> runs the integration tests with Jetty tests-jboss --> runs the integration tests with JBoss tests-catalina --> runs the integration tests with Catalina @@ -94,7 +96,10 @@ Each tests-xxxx target assumes the container is unzipped - + + + @@ -217,6 +222,9 @@ Tomcat ${tomcat-5.version}: Run: ${jakarta-tomcat-5.run} Errored: ${jakart + + + @@ -287,6 +295,9 @@ Tomcat ${tomcat-5.version}: Run: ${jakarta-tomcat-5.run} Errored: ${jakart + + + @@ -349,6 +360,9 @@ Tomcat ${tomcat-5.version}: Run: ${jakarta-tomcat-5.run} Errored: ${jakart + + + diff --git a/integration-test/project.properties b/integration-test/project.properties index b3e507fb35..87ea4c07f0 100644 --- a/integration-test/project.properties +++ b/integration-test/project.properties @@ -16,6 +16,7 @@ lib.dir=${basedir}/../lib dist.lib.dir=${basedir}/../dist contacts.ca.war=${basedir}/../samples/contacts/dist/contacts-container-adapter.war contacts.filter.war=${basedir}/../samples/contacts/dist/contacts.war +contacts.client.jar=${basedir}/../samples/contacts/client/contacts.jar acegisecurity.xml=../src/net/sf/acegisecurity/adapters/acegisecurity.xml jalopy.xml=${basedir}/../jalopy.xml diff --git a/integration-test/src/net/sf/acegisecurity/integrationtests/web/AbstractContactsTests.java b/integration-test/src/net/sf/acegisecurity/integrationtests/web/AbstractContactsTests.java index 83cf139167..39ed0dc122 100644 --- a/integration-test/src/net/sf/acegisecurity/integrationtests/web/AbstractContactsTests.java +++ b/integration-test/src/net/sf/acegisecurity/integrationtests/web/AbstractContactsTests.java @@ -24,8 +24,17 @@ import com.meterware.httpunit.WebResponse; import junit.framework.TestCase; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; + +import org.springframework.remoting.RemoteAccessException; + +import sample.contact.ContactManager; + import java.net.URL; +import java.util.Properties; + /** * Tests the Contacts sample application from a HTTP user's perspective. @@ -63,6 +72,54 @@ public abstract class AbstractContactsTests extends TestCase { assertTrue(response.getText().lastIndexOf("sample.contact.Contact@") != -1); } + public void testHessianFailsWithIncorrectCredentials() { + String PREFIX = "beans."; + DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); + Properties p = new Properties(); + p.setProperty(PREFIX + "hessianProxy.class", + "org.springframework.remoting.caucho.HessianProxyFactoryBean"); + p.setProperty(PREFIX + "hessianProxy.serviceInterface", + "sample.contact.ContactManager"); + p.setProperty(PREFIX + "hessianProxy.serviceUrl", + getBaseUrl() + "/caucho/ContactManager-hessian"); + p.setProperty(PREFIX + "hessianProxy.username", "marissa"); + p.setProperty(PREFIX + "hessianProxy.password", "WRONG_PASSWORD"); + + (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, + PREFIX); + + ContactManager contactManager = (ContactManager) lbf.getBean( + "hessianProxy"); + + try { + contactManager.getRandomContact(); + fail("Should have thrown RemoteAccessException"); + } catch (RemoteAccessException exception) { + assertTrue(true); + } + } + + public void testHessianOperational() { + String PREFIX = "beans."; + DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); + Properties p = new Properties(); + p.setProperty(PREFIX + "hessianProxy.class", + "org.springframework.remoting.caucho.HessianProxyFactoryBean"); + p.setProperty(PREFIX + "hessianProxy.serviceInterface", + "sample.contact.ContactManager"); + p.setProperty(PREFIX + "hessianProxy.serviceUrl", + getBaseUrl() + "/caucho/ContactManager-hessian"); + p.setProperty(PREFIX + "hessianProxy.username", "marissa"); + p.setProperty(PREFIX + "hessianProxy.password", "koala"); + + (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, + PREFIX); + + ContactManager contactManager = (ContactManager) lbf.getBean( + "hessianProxy"); + assertTrue(contactManager.getRandomContact() != null); + } + public void testLoginNameCaseSensitive() throws Exception { WebConversation conversation = new WebConversation(); WebRequest request = new GetMethodWebRequest(getBaseUrl()); diff --git a/samples/contacts/build.xml b/samples/contacts/build.xml index e503ace24c..456f892d63 100644 --- a/samples/contacts/build.xml +++ b/samples/contacts/build.xml @@ -74,11 +74,14 @@ - - - + + + + + - + + @@ -147,6 +150,8 @@ + + @@ -175,6 +180,7 @@ + diff --git a/samples/contacts/client/client.bat b/samples/contacts/client/client.bat new file mode 100644 index 0000000000..98b2e7f7e1 --- /dev/null +++ b/samples/contacts/client/client.bat @@ -0,0 +1 @@ +%JAVA_HOME%/bin/java -cp ../../../lib/aop-alliance/aopalliance.jar;../../../lib/caucho/hessian.jar;../../../lib/caucho/burlap.jar;../../../lib/jakarta-commons/commons-collections.jar;../../../lib/jakarta-commons/commons-logging.jar;../../../lib/spring/spring.jar;contacts.jar sample.contact.ClientApplication %1 %2 %3 diff --git a/samples/contacts/client/client.properties b/samples/contacts/client/client.properties new file mode 100644 index 0000000000..1949f95a37 --- /dev/null +++ b/samples/contacts/client/client.properties @@ -0,0 +1,10 @@ +# Properties file with server URL settings for remote access. +# Applied by PropertyPlaceholderConfigurer from "clientContext.xml". +# +# $Id$ + +serverName=localhost +httpPort=8080 +contextPath=/contacts +username=marissa +password=koala diff --git a/samples/contacts/client/clientContext.xml b/samples/contacts/client/clientContext.xml new file mode 100644 index 0000000000..8c02547160 --- /dev/null +++ b/samples/contacts/client/clientContext.xml @@ -0,0 +1,43 @@ + + + + + + + + + + client.properties + + + + + + + sample.contact.ContactManager + + + http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-hessian + + ${username} + ${password} + + + + + + + sample.contact.ContactManager + + + http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-burlap + + ${username} + ${password} + + + \ No newline at end of file diff --git a/samples/contacts/etc/ca/applicationContext.xml b/samples/contacts/etc/ca/applicationContext.xml new file mode 100644 index 0000000000..ac9cc5f9d3 --- /dev/null +++ b/samples/contacts/etc/ca/applicationContext.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + my_run_as_password + + + + + + my_run_as_password + + + + my_password + + + + + + + + + + + + + + + + marissa=koala,ROLE_TELLER,ROLE_SUPERVISOR + dianne=emu,ROLE_TELLER + scott=wombat,ROLE_TELLER + peter=opal,disabled,ROLE_TELLER + + + + + + + false + true + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + sample.contact.ContactManager.delete=ROLE_SUPERVISOR,RUN_AS_SERVER + sample.contact.ContactManager.getAllByOwner=CONTACT_OWNED_BY_CURRENT_USER,RUN_AS_SERVER + sample.contact.ContactManager.save=CONTACT_OWNED_BY_CURRENT_USER,RUN_AS_SERVER + sample.contact.ContactManager.getById=ROLE_TELLER,RUN_AS_SERVER + + + + + + + + + + + + sample.contact.ContactManager.delete=ROLE_RUN_AS_SERVER + sample.contact.ContactManager.getAllByOwner=ROLE_RUN_AS_SERVER + sample.contact.ContactManager.save=ROLE_RUN_AS_SERVER + sample.contact.ContactManager.getById=ROLE_RUN_AS_SERVER + + + + + + + + sample.contact.ContactManager + + + publicContactManagerSecurity + publicContactManagerTarget + + + + + + + + + + sample.contact.ContactManager + + + backendContactManagerSecurity + backendContactManagerTarget + + + + + + + diff --git a/samples/contacts/etc/ca/web.xml b/samples/contacts/etc/ca/web.xml index 4f9e84c443..4b1d1652c2 100644 --- a/samples/contacts/etc/ca/web.xml +++ b/samples/contacts/etc/ca/web.xml @@ -15,16 +15,45 @@ Example of an application secured using Acegi Security System for Spring. + + + contextConfigLocation + /WEB-INF/applicationContext.xml + + + + Acegi HTTP BASIC Authorization Filter + net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter + + Acegi Security System for Spring Auto Integration Filter net.sf.acegisecurity.ui.AutoIntegrationFilter + + Acegi HTTP BASIC Authorization Filter + /* + + Acegi Security System for Spring Auto Integration Filter /* + + + org.springframework.web.context.ContextLoaderListener + + + + caucho + /caucho/* + + index.jsp diff --git a/samples/contacts/etc/filter/applicationContext.xml b/samples/contacts/etc/filter/applicationContext.xml index cdbba7b824..d846576b4f 100644 --- a/samples/contacts/etc/filter/applicationContext.xml +++ b/samples/contacts/etc/filter/applicationContext.xml @@ -52,6 +52,79 @@ + + + + + + false + + + + + + + + + + + + + + + + + sample.contact.ContactManager.delete=ROLE_SUPERVISOR,RUN_AS_SERVER + sample.contact.ContactManager.getAllByOwner=CONTACT_OWNED_BY_CURRENT_USER,RUN_AS_SERVER + sample.contact.ContactManager.save=CONTACT_OWNED_BY_CURRENT_USER,RUN_AS_SERVER + sample.contact.ContactManager.getById=ROLE_TELLER,RUN_AS_SERVER + + + + + + + + + + + + sample.contact.ContactManager.delete=ROLE_RUN_AS_SERVER + sample.contact.ContactManager.getAllByOwner=ROLE_RUN_AS_SERVER + sample.contact.ContactManager.save=ROLE_RUN_AS_SERVER + sample.contact.ContactManager.getById=ROLE_RUN_AS_SERVER + + + + + + + + sample.contact.ContactManager + + + publicContactManagerSecurity + publicContactManagerTarget + + + + + + + + + + sample.contact.ContactManager + + + backendContactManagerSecurity + backendContactManagerTarget + + + + + + diff --git a/samples/contacts/etc/filter/web.xml b/samples/contacts/etc/filter/web.xml index fedb2d80dc..5baa0042e0 100644 --- a/samples/contacts/etc/filter/web.xml +++ b/samples/contacts/etc/filter/web.xml @@ -41,6 +41,11 @@ + + Acegi HTTP BASIC Authorization Filter + net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter + + Acegi Security System for Spring Auto Integration Filter net.sf.acegisecurity.ui.AutoIntegrationFilter @@ -60,6 +65,11 @@ /* + + Acegi HTTP BASIC Authorization Filter + /* + + Acegi Security System for Spring Auto Integration Filter /* @@ -95,6 +105,12 @@ 1 + + caucho + org.springframework.web.servlet.DispatcherServlet + 2 + + + + caucho + /caucho/* + + index.jsp diff --git a/samples/contacts/project.properties b/samples/contacts/project.properties index ea088a2842..9ed9aafd4a 100644 --- a/samples/contacts/project.properties +++ b/samples/contacts/project.properties @@ -13,3 +13,4 @@ javadocs.dir=api jalopy.xml=${basedir}/../../jalopy.xml tmp.dir=temporary etc.dir=etc +client.dir=client diff --git a/samples/contacts/src/main/java/sample/contact/ClientApplication.java b/samples/contacts/src/main/java/sample/contact/ClientApplication.java new file mode 100644 index 0000000000..64b5880e0d --- /dev/null +++ b/samples/contacts/src/main/java/sample/contact/ClientApplication.java @@ -0,0 +1,107 @@ +/* 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 sample.contact; + +import org.springframework.beans.factory.ListableBeanFactory; + +import org.springframework.context.support.FileSystemXmlApplicationContext; + +import org.springframework.util.StopWatch; + +import java.util.Iterator; +import java.util.Map; + + +/** + * Demonstrates accessing the {@link ContactManager} via remoting protocols. + * + *

+ * Based on Spring's JPetStore sample, written by Juergen Hoeller. + *

+ * + * @author Ben Alex + */ +public class ClientApplication { + //~ Instance fields ======================================================== + + private final ListableBeanFactory beanFactory; + + //~ Constructors =========================================================== + + public ClientApplication(ListableBeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + + //~ Methods ================================================================ + + public void invokeContactManager(String username, int nrOfCalls) { + StopWatch stopWatch = new StopWatch(nrOfCalls + + " ContactManager call(s)"); + Map orderServices = this.beanFactory.getBeansOfType(ContactManager.class, + true, true); + + for (Iterator it = orderServices.keySet().iterator(); it.hasNext();) { + String beanName = (String) it.next(); + + ContactManager remoteContactManager = (ContactManager) orderServices + .get(beanName); + System.out.println("Calling ContactManager '" + beanName + + "' for owner " + username); + stopWatch.start(beanName); + + Contact[] contacts = null; + + for (int i = 0; i < nrOfCalls; i++) { + contacts = remoteContactManager.getAllByOwner(username); + } + + stopWatch.stop(); + + if (contacts.length != 0) { + for (int i = 0; i < contacts.length; i++) { + System.out.println("Contact " + i + ": " + + contacts[i].toString()); + } + } else { + System.out.println("No contacts found belonging to owner"); + } + + System.out.println(); + } + + System.out.println(stopWatch.prettyPrint()); + } + + public static void main(String[] args) { + if ((args.length == 0) || "".equals(args[0])) { + System.out.println( + "You need to specify a user ID and optionally a number of calls, e.g. for user marissa: " + + "'client marissa' for a single call per service or 'client marissa 10' for 10 calls each"); + } else { + String username = args[0]; + int nrOfCalls = 1; + + if ((args.length > 1) && !"".equals(args[1])) { + nrOfCalls = Integer.parseInt(args[1]); + } + + ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext( + "clientContext.xml"); + ClientApplication client = new ClientApplication(beanFactory); + client.invokeContactManager(username, nrOfCalls); + } + } +} diff --git a/samples/contacts/war/WEB-INF/caucho-servlet.xml b/samples/contacts/war/WEB-INF/caucho-servlet.xml new file mode 100644 index 0000000000..b28b7b03ae --- /dev/null +++ b/samples/contacts/war/WEB-INF/caucho-servlet.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + sample.contact.ContactManager + + + + + + + + + sample.contact.ContactManager + + + + diff --git a/samples/contacts/war/WEB-INF/contacts-servlet.xml b/samples/contacts/war/WEB-INF/contacts-servlet.xml index 6c771b534f..1a7711f6d5 100644 --- a/samples/contacts/war/WEB-INF/contacts-servlet.xml +++ b/samples/contacts/war/WEB-INF/contacts-servlet.xml @@ -51,126 +51,4 @@ .jsp
- - - - - my_run_as_password - - - - - - my_run_as_password - - - - my_password - - - - - - - - - - - - - - - - marissa=koala,ROLE_TELLER,ROLE_SUPERVISOR - dianne=emu,ROLE_TELLER - scott=wombat,ROLE_TELLER - peter=opal,disabled,ROLE_TELLER - - - - - - - false - true - - - - - - - - - - - - - false - - - - - - - - - - - - - - - - - sample.contact.ContactManager.delete=ROLE_SUPERVISOR,RUN_AS_SERVER - sample.contact.ContactManager.getAllByOwner=CONTACT_OWNED_BY_CURRENT_USER,RUN_AS_SERVER - sample.contact.ContactManager.save=CONTACT_OWNED_BY_CURRENT_USER,RUN_AS_SERVER - sample.contact.ContactManager.getById=ROLE_TELLER,RUN_AS_SERVER - - - - - - - - - - - - sample.contact.ContactManager.delete=ROLE_RUN_AS_SERVER - sample.contact.ContactManager.getAllByOwner=ROLE_RUN_AS_SERVER - sample.contact.ContactManager.save=ROLE_RUN_AS_SERVER - sample.contact.ContactManager.getById=ROLE_RUN_AS_SERVER - - - - - - - - sample.contact.ContactManager - - - publicContactManagerSecurity - publicContactManagerTarget - - - - - - - - - - sample.contact.ContactManager - - - backendContactManagerSecurity - backendContactManagerTarget - - - - - -