1 package org.jacorb.demo.sas; 2 3 import java.io.FileWriter ; 4 import java.io.PrintWriter ; 5 6 import org.jacorb.sasPolicy.SASPolicyValues; 7 import org.jacorb.sasPolicy.SAS_POLICY_TYPE; 8 import org.jacorb.sasPolicy.SASPolicyValuesHelper; 9 import org.omg.PortableServer.IdAssignmentPolicyValue ; 10 import org.omg.PortableServer.LifespanPolicyValue ; 11 import org.omg.PortableServer.POA ; 12 import org.omg.CORBA.ORB ; 13 import org.omg.CORBA.Any ; 14 import org.omg.CSIIOP.EstablishTrustInClient; 15 16 25 26 public class GssUpServer extends SASDemoPOA { 27 28 private ORB orb; 29 30 public GssUpServer(ORB orb) { 31 this.orb = orb; 32 } 33 34 public void printSAS() { 35 try { 36 org.omg.PortableInterceptor.Current current = (org.omg.PortableInterceptor.Current )orb.resolve_initial_references("PICurrent"); 37 org.omg.CORBA.Any anyName = current.get_slot(org.jacorb.security.sas.SASInitializer.sasPrincipalNamePIC); 38 if( anyName.type().kind().value() == org.omg.CORBA.TCKind._tk_null ) { 39 System.out.println("Null Name"); 40 } else { 41 String name = anyName.extract_string(); 42 System.out.println("printSAS for user " + name); 43 } 44 } catch (Exception e) { 45 e.printStackTrace(); 46 } 47 } 48 49 public static void main(String [] args) { 50 if (args.length != 1) { 51 System.out.println("Usage: java demo.sas.GssUpServer <ior_file>"); 52 System.exit(-1); 53 } 54 55 try { 56 ORB orb = ORB.init(args, null); 58 POA rootPOA = (POA ) orb.resolve_initial_references("RootPOA"); 59 org.omg.CORBA.Policy [] policies = new org.omg.CORBA.Policy [3]; 60 policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID); 61 policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); 62 Any sasAny = orb.create_any(); 63 SASPolicyValuesHelper.insert( sasAny, new SASPolicyValues(EstablishTrustInClient.value, EstablishTrustInClient.value, true) ); 64 policies[2] = orb.create_policy(SAS_POLICY_TYPE.value, sasAny); 65 POA securePOA = rootPOA.create_POA("SecurePOA", rootPOA.the_POAManager(), policies); 66 rootPOA.the_POAManager().activate(); 67 68 GssUpServer server = new GssUpServer(orb); 70 securePOA.activate_object_with_id("SecureObject".getBytes(), server); 71 org.omg.CORBA.Object demo = securePOA.servant_to_reference(server); 72 PrintWriter pw = new PrintWriter (new FileWriter (args[0])); 73 pw.println(orb.object_to_string(demo)); 74 pw.flush(); 75 pw.close(); 76 77 orb.run(); 79 } catch (Exception e) { 80 e.printStackTrace(); 81 } 82 } 83 } 84 | Popular Tags |