KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > demo > sas > GssUpServer


1 package org.jacorb.demo.sas;
2
3 import java.io.FileWriter JavaDoc;
4 import java.io.PrintWriter JavaDoc;
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 JavaDoc;
10 import org.omg.PortableServer.LifespanPolicyValue JavaDoc;
11 import org.omg.PortableServer.POA JavaDoc;
12 import org.omg.CORBA.ORB JavaDoc;
13 import org.omg.CORBA.Any JavaDoc;
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 JavaDoc orb;
29
30     public GssUpServer(ORB JavaDoc orb) {
31         this.orb = orb;
32     }
33
34     public void printSAS() {
35         try {
36             org.omg.PortableInterceptor.Current JavaDoc current = (org.omg.PortableInterceptor.Current JavaDoc)orb.resolve_initial_references("PICurrent");
37             org.omg.CORBA.Any JavaDoc 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 JavaDoc name = anyName.extract_string();
42                 System.out.println("printSAS for user " + name);
43             }
44         } catch (Exception JavaDoc e) {
45             e.printStackTrace();
46         }
47     }
48
49     public static void main(String JavaDoc[] 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             // initialize the ORB and POA.
57
ORB JavaDoc orb = ORB.init(args, null);
58             POA JavaDoc rootPOA = (POA JavaDoc) orb.resolve_initial_references("RootPOA");
59             org.omg.CORBA.Policy JavaDoc [] policies = new org.omg.CORBA.Policy JavaDoc[3];
60             policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
61             policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
62             Any JavaDoc 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 JavaDoc securePOA = rootPOA.create_POA("SecurePOA", rootPOA.the_POAManager(), policies);
66             rootPOA.the_POAManager().activate();
67
68             // create object and write out IOR
69
GssUpServer server = new GssUpServer(orb);
70             securePOA.activate_object_with_id("SecureObject".getBytes(), server);
71             org.omg.CORBA.Object JavaDoc demo = securePOA.servant_to_reference(server);
72             PrintWriter JavaDoc pw = new PrintWriter JavaDoc(new FileWriter JavaDoc(args[0]));
73             pw.println(orb.object_to_string(demo));
74             pw.flush();
75             pw.close();
76
77             // run the ORB
78
orb.run();
79         } catch (Exception JavaDoc e) {
80             e.printStackTrace();
81         }
82     }
83 }
84
Popular Tags