Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 45247 invoked from network); 16 Nov 2007 10:08:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Nov 2007 10:08:34 -0000 Received: (qmail 25768 invoked by uid 500); 16 Nov 2007 10:08:22 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 25688 invoked by uid 500); 16 Nov 2007 10:08:22 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 25660 invoked by uid 99); 16 Nov 2007 10:08:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Nov 2007 02:08:22 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Nov 2007 10:08:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C2C7E1A9832; Fri, 16 Nov 2007 02:08:13 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@harmony.apache.org From: pyang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071116100813.C2C7E1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 LdapContextImpl * * @param context - * @param env + * @param environment * @param dn * @throws InvalidNameException */ @@ -130,7 +137,14 @@ Hashtable 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)