For more information about using the sample client program, see Downloading and running the IBM® JGSS samples.
// IBM Java GSS 1.0 sample JAAS-enabled client program package com.ibm.security.jgss.test; import com.ibm.security.jgss.Debug; import com.ibm.security.auth.callback.Krb5CallbackHandler; import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; import java.security.PrivilegedExceptionAction; /** * A Java GSS sample client that uses JAAS. * * It does a JAAS login and operates within the JAAS login context so created. * * It does not set the JAVA variable * javax.security.auth.useSubjectCredsOnly, leaving * the variable to default to true * so that Java GSS acquires credentials from the JAAS Subject * associated with login context (created by the client). * * The JAASClient is equivalent to its superclass {@link Client Client} * in all other respects, and it * can be run against the non-JAAS sample clients and servers. */ class JAASClient extends Client { JAASClient(String programName) throws Exception { // Do not set useSubjectCredsOnly. Set only the program name. // useSubjectCredsOnly default to "true" if not set. super(programName); } static class JAASClientAction implements PrivilegedExceptionAction { private JAASClient client; public JAASClientAction(JAASClient client) { this.client = client; } public Object run () throws Exception { client.initialize(); client.interactWithAcceptor(); return null; } } public static void main(String args[]) throws Exception { String programName = "JAASClient"; JAASClient client = null; Debug dbg = new Debug(); System.out.println(dbg.toString()); // XXXXXXX try { client = new JAASClient(programName);//use Subject creds client.processArgs(args); LoginContext loginCtxt = new LoginContext("JAASClient", new Krb5CallbackHandler()); loginCtxt.login(); dbg.out(Debug.OPTS_CAT_APPLICATION, programName + ": Kerberos login OK"); Subject subject = loginCtxt.getSubject(); PrivilegedExceptionAction jaasClientAction = new JAASClientAction(client); Subject.doAsPrivileged(subject, jaasClientAction, null); } catch (Exception exc) { dbg.out(Debug.OPTS_CAT_APPLICATION, programName + " Exception: " + exc.toString()); exc.printStackTrace(); throw exc; } finally { try { if (client != null) client.dispose(); } catch (Exception exc) {} } dbg.out(Debug.OPTS_CAT_APPLICATION, programName + ": Done ..."); } }