Improve client application by moving username/password specification to command-line.
This commit is contained in:
parent
66e8d741ca
commit
7ae1844130
|
@ -1564,7 +1564,7 @@ public boolean supports(Class clazz);</programlisting></para>
|
||||||
be used instead of Container Adapters.</para>
|
be used instead of Container Adapters.</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="security-ui-http-session">
|
<sect2 id="security-ui-http-basic">
|
||||||
<title>HTTP Basic Authentication</title>
|
<title>HTTP Basic Authentication</title>
|
||||||
|
|
||||||
<para>Primarily to cater for the needs of remoting protocols such as
|
<para>Primarily to cater for the needs of remoting protocols such as
|
||||||
|
@ -2180,15 +2180,16 @@ $CATALINA_HOME/bin/startup.sh</programlisting></para>
|
||||||
and Burlap protocols. This demonstrates how to use the Acegi Security
|
and Burlap protocols. This demonstrates how to use the Acegi Security
|
||||||
System for Spring for authentication with Spring remoting protocols. To
|
System for Spring for authentication with Spring remoting protocols. To
|
||||||
try this client, ensure your servlet container is still running the
|
try this client, ensure your servlet container is still running the
|
||||||
Contacts sample application, and then execute <literal>client
|
Contacts sample application, and then execute <literal>client marissa
|
||||||
marissa</literal>. This will use the remoting protocols to obtain the
|
marissa koala</literal>. The command-line parameters respectively
|
||||||
list of contacts with the owner specified (in this case
|
represent the owner of the contacts to extract, the username to use, and
|
||||||
<literal>marissa</literal>). Note you will be need to edit
|
the password to use. Note that you may need to edit
|
||||||
<literal>client.properties</literal> to use a different username,
|
<literal>client.properties</literal> to use a different target URL. To
|
||||||
password, or target URL. To see that security does indeed work, try
|
see that security does indeed work, try running <literal>client scott
|
||||||
running <literal>client scott</literal> before changing
|
marissa koala</literal>, which will try to obtain
|
||||||
<literal>client.properties</literal> to use <literal>scott</literal>'s
|
<literal>scott</literal>'s contacts when authenticating as
|
||||||
authentication details.</para>
|
<literal>marissa</literal>. To see it work properly, use <literal>client
|
||||||
|
scott scott wombat</literal>.</para>
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
||||||
<sect1 id="security-become-involved">
|
<sect1 id="security-become-involved">
|
||||||
|
|
|
@ -6,5 +6,3 @@
|
||||||
serverName=localhost
|
serverName=localhost
|
||||||
httpPort=8080
|
httpPort=8080
|
||||||
contextPath=/contacts
|
contextPath=/contacts
|
||||||
username=marissa
|
|
||||||
password=koala
|
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
<property name="serviceUrl">
|
<property name="serviceUrl">
|
||||||
<value>http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-hessian</value>
|
<value>http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-hessian</value>
|
||||||
</property>
|
</property>
|
||||||
<property name="username"><value>${username}</value></property>
|
|
||||||
<property name="password"><value>${password}</value></property>
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Proxy for the Burlap-exported ContactManager -->
|
<!-- Proxy for the Burlap-exported ContactManager -->
|
||||||
|
@ -36,8 +34,6 @@
|
||||||
<property name="serviceUrl">
|
<property name="serviceUrl">
|
||||||
<value>http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-burlap</value>
|
<value>http://${serverName}:${httpPort}${contextPath}/caucho/ContactManager-burlap</value>
|
||||||
</property>
|
</property>
|
||||||
<property name="username"><value>${username}</value></property>
|
|
||||||
<property name="password"><value>${password}</value></property>
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
|
@ -21,6 +21,9 @@ import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||||
|
|
||||||
import org.springframework.util.StopWatch;
|
import org.springframework.util.StopWatch;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -47,7 +50,8 @@ public class ClientApplication {
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public void invokeContactManager(String username, int nrOfCalls) {
|
public void invokeContactManager(String forOwner, String username,
|
||||||
|
String password, int nrOfCalls) {
|
||||||
StopWatch stopWatch = new StopWatch(nrOfCalls
|
StopWatch stopWatch = new StopWatch(nrOfCalls
|
||||||
+ " ContactManager call(s)");
|
+ " ContactManager call(s)");
|
||||||
Map orderServices = this.beanFactory.getBeansOfType(ContactManager.class,
|
Map orderServices = this.beanFactory.getBeansOfType(ContactManager.class,
|
||||||
|
@ -59,13 +63,44 @@ public class ClientApplication {
|
||||||
ContactManager remoteContactManager = (ContactManager) orderServices
|
ContactManager remoteContactManager = (ContactManager) orderServices
|
||||||
.get(beanName);
|
.get(beanName);
|
||||||
System.out.println("Calling ContactManager '" + beanName
|
System.out.println("Calling ContactManager '" + beanName
|
||||||
+ "' for owner " + username);
|
+ "' for owner " + forOwner);
|
||||||
|
|
||||||
|
Object object = this.beanFactory.getBean("&" + beanName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("Trying to find setUsername(String) method");
|
||||||
|
|
||||||
|
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});
|
||||||
|
} catch (NoSuchMethodException ignored) {
|
||||||
|
ignored.printStackTrace();
|
||||||
|
} catch (IllegalAccessException ignored) {
|
||||||
|
ignored.printStackTrace();
|
||||||
|
} catch (InvocationTargetException ignored) {
|
||||||
|
ignored.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("Trying to find setPassword(String) method");
|
||||||
|
|
||||||
|
Method method = object.getClass().getMethod("setPassword",
|
||||||
|
new Class[] {String.class});
|
||||||
|
method.invoke(object, new Object[] {password});
|
||||||
|
System.out.println("Found; Trying to setPassword(String) to "
|
||||||
|
+ password);
|
||||||
|
} catch (NoSuchMethodException ignored) {}
|
||||||
|
catch (IllegalAccessException ignored) {}
|
||||||
|
catch (InvocationTargetException ignored) {}
|
||||||
|
|
||||||
stopWatch.start(beanName);
|
stopWatch.start(beanName);
|
||||||
|
|
||||||
Contact[] contacts = null;
|
Contact[] contacts = null;
|
||||||
|
|
||||||
for (int i = 0; i < nrOfCalls; i++) {
|
for (int i = 0; i < nrOfCalls; i++) {
|
||||||
contacts = remoteContactManager.getAllByOwner(username);
|
contacts = remoteContactManager.getAllByOwner(forOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
|
@ -88,20 +123,23 @@ public class ClientApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if ((args.length == 0) || "".equals(args[0])) {
|
if ((args.length == 0) || "".equals(args[0])) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"You need to specify a user ID and optionally a number of calls, e.g. for user marissa: "
|
"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' for a single call per service or 'client marissa 10' for 10 calls each");
|
+ "'client marissa marissa koala' for a single call per service or 'client marissa marissa koala 10' for 10 calls each");
|
||||||
} else {
|
} else {
|
||||||
String username = args[0];
|
String forOwner = args[0];
|
||||||
|
String username = args[1];
|
||||||
|
String password = args[2];
|
||||||
|
|
||||||
int nrOfCalls = 1;
|
int nrOfCalls = 1;
|
||||||
|
|
||||||
if ((args.length > 1) && !"".equals(args[1])) {
|
if ((args.length > 3) && !"".equals(args[3])) {
|
||||||
nrOfCalls = Integer.parseInt(args[1]);
|
nrOfCalls = Integer.parseInt(args[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(
|
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(
|
||||||
"clientContext.xml");
|
"clientContext.xml");
|
||||||
ClientApplication client = new ClientApplication(beanFactory);
|
ClientApplication client = new ClientApplication(beanFactory);
|
||||||
client.invokeContactManager(username, nrOfCalls);
|
client.invokeContactManager(forOwner, username, password, nrOfCalls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue