mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 09:12:14 +00:00
Add RMI + HTTP Invoker remoting protocols and fixes related to Maven migration.
This commit is contained in:
parent
2744251df3
commit
44b7cccc1f
@ -5,4 +5,5 @@
|
||||
|
||||
serverName=localhost
|
||||
httpPort=8080
|
||||
contextPath=/contacts
|
||||
contextPath=/acegi-security-sample-contacts-filter
|
||||
rmiPort=1099
|
||||
|
@ -14,6 +14,42 @@
|
||||
<property name="location"><value>client.properties</value></property>
|
||||
</bean>
|
||||
|
||||
<!-- Proxy for the RMI-exported ContactManager -->
|
||||
<!-- COMMENTED OUT BY DEFAULT TO AVOID CONFLICTS WITH APPLICATION SERVERS
|
||||
<bean id="rmiProxy" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
|
||||
<property name="serviceInterface">
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
<property name="serviceUrl">
|
||||
<value>rmi://${serverName}:${rmiPort}/contactManager</value>
|
||||
</property>
|
||||
<property name="remoteInvocationFactory">
|
||||
<ref local="remoteInvocationFactory"/>
|
||||
</property>
|
||||
</bean>
|
||||
-->
|
||||
|
||||
<!-- Automatically propagates ContextHolder contents when using the RMI proxy -->
|
||||
<bean id="remoteInvocationFactory" class="net.sf.acegisecurity.ui.rmi.ContextPropagatingRemoteInvocationFactory"/>
|
||||
|
||||
<!-- Proxy for the HTTP-invoker-exported ContactManager -->
|
||||
<!-- Spring's HTTP invoker uses Java serialization via HTTP -->
|
||||
<bean id="httpInvokerProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
|
||||
<property name="serviceInterface">
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
<property name="serviceUrl">
|
||||
<value>http://${serverName}:${httpPort}${contextPath}/remoting/ContactManager-httpinvoker</value>
|
||||
</property>
|
||||
<property name="httpInvokerRequestExecutor">
|
||||
<ref local="httpInvokerRequestExecutor"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Automatically propagates ContextHolder-managed Authentication principal
|
||||
and credentials to a HTTP invoker BASIC authentication header -->
|
||||
<bean id="httpInvokerRequestExecutor" class="net.sf.acegisecurity.ui.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor"/>
|
||||
|
||||
<!-- Proxy for the Hessian-exported ContactManager -->
|
||||
<!-- Hessian is a slim binary HTTP remoting protocol -->
|
||||
<bean id="hessianProxy" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
|
||||
@ -21,7 +57,7 @@
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
<property name="serviceUrl">
|
||||
<value>http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-hessian</value>
|
||||
<value>http://${serverName}:${httpPort}${contextPath}/remoting/ContactManager-hessian</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@ -32,7 +68,7 @@
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
<property name="serviceUrl">
|
||||
<value>http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-burlap</value>
|
||||
<value>http://${serverName}:${httpPort}${contextPath}/remoting/ContactManager-burlap</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,10 +70,10 @@
|
||||
</servlet>
|
||||
|
||||
<!--
|
||||
- Provides web services endpoint. See caucho-servlet.xml.
|
||||
- Provides web services endpoint. See remoting-servlet.xml.
|
||||
-->
|
||||
<servlet>
|
||||
<servlet-name>caucho</servlet-name>
|
||||
<servlet-name>remoting</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
@ -84,8 +84,8 @@
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>caucho</servlet-name>
|
||||
<url-pattern>/caucho/*</url-pattern>
|
||||
<servlet-name>remoting</servlet-name>
|
||||
<url-pattern>/remoting/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<welcome-file-list>
|
||||
|
@ -141,10 +141,10 @@
|
||||
</servlet>
|
||||
|
||||
<!--
|
||||
- Provides web services endpoint. See caucho-servlet.xml.
|
||||
- Provides web services endpoint. See remoting-servlet.xml.
|
||||
-->
|
||||
<servlet>
|
||||
<servlet-name>caucho</servlet-name>
|
||||
<servlet-name>remoting</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
@ -155,8 +155,8 @@
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>caucho</servlet-name>
|
||||
<url-pattern>/caucho/*</url-pattern>
|
||||
<servlet-name>remoting</servlet-name>
|
||||
<url-pattern>/remoting/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<welcome-file-list>
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<!--
|
||||
- Contacts web application
|
||||
- $Id$
|
||||
-->
|
||||
<beans>
|
||||
|
||||
<!-- Hessian exporter for the ContactManager -->
|
||||
<!-- Hessian is a slim binary HTTP remoting protocol -->
|
||||
<bean name="/ContactManager-hessian" class="org.springframework.remoting.caucho.HessianServiceExporter">
|
||||
<property name="service"><ref bean="contactManager"/></property>
|
||||
<property name="serviceInterface">
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Burlap exporter for the ContactManager -->
|
||||
<!-- Burlap is a slim XML-based HTTP remoting protocol -->
|
||||
<bean name="/ContactManager-burlap" class="org.springframework.remoting.caucho.BurlapServiceExporter">
|
||||
<property name="service"><ref bean="contactManager"/></property>
|
||||
<property name="serviceInterface">
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<!--
|
||||
- Contacts web application
|
||||
- $Id$
|
||||
-->
|
||||
<beans>
|
||||
|
||||
<!-- RMI exporter for the ContactManager -->
|
||||
<!-- This could just as easily have been in
|
||||
applicationContext-common-business.xml, because it doesn't rely on
|
||||
DispatcherServlet or indeed any other HTTP services. It's in this
|
||||
application context simply for logical placement with other
|
||||
remoting exporters. -->
|
||||
<!-- COMMENTED OUT BY DEFAULT TO AVOID CONFLICTS WITH APPLICATION SERVERS
|
||||
<bean id="contactManager-rmi" class="org.springframework.remoting.rmi.RmiServiceExporter">
|
||||
<property name="service"><ref bean="contactManager"/></property>
|
||||
<property name="serviceInterface">
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
<property name="serviceName"><value>contactManager</value></property>
|
||||
<property name="registryPort"><value>1099</value></property>
|
||||
</bean>
|
||||
-->
|
||||
|
||||
<!-- HTTP invoker exporter for the ContactManager -->
|
||||
<!-- Spring's HTTP invoker uses Java serialization via HTTP -->
|
||||
<bean name="/ContactManager-httpinvoker" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
|
||||
<property name="service"><ref bean="contactManager"/></property>
|
||||
<property name="serviceInterface">
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Hessian exporter for the ContactManager -->
|
||||
<!-- Hessian is a slim binary HTTP remoting protocol -->
|
||||
<bean name="/ContactManager-hessian" class="org.springframework.remoting.caucho.HessianServiceExporter">
|
||||
<property name="service"><ref bean="contactManager"/></property>
|
||||
<property name="serviceInterface">
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Burlap exporter for the ContactManager -->
|
||||
<!-- Burlap is a slim XML-based HTTP remoting protocol -->
|
||||
<bean name="/ContactManager-burlap" class="org.springframework.remoting.caucho.BurlapServiceExporter">
|
||||
<property name="service"><ref bean="contactManager"/></property>
|
||||
<property name="serviceInterface">
|
||||
<value>sample.contact.ContactManager</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
@ -137,10 +137,10 @@
|
||||
</servlet>
|
||||
|
||||
<!--
|
||||
- Provides web services endpoint. See caucho-servlet.xml.
|
||||
- Provides web services endpoint. See remoting-servlet.xml.
|
||||
-->
|
||||
<servlet>
|
||||
<servlet-name>caucho</servlet-name>
|
||||
<servlet-name>remoting</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
@ -151,8 +151,8 @@
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>caucho</servlet-name>
|
||||
<url-pattern>/caucho/*</url-pattern>
|
||||
<servlet-name>remoting</servlet-name>
|
||||
<url-pattern>/remoting/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<welcome-file-list>
|
||||
|
Loading…
x
Reference in New Issue
Block a user