java client
radl01 Jul 2, 2003 11:35 AMHallo all,
I have a problem with ClientLoginModule. I code very simple SessionBean and very simple java client which should use ClientLoginModule to authenticate user.
Here are the config files on server-side
 <container-configurations>
 <container-configuration>
 <container-name>Standard Stateful SessionBean</container-name>
 <security-domain>java:/jaas/exa1</security-domain>
 </container-configuration>
 </container-configurations>
etc..
and login-config.xml
 <application-policy name = "exa1">
 <login-module code = "org.jboss.security.auth.spi.UsersRolesLoginModule"
 flag = "required" />
 <module-option name = "password-stacking">useFirstPass</module-option>
 <module-option name = "unauthenticatedIdentity">nobody</module-option>
 <module-option name = "debug">true</module-option>
 </application-policy>
On client side I have auth.conf like this:
client-login {
 // jBoss LoginModule
 org.jboss.security.ClientLoginModule required
 ;
 //password-stacking="useFirstPass"
 // Put your login modules that need jBoss here
};
Short snap-shot of client app:
 static class AppCallbackHandler implements CallbackHandler {
 private String username;
 private char[] password;
 public AppCallbackHandler(String username, char[] password) {
 this.username = username;
 this.password = password;
 }
 public void handle(Callback[] callbacks) throws java.io.IOException,
 UnsupportedCallbackException {
 for (int i = 0; i < callbacks.length; i++) {
 if (callbacks instanceof NameCallback) {
 NameCallback nc = (NameCallback)callbacks;
 nc.setName(username);
 } else if (callbacks instanceof PasswordCallback) {
 PasswordCallback pc = (PasswordCallback)callbacks;
 pc.setPassword(password);
 } else {
 throw new UnsupportedCallbackException(callbacks, "Unrecognized Callback");
 }
 }
 }
 }
 public static void main(String args[]) throws Exception {
 if( args.length != 3 )
 throw new IllegalArgumentException("Usage: username password example");
 System.setErr(System.out);
 String name = args[0];
 char[] password = args[1].toCharArray();
 String example = args[2];
 System.out.println("+++ Running SessionClient with username="+name+", password="+args[1]+", example=
 "+example);
 try {
 System.out.println("before new AppCalllback");
 AppCallbackHandler handler = new AppCallbackHandler(name, password);
 System.out.println("after new AppCalllback");
 LoginContext lc = new LoginContext(example, handler);
 System.out.println("Created LoginContext");
 lc.login();
 System.out.println(lc.toString());
 System.out.println(lc.getSubject().toString());
 } catch (LoginException le) {
 System.out.println("Login failed");
 le.printStackTrace();
 }
 try {
 InitialContext ctx = new InitialContext();
 Object objRef = ctx.lookup("ejb/Salary");
 SalaryHome home = (SalaryHome)javax.rmi.PortableRemoteObject.narrow(objRef,
 etc.
 I run java client with this script:
 #!/bin/sh
 if [ "x$JBOSS_HOME" = "x" ]; then
 JBOSS_HOME="/opt/jboss"
 export JBOSS_HOME
 fi
 $JRE_HOME/bin/java -Djava.security.auth.login.config=auth.conf -classpath .:auth.conf:$JBOSS_HOME/client/jbossall-client.jar:./ejb_sample_client.jar:./ejb_first.jar com.client.SalaryClient "$@"
 1. param is username
 2. param is paasword
 3. param is ID of ClientLoginModule ("client-login") that is spec. in auth.conf
 Problem:
 On server side I have principal equals to null => I=ve got exception like this:
 2003-07-02 17:05:48,151 ERROR [org.jboss.ejb.plugins.LogInterceptor] EJBException, causedBy:
 java.lang.SecurityException: Authentication exception, principal=null
 at org.jboss.ejb.plugins.SecurityInterceptor.checkSecurityAssociation(SecurityInterceptor.java:162)
 at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:81)
 at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
 at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invokeHome(StatefulSessionInstanceInterceptor.java:128)
 at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
 at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
 at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
 at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
 at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
 at org.jboss.ejb.StatefulSessionContainer.internalInvokeHome(StatefulSessionContainer.java:398)
 at org.jboss.ejb.Container.invoke(Container.java:694)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:324)
 at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
 at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:324)
 at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
 at sun.rmi.transport.Transport$1.run(Transport.java:148)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
 at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
 at java.lang.Thread.run(Thread.java:536)
 Pleas help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 Jan
 
     
     
     
    