users@glassfish.java.net

Re: JAAS in standalone application with GlassFish

From: <glassfish_at_javadesktop.org>
Date: Mon, 05 Nov 2007 17:33:31 PST

I am having the same problem.. I can't believe it is so complicated!
I'm pretty sure all the server-side configuration is ok.
Here's what I tried on the client:

    public void test() throws Exception
    {
        System.setProperty("java.security.auth.login.config", "c:/projects/ErpApplication/config/jaas.config");
        ScitCallbackHandler handler = new ScitCallbackHandler("sales", "sales".toCharArray());
        LoginContext loginContext = new LoginContext("fileRealm", handler);
        loginContext.login();

        Properties props = new Properties();
        //props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
        //props.setProperty(Context.SECURITY_PRINCIPAL, "sales");
        //props.setProperty(Context.SECURITY_CREDENTIALS, "sales");
        props.setProperty("java.naming.factory.initial",
                "com.sun.enterprise.naming.SerialInitContextFactory");
        props.setProperty("java.naming.factory.url.pkgs",
                "com.sun.enterprise.naming");
        props.setProperty("java.naming.factory.state",
                "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

        // optional. Defaults to localhost. Only needed if web server is running
    // on a different host than the appserver
        props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");

        // optional. Defaults to 3700. Only needed if target orb port is not 3700.
        props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

        InitialContext ctx = new InitialContext(props);
        
        MyOperationsRemote br = (MyOperationsRemote) ctx.lookup("SecurityOperations");

        try
        {
            String[] roles = br.getListOfNames();
            System.out.println(roles.length + " roles ");
            for (String role : roles)
            {
                System.out.println(role);
            }
        } catch (Exception x)
        {
            x.printStackTrace();
            throw x;
        }


    }

I am trying the JAAS stuff because just putting the username and password in the initialcontext did not work. The Callback class just returns a static username and password for testing.
Here's what's in my jaas.config - but honestly I don't know what I am doing anymore.

fileRealm {
        com.sun.enterprise.security.auth.login.FileLoginModule required;
};

ldapRealm {
        com.sun.enterprise.security.auth.login.LDAPLoginModule required;
};

solarisRealm {
        com.sun.enterprise.security.auth.login.SolarisLoginModule required;
};

jdbcRealm {
        com.sun.enterprise.security.auth.login.JDBCLoginModule required;
};

I can't find a comprehensive example for the client.. very frustrating.
Thanks for any help.
[Message sent by forum member 'manjuka' (manjuka)]

http://forums.java.net/jive/thread.jspa?messageID=243976