diff --git a/samples/contacts/client/client.properties b/samples/contacts/client/client.properties
index 539fc7dab2..8105a5e49b 100644
--- a/samples/contacts/client/client.properties
+++ b/samples/contacts/client/client.properties
@@ -5,4 +5,5 @@
serverName=localhost
httpPort=8080
-contextPath=/contacts
+contextPath=/acegi-security-sample-contacts-filter
+rmiPort=1099
diff --git a/samples/contacts/client/clientContext.xml b/samples/contacts/client/clientContext.xml
index cca485d481..b8e8c7678b 100644
--- a/samples/contacts/client/clientContext.xml
+++ b/samples/contacts/client/clientContext.xml
@@ -14,6 +14,42 @@
client.properties
+
+
+
+
+
+
+
+
+
+
+ sample.contact.ContactManager
+
+
+ http://${serverName}:${httpPort}${contextPath}/remoting/ContactManager-httpinvoker
+
+
+
+
+
+
+
+
+
@@ -21,7 +57,7 @@
sample.contact.ContactManager
- http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-hessian
+ http://${serverName}:${httpPort}${contextPath}/remoting/ContactManager-hessian
@@ -32,7 +68,7 @@
sample.contact.ContactManager
- http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-burlap
+ http://${serverName}:${httpPort}${contextPath}/remoting/ContactManager-burlap
diff --git a/samples/contacts/src/main/java/sample/contact/ClientApplication.java b/samples/contacts/src/main/java/sample/contact/ClientApplication.java
index c9bf2090b3..d290c5711a 100644
--- a/samples/contacts/src/main/java/sample/contact/ClientApplication.java
+++ b/samples/contacts/src/main/java/sample/contact/ClientApplication.java
@@ -15,6 +15,12 @@
package sample.contact;
+import net.sf.acegisecurity.Authentication;
+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.beans.factory.ListableBeanFactory;
import org.springframework.context.support.FileSystemXmlApplicationContext;
@@ -51,33 +57,36 @@ public class ClientApplication {
//~ Methods ================================================================
- public void invokeContactManager(String forOwner, String username,
- String password, int nrOfCalls) {
+ public void invokeContactManager(Authentication authentication,
+ int nrOfCalls) {
StopWatch stopWatch = new StopWatch(nrOfCalls
+ " ContactManager call(s)");
- Map orderServices = this.beanFactory.getBeansOfType(ContactManager.class,
+ Map contactServices = this.beanFactory.getBeansOfType(ContactManager.class,
true, true);
- for (Iterator it = orderServices.keySet().iterator(); it.hasNext();) {
- String beanName = (String) it.next();
+ SecureContext secureContext = new SecureContextImpl();
+ secureContext.setAuthentication(authentication);
+ ContextHolder.setContext(secureContext);
- ContactManager remoteContactManager = (ContactManager) orderServices
- .get(beanName);
- System.out.println("Calling ContactManager '" + beanName
- + "' for owner " + forOwner);
+ for (Iterator it = contactServices.keySet().iterator(); it.hasNext();) {
+ String beanName = (String) it.next();
Object object = this.beanFactory.getBean("&" + beanName);
try {
- System.out.println("Trying to find setUsername(String) method");
+ System.out.println(
+ "Trying to find setUsername(String) method on: "
+ + object.getClass().getName());
Method method = object.getClass().getMethod("setUsername",
new Class[] {String.class});
System.out.println("Found; Trying to setUsername(String) to "
- + username);
- method.invoke(object, new Object[] {username});
+ + authentication.getPrincipal());
+ method.invoke(object,
+ new Object[] {authentication.getPrincipal()});
} catch (NoSuchMethodException ignored) {
- ignored.printStackTrace();
+ System.out.println(
+ "This client proxy factory does not have a setUsername(String) method");
} catch (IllegalAccessException ignored) {
ignored.printStackTrace();
} catch (InvocationTargetException ignored) {
@@ -85,17 +94,26 @@ public class ClientApplication {
}
try {
- System.out.println("Trying to find setPassword(String) method");
+ System.out.println(
+ "Trying to find setPassword(String) method on: "
+ + object.getClass().getName());
Method method = object.getClass().getMethod("setPassword",
new Class[] {String.class});
- method.invoke(object, new Object[] {password});
+ method.invoke(object,
+ new Object[] {authentication.getCredentials()});
System.out.println("Found; Trying to setPassword(String) to "
- + password);
- } catch (NoSuchMethodException ignored) {}
- catch (IllegalAccessException ignored) {}
+ + authentication.getCredentials());
+ } catch (NoSuchMethodException ignored) {
+ System.out.println(
+ "This client proxy factory does not have a setPassword(String) method");
+ } catch (IllegalAccessException ignored) {}
catch (InvocationTargetException ignored) {}
+ ContactManager remoteContactManager = (ContactManager) contactServices
+ .get(beanName);
+ System.out.println("Calling ContactManager '" + beanName + "'");
+
stopWatch.start(beanName);
List contacts = null;
@@ -106,7 +124,7 @@ public class ClientApplication {
stopWatch.stop();
- if (contacts.size() == 0) {
+ if (contacts.size() != 0) {
Iterator listIterator = contacts.iterator();
while (listIterator.hasNext()) {
@@ -121,28 +139,36 @@ public class ClientApplication {
System.out.println();
System.out.println(stopWatch.prettyPrint());
}
+
+ ContextHolder.setContext(null);
}
public static void main(String[] args) {
- if ((args.length == 0) || "".equals(args[0])) {
- System.out.println(
- "You need to specify the owner to request contacts for, the user ID to use, the password to use, and optionally a number of calls, e.g. for user marissa: "
- + "'client marissa marissa koala' for a single call per service or 'client marissa marissa koala 10' for 10 calls each");
- } else {
- String forOwner = args[0];
- String username = args[1];
- String password = args[2];
+ String username = System.getProperty("username", "");
+ String password = System.getProperty("password", "");
+ String nrOfCallsString = System.getProperty("nrOfCalls", "");
+ if ("".equals(username) || "".equals(password)) {
+ System.out.println(
+ "You need to specify the user ID to use, the password to use, and optionally a number of calls "
+ + "using the username, password, and nrOfCalls system properties respectively. eg for user marissa, "
+ + "use: -Dusername=marissa -Dpassword=koala' for a single call per service and "
+ + "use: -Dusername=marissa -Dpassword=koala -DnrOfCalls=10 for ten calls per service.");
+ System.exit(-1);
+ } else {
int nrOfCalls = 1;
- if ((args.length > 3) && !"".equals(args[3])) {
- nrOfCalls = Integer.parseInt(args[3]);
+ if (!"".equals(nrOfCallsString)) {
+ nrOfCalls = Integer.parseInt(nrOfCallsString);
}
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(
"clientContext.xml");
ClientApplication client = new ClientApplication(beanFactory);
- client.invokeContactManager(forOwner, username, password, nrOfCalls);
+
+ client.invokeContactManager(new UsernamePasswordAuthenticationToken(
+ username, password), nrOfCalls);
+ System.exit(0);
}
}
}
diff --git a/samples/contacts/src/main/webapp/ca/WEB-INF/web.xml b/samples/contacts/src/main/webapp/ca/WEB-INF/web.xml
index e72ee88891..605a84b898 100644
--- a/samples/contacts/src/main/webapp/ca/WEB-INF/web.xml
+++ b/samples/contacts/src/main/webapp/ca/WEB-INF/web.xml
@@ -70,10 +70,10 @@
- caucho
+ remoting
org.springframework.web.servlet.DispatcherServlet
2
@@ -84,8 +84,8 @@
- caucho
- /caucho/*
+ remoting
+ /remoting/*
diff --git a/samples/contacts/src/main/webapp/cas/WEB-INF/web.xml b/samples/contacts/src/main/webapp/cas/WEB-INF/web.xml
index 6299f90175..83e304921b 100644
--- a/samples/contacts/src/main/webapp/cas/WEB-INF/web.xml
+++ b/samples/contacts/src/main/webapp/cas/WEB-INF/web.xml
@@ -141,10 +141,10 @@
- caucho
+ remoting
org.springframework.web.servlet.DispatcherServlet
2
@@ -155,8 +155,8 @@
- caucho
- /caucho/*
+ remoting
+ /remoting/*
diff --git a/samples/contacts/src/main/webapp/common/WEB-INF/caucho-servlet.xml b/samples/contacts/src/main/webapp/common/WEB-INF/caucho-servlet.xml
deleted file mode 100644
index b28b7b03ae..0000000000
--- a/samples/contacts/src/main/webapp/common/WEB-INF/caucho-servlet.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
- sample.contact.ContactManager
-
-
-
-
-
-
-
-
- sample.contact.ContactManager
-
-
-
-
diff --git a/samples/contacts/src/main/webapp/common/WEB-INF/remoting-servlet.xml b/samples/contacts/src/main/webapp/common/WEB-INF/remoting-servlet.xml
new file mode 100644
index 0000000000..cdc2ec7171
--- /dev/null
+++ b/samples/contacts/src/main/webapp/common/WEB-INF/remoting-servlet.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ sample.contact.ContactManager
+
+
+
+
+
+
+
+
+ sample.contact.ContactManager
+
+
+
+
+
+
+
+
+ sample.contact.ContactManager
+
+
+
+
diff --git a/samples/contacts/src/main/webapp/filter/WEB-INF/web.xml b/samples/contacts/src/main/webapp/filter/WEB-INF/web.xml
index ee12af5710..abb578b5b6 100644
--- a/samples/contacts/src/main/webapp/filter/WEB-INF/web.xml
+++ b/samples/contacts/src/main/webapp/filter/WEB-INF/web.xml
@@ -137,10 +137,10 @@
- caucho
+ remoting
org.springframework.web.servlet.DispatcherServlet
2
@@ -151,8 +151,8 @@
- caucho
- /caucho/*
+ remoting
+ /remoting/*