1 package org.jacorb.demo.sas; 2 3 import java.io.BufferedReader ; 4 import java.io.File ; 5 import java.io.FileReader ; 6 import java.security.Principal ; 7 import java.security.PrivilegedAction ; 8 9 import javax.security.auth.Subject ; 10 import javax.security.auth.login.LoginContext ; 11 import javax.security.auth.login.LoginException ; 12 13 import org.omg.CORBA.ORB ; 14 15 23 24 public class KerberosClient { 25 private static Principal myPrincipal = null; 26 private static Subject mySubject = null; 27 private static ORB orb = null; 28 29 public KerberosClient(String args[]) { 30 31 try { 32 orb = ORB.init(args, null); 34 35 File f = new File (args[0]); 37 if (!f.exists()) { 38 System.out.println("File " + args[0] + " does not exist."); 39 System.exit(-1); 40 } 41 if (f.isDirectory()) { 42 System.out.println("File " + args[0] + " is a directory."); 43 System.exit(-1); 44 } 45 BufferedReader br = new BufferedReader (new FileReader (f)); 46 org.omg.CORBA.Object obj = orb.string_to_object(br.readLine()); 47 br.close(); 48 SASDemo demo = SASDemoHelper.narrow(obj); 49 50 demo.printSAS(); 52 demo.printSAS(); 53 demo.printSAS(); 54 55 System.out.println("Call to server succeeded"); 56 } catch (Exception ex) { 57 ex.printStackTrace(); 58 } 59 } 60 61 public static void main(String args[]) { 62 if (args.length != 3) { 63 System.out.println("Usage: java demo.sas.KerberosClient <ior_file> <username> <password>"); 64 System.exit(1); 65 } 66 67 LoginContext loginContext = null; 69 try { 70 JaasTxtCalbackHandler txtHandler = new JaasTxtCalbackHandler(); 71 txtHandler.setMyUsername(args[1]); 72 txtHandler.setMyPassword(args[2].toCharArray()); 73 loginContext = new LoginContext ("KerberosClient", txtHandler); 74 loginContext.login(); 75 } catch (LoginException le) { 76 System.out.println("Login error: " + le); 77 System.exit(1); 78 } 79 mySubject = loginContext.getSubject(); 80 myPrincipal = (Principal ) mySubject.getPrincipals().iterator().next(); 81 System.out.println("Found principal " + myPrincipal.getName()); 82 83 final String [] finalArgs = args; 85 try { 86 Subject.doAs(mySubject, new PrivilegedAction () { 87 public Object run() { 88 try { 89 KerberosClient client = new KerberosClient(finalArgs); 90 orb.run(); 91 } catch (Exception e) { 92 System.out.println("Error running program: "+e); 93 } 94 System.out.println("Exiting privileged operation"); 95 return null; 96 } 97 }); 98 } catch (Exception e) { 99 System.out.println("Error running privileged: "+e); 100 } 101 } 102 } 103 | Popular Tags |