I read the article and based on it the following standalone class should be able to 
access the remote EJB because the logincontext.login() call succeeds. Is there 
anything wrong with this class?

===============================================
package tutorial.client;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.security.auth.callback.*;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

import tutorial.interfaces.Fibo;
import tutorial.interfaces.FiboHome;


public class ClientMain {
    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) {
        FiboHome home;
        String name = "login";
        char[] password = "password".toCharArray();
        try {
            AppCallbackHandler handler = new AppCallbackHandler(name, password);
            LoginContext lc = new LoginContext("TestClient", handler);
            System.out.println("Created LoginContext");
            lc.login();
        } catch (LoginException le) {
            System.out.println("Login failed");
            le.printStackTrace();
        }

        try {
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, 
"org.jnp.interfaces.NamingContextFactory");
            env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
            env.put(Context.OBJECT_FACTORIES, "org.jboss.naming:org.jnp.interfaces");
            
            Context context = new InitialContext(env);
            Object ref = context.lookup("ejb/tutorial/Fibo");
            home = (FiboHome) PortableRemoteObject.narrow(ref, FiboHome.class);
            
            env = context.getEnvironment();
            Set keys = env.keySet();
            Iterator it = keys.iterator();
            while (it.hasNext()) {
                Object next = it.next();
                System.out.println("key: " + next + ", value: " + env.get(next));
            }
            
            Fibo bean = home.create();
            double[] result = bean.compute(5);
            bean.remove();
            System.out.println("The first 5 Fibonacci numbers ");
            for (int i = 0; i < result.length; i++) {
                System.out.println(result);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
===============================================


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3839323#3839323

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3839323


-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to