Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jacorb.demo.sas;
  
  import java.io.FileWriter;
  
 
This is the server part of the sas demo. It demonstrates how to get access to the certificates that the client sent for mutual authentication. The certificate chain can be accessed via the Security Level 2 interfaces.

Author(s):
Nicolas Noffke
 
 
 public class KerberosServer extends SASDemoPOA {
     private static Principal myPrincipal = null;
     private static Subject mySubject = null;
     private ORB orb;
     private boolean shutdown;
 
     public KerberosServer(ORB orb) {
         this. = orb;
     }
 
     public void shutdown ()
     {
          = true;
     }
 
     public boolean getShutdown ()
     {
         return ;
     }
 
     public void printSAS() {
         try {
             org.omg.PortableInterceptor.Current current = (org.omg.PortableInterceptor.Current.resolve_initial_references("PICurrent");
             org.omg.CORBA.Any anyName = current.get_slot(.....);
             String name = anyName.extract_string();
             ..println("printSAS for user " + name);
         } catch (Exception e) {
             ..println("printSAS Error: " + e);
         }
     }
 
     public KerberosServer(String[] args) {
         try {
             // initialize the ORB and POA.
              = ORB.init(argsnull);
             POA rootPOA = (POA.resolve_initial_references("RootPOA");
             org.omg.CORBA.Policy [] policies = new org.omg.CORBA.Policy[3];
             policies[0] = rootPOA.create_id_assignment_policy(.);
             policies[1] = rootPOA.create_lifespan_policy(.);
             Any sasAny = .create_any();
             SASPolicyValuesHelper.insertsasAnynew SASPolicyValues(..true) );
             policies[2] = .create_policy(.sasAny);
             POA securePOA = rootPOA.create_POA("SecurePOA"rootPOA.the_POAManager(), policies);
             rootPOA.the_POAManager().activate();
 
             // create object and write out IOR
             securePOA.activate_object_with_id("SecureObject".getBytes(), this);
             org.omg.CORBA.Object demo = securePOA.servant_to_reference(this);
             PrintWriter pw = new PrintWriter(new FileWriter(args[0]));
             pw.println(.object_to_string(demo));
             pw.flush();
             pw.close();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
     public static void main(final String[] args) {
         if (args.length != 2) {
             ..println("Usage: java demo.sas.KerberosServer <ior_file> <password>");
             System.exit(-1);
         }
 
         // login - with Kerberos
         LoginContext loginContext = null;
         try {
             JaasTxtCalbackHandler cbHandler = new JaasTxtCalbackHandler();
             cbHandler.setMyPassword(args[1].toCharArray());
             loginContext = new LoginContext("KerberosService"cbHandler);
            loginContext.login();
        } catch (LoginException le) {
            ..println("Login error: " + le);
            System.exit(1);
        }
         = loginContext.getSubject();
        ..println("Found principal " + .getName());
        // run in privileged mode
        final String[] finalArgs = args;
        try {
            Subject.doAs(new PrivilegedAction() {
                public Object run() {
                    try {
                        // create application
                        KerberosServer app = new KerberosServer(finalArgs);
                        while ( args.length == 3 || ! app.getShutdown ())
                        {
                            Thread.sleep(1000);
                        }
                        app.orb.shutdown(true);
                    } catch (Exception e) {
                        ..println("Error running program: "+e);
                    }
                    return null;
                }
            });
        } catch (Exception e) {
            ..println("Error running privileged: "+e);
        }
    }
New to GrepCode? Check out our FAQ X