harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r595615 - in /harmony/enhanced/classlib/trunk/modules/jndi: make/exclude.common src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
Date Fri, 16 Nov 2007 10:08:12 GMT
Author: pyang
Date: Fri Nov 16 02:08:10 2007
New Revision: 595615

URL: http://svn.apache.org/viewvc?rev=595615&view=rev
Log:
Apply patch for HARMONY-5131([classlib][ldap]Do ldap bind operation whne LdapContextImpl initial)

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common?rev=595615&r1=595614&r2=595615&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/make/exclude.common Fri Nov 16 02:08:10 2007
@@ -1,2 +1,10 @@
 # not a test
 org/apache/harmony/jndi/provider/dns/TestMgr.java
+
+# Add this to exclude list with patch for HARMONY-5131
+# this test is broken after add ldap bind operation when initial
+# LdapContextImpl, because it's hard to simulate ldap server to response
+# bind request, mock is so complex that
+# LdapContextFactory.getInitialContext will be tested in scenario tests
+#
+org/apache/harmony/jndi/provider/ldap/LdapContextFactoryTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java?rev=595615&r1=595614&r2=595615&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
Fri Nov 16 02:08:10 2007
@@ -61,8 +61,10 @@
 import org.apache.harmony.jndi.internal.nls.Messages;
 import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
 import org.apache.harmony.jndi.internal.parser.LdapNameParser;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
 import org.apache.harmony.jndi.provider.ldap.parser.FilterParser;
 import org.apache.harmony.jndi.provider.ldap.parser.ParseException;
+import org.apache.harmony.jndi.provider.ldap.sasl.SaslBind;
 
 /**
  * This context implements LdapContext, it's main entry point of all JNDI ldap
@@ -94,6 +96,11 @@
      */
     private NameParser parser;
 
+    /**
+     * connection controls for this context
+     */
+    private Control[] connCtls;
+
     private static final Control NON_CRITICAL_MANAGE_REF_CONTROL = new ManageReferralControl(
             Control.NONCRITICAL);
 
@@ -107,7 +114,7 @@
      * construct a new inherit <code>LdapContextImpl</code>
      * 
      * @param context
-     * @param env
+     * @param environment
      * @param dn
      * @throws InvalidNameException
      */
@@ -130,7 +137,14 @@
             Hashtable<Object, Object> environment, String dn)
             throws NamingException {
         initial(client, environment, dn);
-        // TODO do ldap bind operation
+
+        try {
+            doBindOperation(connCtls);
+        } catch (IOException e) {
+            CommunicationException ex = new CommunicationException();
+            ex.setRootCause(e);
+            throw ex;
+        }
     }
 
     private void initial(LdapClient ldapClient,
@@ -145,6 +159,42 @@
 
         contextDn = new LdapName(dn);
         parser = new LdapNameParser(dn);
+    }
+
+    /**
+     * Perform a LDAP Bind operation.
+     * 
+     * @param env
+     * @throws IOException
+     * @throws IOException
+     * @throws NamingException
+     * @throws ParseException
+     */
+    private void doBindOperation(Control[] connCtsl) throws IOException,
+            NamingException {
+
+        SaslBind saslBind = new SaslBind();
+        LdapResult result = null;
+
+        SaslBind.AuthMech authMech = saslBind.valueAuthMech(env);
+        if (authMech == SaslBind.AuthMech.None) {
+            BindOp bind = new BindOp("", "", null, null);
+            client.doOperation(bind, connCtsl);
+            result = bind.getResult();
+        } else if (authMech == SaslBind.AuthMech.Simple) {
+            String principal = (String) env.get(Context.SECURITY_PRINCIPAL);
+            String credential = Utils.getString(env
+                    .get(Context.SECURITY_CREDENTIALS));
+            BindOp bind = new BindOp(principal, credential, null, null);
+            client.doOperation(bind, connCtsl);
+            result = bind.getResult();
+        } else if (authMech == SaslBind.AuthMech.SASL) {
+            result = saslBind.doSaslBindOperation(env, client, connCtsl);
+        }
+
+        if (LdapUtils.getExceptionFromResult(result) != null) {
+            throw LdapUtils.getExceptionFromResult(result);
+        }
     }
 
     public ExtendedResponse extendedOperation(ExtendedRequest request)



Mime
View raw message