From 29ca2f8049898c320a8135e56fad2e86d40f8f70 Mon Sep 17 00:00:00 2001
From: smaguin <smaguin@localhost>
Date: Tue, 24 Jun 2008 07:44:51 +0000
Subject: [PATCH] client supports starttls

---
 opendj-sdk/opends/tests/system-tests/scenario/singleServer/clients/secureSearch/src/Worker.java |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/opendj-sdk/opends/tests/system-tests/scenario/singleServer/clients/secureSearch/src/Worker.java b/opendj-sdk/opends/tests/system-tests/scenario/singleServer/clients/secureSearch/src/Worker.java
index 9f20d76..74b0963 100644
--- a/opendj-sdk/opends/tests/system-tests/scenario/singleServer/clients/secureSearch/src/Worker.java
+++ b/opendj-sdk/opends/tests/system-tests/scenario/singleServer/clients/secureSearch/src/Worker.java
@@ -32,10 +32,13 @@
 import javax.naming.directory.SearchResult;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.Attribute;
-import javax.naming.directory.DirContext;
+//import javax.naming.directory.DirContext;
 import javax.naming.Context;
-import javax.naming.directory.InitialDirContext;
-
+//import javax.naming.directory.InitialDirContext;
+import javax.naming.ldap.*;
+import javax.naming.ldap.StartTlsResponse;
+import javax.naming.ldap.StartTlsRequest;
+import javax.net.ssl.*;
 
 public class Worker extends Thread {
   
@@ -64,8 +67,9 @@
 
     try {
       
-      DirContext ctx = null;
-      
+     LdapContext ctx = null; 
+     StartTlsResponse tls = null;
+     
       // Set the properties 
      Hashtable envLdap = client.set_properties_LDAP();
       
@@ -88,7 +92,16 @@
          
         }
         // bind
-        ctx = new InitialDirContext(envLdap);
+        ctx = new InitialLdapContext(envLdap,null);
+   
+        if ( client.protocol.equals("starttls")) {
+          // Start TLS
+          tls = (StartTlsResponse) ctx.extendedOperation(new StartTlsRequest());
+          SSLSession sess = tls.negotiate();
+   
+          ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, client.authentication);
+          
+        }
         
         
         //String filter = "(objectclass=*)";
@@ -119,6 +132,9 @@
               
               client.inc_srchs_done();
             } else {
+              if ( client.protocol.equals("starttls")) {
+                tls.close();
+              }
               ctx.close();
               client.thread_go_to_sleep();
               break;

--
Gitblit v1.10.0