1 package demo.ssl; 2 3 import java.io.*; 4 5 import java.security.cert.X509Certificate ; 6 7 import org.omg.PortableServer.POA ; 8 import org.omg.SecurityLevel2.*; 9 import org.omg.Security.*; 10 import org.omg.CORBA.ORB ; 11 12 import org.jacorb.security.level2.*; 13 14 23 24 public class Server 25 extends SSLDemoPOA 26 { 27 private Current current = null; 29 30 34 private SecAttributeManager attrib_mgr = null; 35 36 private AttributeType[] access_id = null; 39 40 41 public Server( Current current ) 42 { 43 this.current = current; 44 45 attrib_mgr = SecAttributeManager.getInstance(); 46 47 AttributeType attribute_type = 48 new AttributeType(new ExtensibleFamily((short) 0, 49 (short) 1), 50 AccessId.value); 51 52 access_id = new AttributeType[] {attribute_type}; 53 } 54 55 59 private X509Certificate getClientCert() 60 { 61 ReceivedCredentials creds = current.received_credentials(); 63 64 if (creds == null) 65 { 66 return null; 67 } 68 69 SecAttribute[] attribs = creds.get_attributes( access_id ); 71 72 if( attribs.length == 0 ) 73 { 74 return null; 75 } 76 77 KeyAndCert kac = attrib_mgr.getAttributeCertValue( attribs[0] ); 80 81 if( kac == null ) 82 { 83 return null; 84 } 85 86 return (X509Certificate ) kac.chain[0]; 88 } 89 90 91 95 public void printCert() 96 { 97 X509Certificate client_cert = getClientCert(); 98 99 if( client_cert == null ) 100 { 101 System.out.println( "No client certificate available" ); 102 } 103 else 104 { 105 System.out.println( "Received a client certificate:" ); 106 System.out.println( client_cert ); 107 } 108 } 109 110 public static void main( String [] args ) 111 { 112 if( args.length != 1 ) 113 { 114 System.out.println( "Usage: java demo.ssl.Server <ior_file>" ); 115 System.exit( -1 ); 116 } 117 118 try 119 { 120 ORB orb = ORB.init( args, null ); 121 122 POA poa = (POA ) 123 orb.resolve_initial_references( "RootPOA" ); 124 125 poa.the_POAManager().activate(); 126 127 Current current = (org.omg.SecurityLevel2.Current) 128 orb.resolve_initial_references( "SecurityCurrent" ); 129 130 org.omg.CORBA.Object demo = 131 poa.servant_to_reference( new Server( current )); 132 133 PrintWriter pw = 134 new PrintWriter( new FileWriter( args[ 0 ] )); 135 136 pw.println( orb.object_to_string( demo )); 138 139 pw.flush(); 140 pw.close(); 141 142 orb.run(); 144 } 145 catch( Exception e ) 146 { 147 e.printStackTrace(); 148 } 149 } 150 } | Popular Tags |