01: package org.jacorb.demo.sas;
02:
03: import java.io.FileWriter;
04: import java.io.PrintWriter;
05:
06: import org.jacorb.sasPolicy.SASPolicyValues;
07: import org.jacorb.sasPolicy.SAS_POLICY_TYPE;
08: import org.jacorb.sasPolicy.SASPolicyValuesHelper;
09: 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: /**
17: * This is the server part of the sas demo. It demonstrates
18: * how to get access to the certificates that the client sent
19: * for mutual authentication. The certificate chain can be
20: * accessed via the Security Level 2 interfaces.
21: *
22: * @author Nicolas Noffke
23: * @version $Id: GssUpServer.java,v 1.3 2004/02/05 10:49:54 nick.cross Exp $
24: */
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
37: .resolve_initial_references("PICurrent");
38: org.omg.CORBA.Any anyName = current
39: .get_slot(org.jacorb.security.sas.SASInitializer.sasPrincipalNamePIC);
40: if (anyName.type().kind().value() == org.omg.CORBA.TCKind._tk_null) {
41: System.out.println("Null Name");
42: } else {
43: String name = anyName.extract_string();
44: System.out.println("printSAS for user " + name);
45: }
46: } catch (Exception e) {
47: e.printStackTrace();
48: }
49: }
50:
51: public static void main(String[] args) {
52: if (args.length != 1) {
53: System.out
54: .println("Usage: java demo.sas.GssUpServer <ior_file>");
55: System.exit(-1);
56: }
57:
58: try {
59: // initialize the ORB and POA.
60: ORB orb = ORB.init(args, null);
61: POA rootPOA = (POA) orb
62: .resolve_initial_references("RootPOA");
63: org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[3];
64: policies[0] = rootPOA
65: .create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
66: policies[1] = rootPOA
67: .create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
68: Any sasAny = orb.create_any();
69: SASPolicyValuesHelper.insert(sasAny, new SASPolicyValues(
70: EstablishTrustInClient.value,
71: EstablishTrustInClient.value, true));
72: policies[2] = orb.create_policy(SAS_POLICY_TYPE.value,
73: sasAny);
74: POA securePOA = rootPOA.create_POA("SecurePOA", rootPOA
75: .the_POAManager(), policies);
76: rootPOA.the_POAManager().activate();
77:
78: // create object and write out IOR
79: GssUpServer server = new GssUpServer(orb);
80: securePOA.activate_object_with_id(
81: "SecureObject".getBytes(), server);
82: org.omg.CORBA.Object demo = securePOA
83: .servant_to_reference(server);
84: PrintWriter pw = new PrintWriter(new FileWriter(args[0]));
85: pw.println(orb.object_to_string(demo));
86: pw.flush();
87: pw.close();
88:
89: // run the ORB
90: orb.run();
91: } catch (Exception e) {
92: e.printStackTrace();
93: }
94: }
95: }
|