| 52 | import org.ietf.jgss.*; |
| 53 | |
| 54 | public class gssClient { |
| 55 | |
| 56 | /* set these to match your environment and principal names */ |
| 57 | private static int port = 11115; |
| 58 | private static String server = "127.0.0.1"; |
| 59 | private static String serviceName = "service@host"; |
| 60 | private static String clientPrincipal = "clientname"; |
| 61 | |
| 62 | private static GSSCredential clientCred = null; |
| 63 | private static GSSContext context = null; |
| 64 | private static GSSManager mgr = GSSManager.getInstance(); |
| 65 | |
| 66 | /* using null to request default mech, krb5 */ |
| 67 | private static Oid mech = null; |
| 68 | |
| 69 | private static Socket clientSocket = null; |
| 70 | private static OutputStream serverOut = null; |
| 71 | private static InputStream serverIn = null; |
| 72 | |
| 73 | public static void main(String argv[]) throws Exception { |
| 74 | |
| 75 | System.out.println("Starting GSS-API Client Example\n"); |
| 76 | |
| 77 | connectToServer(); |
| 78 | initializeGSS(); |
| 79 | establishContext(serverIn, serverOut); |
| 80 | doCommunication(serverIn, serverOut); |
| 81 | |
| 82 | /* shutdown */ |
| 83 | context.dispose(); |
| 84 | clientCred.dispose(); |
| 85 | serverIn.close(); |
| 86 | serverOut.close(); |
| 87 | clientSocket.close(); |
| 88 | |
| 89 | System.out.println("\nShut down GSS-API and closed connection to server"); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Connect to example GSS-API server, using specified port and |
| 94 | * service name. |
| 95 | **/ |
| 96 | public static void connectToServer() { |
| 97 | |
| 98 | try { |
| 99 | clientSocket = new Socket(server, port); |
| 100 | System.out.println("Connected to " + server + " at port " |
| 101 | + port + "\n"); |
| 102 | |
| 103 | /* get input and output streams */ |
| 104 | serverOut = clientSocket.getOutputStream(); |
| 105 | serverIn = clientSocket.getInputStream(); |
| 106 | |
| 107 | } catch (UnknownHostException e) { |
| 108 | System.err.println("Unknown host: " + server); |
| 109 | e.printStackTrace(); |
| 110 | } catch (IOException e) { |
| 111 | System.err.println("I/O error for the connection to " + server); |
nothing calls this directly
no test coverage detected