For more information about using the sample server program, see Downloading and running the IBM® JGSS samples.
// IBM Java GSS 1.0 sample JAAS-enabled server 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 server 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 server). * * The JAASServer is equivalent to its superclass {@link Server Server} * in all other respects, and it * can be run against the non-JAAS sample clients and servers. */ class JAASServer extends Server { JAASServer(String programName) throws Exception { super(programName); } static class JAASServerAction implements PrivilegedExceptionAction { private JAASServer server = null; JAASServerAction(JAASServer server) { this.server = server; } public Object run() throws Exception { server.initialize(); server.processRequests(); return null; } } public static void main(String[] args) throws Exception { String programName = "JAASServer"; Debug dbg = new Debug(); System.out.println(dbg.toString()); // XXXXXXX try { // Do not set useSubjectCredsOnly. // useSubjectCredsOnly defaults to "true" if not set. JAASServer server = new JAASServer(programName); server.processArgs(args); LoginContext loginCtxt = new LoginContext(programName, new Krb5CallbackHandler()); dbg.out(Debug.OPTS_CAT_APPLICATION, programName + ": Login in ..."); loginCtxt.login(); dbg.out(Debug.OPTS_CAT_APPLICATION, programName + ": Login successful"); Subject subject = loginCtxt.getSubject(); JAASServerAction serverAction = new JAASServerAction(server); Subject.doAsPrivileged(subject, serverAction, null); } catch (Exception exc) { dbg.out(Debug.OPTS_CAT_APPLICATION, programName + " EXCEPTION"); exc.printStackTrace(); throw exc; } } }