You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2014/10/10 17:09:36 UTC

svn commit: r1630920 [1/2] - in /directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client: api/ template/ template/exception/

Author: elecharny
Date: Fri Oct 10 15:09:35 2014
New Revision: 1630920

URL: http://svn.apache.org/r1630920
Log:
replaced windows EOL by linux EOL

Removed:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/exception/PasswordException.java
Modified:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionFactory.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ConnectionCallback.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/EntryMapper.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/MemoryClearingBuffer.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ModelFactory.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ModelFactoryImpl.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordPolicyOperation.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordPolicyResponder.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordPolicyResponderImpl.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordWarning.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordWarningImpl.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/RequestBuilder.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/exception/LdapRequestUnsuccessfulException.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/exception/LdapRuntimeException.java

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionFactory.java?rev=1630920&r1=1630919&r2=1630920&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionFactory.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionFactory.java Fri Oct 10 15:09:35 2014
@@ -1,97 +1,97 @@
-/*
- *   Licensed to the Apache Software Foundation (ASF) under one
- *   or more contributor license agreements.  See the NOTICE file
- *   distributed with this work for additional information
- *   regarding copyright ownership.  The ASF licenses this file
- *   to you under the Apache License, Version 2.0 (the
- *   "License"); you may not use this file except in compliance
- *   with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing,
- *   software distributed under the License is distributed on an
- *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *   KIND, either express or implied.  See the License for the
- *   specific language governing permissions and limitations
- *   under the License.
- *
- */
-package org.apache.directory.ldap.client.api;
-
-
-import org.apache.directory.api.ldap.codec.api.LdapApiService;
-import org.apache.directory.api.ldap.model.exception.LdapException;
-
-
-/**
- * A factory that creates {@link LdapConnection} objects using the provided
- * {@link LdapConnectionConfig}.
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public interface LdapConnectionFactory
-{
-    /**
-     * Issues a bind request on the supplied connection using the name and
-     * credentials from the LdapConnectionConfg supplied to the constructor.
-     * Returns the connection supplied for chaining.
-     * 
-     * @param connection
-     *            The connection to bind with the configuration credentials.
-     * @return The connection supplied.
-     * @throws LdapException
-     *             If the bind fails.
-     */
-    public abstract LdapConnection bindConnection( LdapConnection connection ) throws LdapException;
-
-
-    /**
-     * Applies the following configuration settings from the
-     * LdapConnectionConfig to the supplied connection:
-     * <ul>
-     * <li>timeOut</li>
-     * <li>binaryAttributeDetector</li>
-     * </ul>
-     * This method is called by newLdapConnection, so there is no need to call
-     * this on a newly created connection. This should be used for pooling where
-     * the returned connection could have been modified by the borrower in order
-     * to ensure the next borrower gets a correctly configured connection.
-     * Returns the supplied connection for chaining.
-     * 
-     * @param connection
-     *            The connection to configure
-     * @return The supplied connection.
-     */
-    public abstract LdapConnection configureConnection( LdapConnection connection );
-
-
-    /**
-     * Returns the LdapApiService instance used by this factory.
-     *
-     * @return The LdapApiService instance used by this factory
-     */
-    public LdapApiService getLdapApiService();
-
-
-    /**
-     * Returns a newly created, configured, and authenticated connection. This
-     * method should be used by a connection pool to manufacture the pooled
-     * instances.
-     * 
-     * @return A newly created, configured, and authenticated LdapConnection.
-     * @throws LdapException
-     */
-    public abstract LdapConnection newLdapConnection() throws LdapException;
-    
-    
-    /**
-     * Returns a newly created connection, that has not been bound (bind) that
-     * otherwise respects LdapConnectionConfig supplied to the constructor. This
-     * is useful for authentication purposes where the consumer will use a bind
-     * operation.
-     * 
-     * @return A newly created and configured LdapConnection.
-     */
-    public abstract LdapConnection newUnboundLdapConnection();
-}
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.ldap.client.api;
+
+
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+
+
+/**
+ * A factory that creates {@link LdapConnection} objects using the provided
+ * {@link LdapConnectionConfig}.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface LdapConnectionFactory
+{
+    /**
+     * Issues a bind request on the supplied connection using the name and
+     * credentials from the LdapConnectionConfg supplied to the constructor.
+     * Returns the connection supplied for chaining.
+     * 
+     * @param connection
+     *            The connection to bind with the configuration credentials.
+     * @return The connection supplied.
+     * @throws LdapException
+     *             If the bind fails.
+     */
+    public abstract LdapConnection bindConnection( LdapConnection connection ) throws LdapException;
+
+
+    /**
+     * Applies the following configuration settings from the
+     * LdapConnectionConfig to the supplied connection:
+     * <ul>
+     * <li>timeOut</li>
+     * <li>binaryAttributeDetector</li>
+     * </ul>
+     * This method is called by newLdapConnection, so there is no need to call
+     * this on a newly created connection. This should be used for pooling where
+     * the returned connection could have been modified by the borrower in order
+     * to ensure the next borrower gets a correctly configured connection.
+     * Returns the supplied connection for chaining.
+     * 
+     * @param connection
+     *            The connection to configure
+     * @return The supplied connection.
+     */
+    public abstract LdapConnection configureConnection( LdapConnection connection );
+
+
+    /**
+     * Returns the LdapApiService instance used by this factory.
+     *
+     * @return The LdapApiService instance used by this factory
+     */
+    public LdapApiService getLdapApiService();
+
+
+    /**
+     * Returns a newly created, configured, and authenticated connection. This
+     * method should be used by a connection pool to manufacture the pooled
+     * instances.
+     * 
+     * @return A newly created, configured, and authenticated LdapConnection.
+     * @throws LdapException
+     */
+    public abstract LdapConnection newLdapConnection() throws LdapException;
+    
+    
+    /**
+     * Returns a newly created connection, that has not been bound (bind) that
+     * otherwise respects LdapConnectionConfig supplied to the constructor. This
+     * is useful for authentication purposes where the consumer will use a bind
+     * operation.
+     * 
+     * @return A newly created and configured LdapConnection.
+     */
+    public abstract LdapConnection newUnboundLdapConnection();
+}

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java?rev=1630920&r1=1630919&r2=1630920&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java Fri Oct 10 15:09:35 2014
@@ -1,139 +1,139 @@
-/*
- *   Licensed to the Apache Software Foundation (ASF) under one
- *   or more contributor license agreements.  See the NOTICE file
- *   distributed with this work for additional information
- *   regarding copyright ownership.  The ASF licenses this file
- *   to you under the Apache License, Version 2.0 (the
- *   "License"); you may not use this file except in compliance
- *   with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing,
- *   software distributed under the License is distributed on an
- *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *   KIND, either express or implied.  See the License for the
- *   specific language governing permissions and limitations
- *   under the License.
- *
- */
-package org.apache.directory.ldap.client.template;
-
-
-import org.apache.directory.api.ldap.codec.api.LdapApiService;
-import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy;
-import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator;
-import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.api.ldap.model.message.Control;
-import org.apache.directory.api.ldap.model.message.Response;
-import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
-import org.apache.directory.api.ldap.model.message.ResultResponse;
-import org.apache.directory.ldap.client.template.exception.PasswordException;
-
-
-/**
- * A base, abstract, implementation of <code>PasswordPolicyResponder</code>.  
- * Extend this class and override {@link #success(PasswordPolicy)}, 
- * {@link #fail(ResultResponse, PasswordPolicy, ResultCodeEnum)}, or
- * {@link #exception(LdapException)}.  If that does not offer enough
- * flexibility, you must implement PasswordPolicyResponder yourself.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-abstract public class AbstractPasswordPolicyResponder implements PasswordPolicyResponder
-{
-    private final PasswordPolicyDecorator passwordPolicyRequestControl;
-
-
-    protected AbstractPasswordPolicyResponder( LdapApiService ldapApiService )
-    {
-        this.passwordPolicyRequestControl = new PasswordPolicyDecorator(
-            ldapApiService );
-    }
-    
-    
-    /**
-     * Translates an <code>LdapException</code> to a 
-     * <code>PasswordException</code> to be thrown when 
-     * {@link #process(PasswordPolicyOperation)} fails.
-     * 
-     * @param e
-     * @return
-     */
-    protected PasswordException exception( LdapException e )
-    {
-        return new PasswordException().setLdapException( e );
-    }
-    
-    
-    /**
-     * Returns an exception to be thrown in the case of a non SUCCESS 
-     * <code>resultCode</code>.
-     * 
-     * @param resultResponse
-     * @param passwordPolicy
-     * @param resultCode
-     * @return
-     */
-    protected PasswordException fail( ResultResponse resultResponse, 
-            PasswordPolicy passwordPolicy, ResultCodeEnum resultCode )
-    {
-        PasswordException exception = new PasswordException();
-        exception.setResultCode( resultCode );
-        if ( passwordPolicy != null
-            && passwordPolicy.getResponse() != null
-            && passwordPolicy.getResponse().getPasswordPolicyError() != null )
-        {
-            exception.setPasswordPolicyError( passwordPolicy.getResponse().getPasswordPolicyError() );
-        }
-        return exception;
-    }
-
-
-    private PasswordPolicy getPasswordPolicy( Response response )
-    {
-        Control control = response.getControls().get( passwordPolicyRequestControl.getOid() );
-        return control == null
-            ? null
-            : ( ( PasswordPolicyDecorator ) control ).getDecorated();
-    }
-
-
-    @Override
-    final public PasswordWarning process( PasswordPolicyOperation operation )
-        throws PasswordException
-    {
-        try
-        {
-            ResultResponse response = operation.process();
-            PasswordPolicy passwordPolicy = getPasswordPolicy( response );
-            ResultCodeEnum resultCode = response.getLdapResult().getResultCode();
-            if ( resultCode == ResultCodeEnum.SUCCESS )
-            {
-                return success( passwordPolicy );
-            }
-            else
-            {
-                throw fail( response, passwordPolicy, resultCode );
-            }
-        }
-        catch ( LdapException e )
-        {
-            throw new PasswordException().setLdapException( e );
-        }
-    }
-    
-    /**
-     * Returns a <code>PasswordWarning</code>, or <code>null</code> if no 
-     * warnings were present in the supplied <code>passwordPolicy</code>.
-     * 
-     * @param passwordPolicy
-     * @return
-     */
-    protected PasswordWarning success( PasswordPolicy passwordPolicy ) 
-    {
-        return passwordPolicy == null
-                ? null
-                : PasswordWarningImpl.newWarning( passwordPolicy );
-    }
-}
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.ldap.client.template;
+
+
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy;
+import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.message.Control;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.api.ldap.model.message.ResultResponse;
+import org.apache.directory.ldap.client.template.exception.PasswordException;
+
+
+/**
+ * A base, abstract, implementation of <code>PasswordPolicyResponder</code>.  
+ * Extend this class and override {@link #success(PasswordPolicy)}, 
+ * {@link #fail(ResultResponse, PasswordPolicy, ResultCodeEnum)}, or
+ * {@link #exception(LdapException)}.  If that does not offer enough
+ * flexibility, you must implement PasswordPolicyResponder yourself.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+abstract public class AbstractPasswordPolicyResponder implements PasswordPolicyResponder
+{
+    private final PasswordPolicyDecorator passwordPolicyRequestControl;
+
+
+    protected AbstractPasswordPolicyResponder( LdapApiService ldapApiService )
+    {
+        this.passwordPolicyRequestControl = new PasswordPolicyDecorator(
+            ldapApiService );
+    }
+    
+    
+    /**
+     * Translates an <code>LdapException</code> to a 
+     * <code>PasswordException</code> to be thrown when 
+     * {@link #process(PasswordPolicyOperation)} fails.
+     * 
+     * @param e
+     * @return
+     */
+    protected PasswordException exception( LdapException e )
+    {
+        return new PasswordException().setLdapException( e );
+    }
+    
+    
+    /**
+     * Returns an exception to be thrown in the case of a non SUCCESS 
+     * <code>resultCode</code>.
+     * 
+     * @param resultResponse
+     * @param passwordPolicy
+     * @param resultCode
+     * @return
+     */
+    protected PasswordException fail( ResultResponse resultResponse, 
+            PasswordPolicy passwordPolicy, ResultCodeEnum resultCode )
+    {
+        PasswordException exception = new PasswordException();
+        exception.setResultCode( resultCode );
+        if ( passwordPolicy != null
+            && passwordPolicy.getResponse() != null
+            && passwordPolicy.getResponse().getPasswordPolicyError() != null )
+        {
+            exception.setPasswordPolicyError( passwordPolicy.getResponse().getPasswordPolicyError() );
+        }
+        return exception;
+    }
+
+
+    private PasswordPolicy getPasswordPolicy( Response response )
+    {
+        Control control = response.getControls().get( passwordPolicyRequestControl.getOid() );
+        return control == null
+            ? null
+            : ( ( PasswordPolicyDecorator ) control ).getDecorated();
+    }
+
+
+    @Override
+    final public PasswordWarning process( PasswordPolicyOperation operation )
+        throws PasswordException
+    {
+        try
+        {
+            ResultResponse response = operation.process();
+            PasswordPolicy passwordPolicy = getPasswordPolicy( response );
+            ResultCodeEnum resultCode = response.getLdapResult().getResultCode();
+            if ( resultCode == ResultCodeEnum.SUCCESS )
+            {
+                return success( passwordPolicy );
+            }
+            else
+            {
+                throw fail( response, passwordPolicy, resultCode );
+            }
+        }
+        catch ( LdapException e )
+        {
+            throw new PasswordException().setLdapException( e );
+        }
+    }
+    
+    /**
+     * Returns a <code>PasswordWarning</code>, or <code>null</code> if no 
+     * warnings were present in the supplied <code>passwordPolicy</code>.
+     * 
+     * @param passwordPolicy
+     * @return
+     */
+    protected PasswordWarning success( PasswordPolicy passwordPolicy ) 
+    {
+        return passwordPolicy == null
+                ? null
+                : PasswordWarningImpl.newWarning( passwordPolicy );
+    }
+}

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ConnectionCallback.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ConnectionCallback.java?rev=1630920&r1=1630919&r2=1630920&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ConnectionCallback.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ConnectionCallback.java Fri Oct 10 15:09:35 2014
@@ -1,41 +1,41 @@
-/*
- *   Licensed to the Apache Software Foundation (ASF) under one
- *   or more contributor license agreements.  See the NOTICE file
- *   distributed with this work for additional information
- *   regarding copyright ownership.  The ASF licenses this file
- *   to you under the Apache License, Version 2.0 (the
- *   "License"); you may not use this file except in compliance
- *   with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing,
- *   software distributed under the License is distributed on an
- *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *   KIND, either express or implied.  See the License for the
- *   specific language governing permissions and limitations
- *   under the License.
- *
- */
-package org.apache.directory.ldap.client.template;
-
-import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.ldap.client.api.LdapConnection;
-
-/**
- * A callback for running code against a managed {@link LdapConnection}.
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public interface ConnectionCallback<T>
-{
-    /**
-     * Provides a managed connection to the implementation of this method.
-     * The implementation is not responsible for open/close or borrow/return.
-     *
-     * @param connection The connection supplied to the implementation.
-     * @return Anything you want
-     * @throws LdapException If you want to
-     */
-    public T doWithConnection( LdapConnection connection ) throws LdapException;
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.ldap.client.template;
+
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.ldap.client.api.LdapConnection;
+
+/**
+ * A callback for running code against a managed {@link LdapConnection}.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface ConnectionCallback<T>
+{
+    /**
+     * Provides a managed connection to the implementation of this method.
+     * The implementation is not responsible for open/close or borrow/return.
+     *
+     * @param connection The connection supplied to the implementation.
+     * @return Anything you want
+     * @throws LdapException If you want to
+     */
+    public T doWithConnection( LdapConnection connection ) throws LdapException;
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/EntryMapper.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/EntryMapper.java?rev=1630920&r1=1630919&r2=1630920&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/EntryMapper.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/EntryMapper.java Fri Oct 10 15:09:35 2014
@@ -1,40 +1,40 @@
-/*
- *   Licensed to the Apache Software Foundation (ASF) under one
- *   or more contributor license agreements.  See the NOTICE file
- *   distributed with this work for additional information
- *   regarding copyright ownership.  The ASF licenses this file
- *   to you under the Apache License, Version 2.0 (the
- *   "License"); you may not use this file except in compliance
- *   with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing,
- *   software distributed under the License is distributed on an
- *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *   KIND, either express or implied.  See the License for the
- *   specific language governing permissions and limitations
- *   under the License.
- *
- */
-package org.apache.directory.ldap.client.template;
-
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.exception.LdapException;
-
-/**
- * A callback for processing entries from a search result.
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public interface EntryMapper<T>
-{
-    /**
-     * Will be called once for each entry in the search result.
-     *
-     * @param entry An entry from the search result
-     * @return A object modeling the entry
-     * @throws LdapException If something goes wrong
-     */
-    public T map( Entry entry ) throws LdapException;
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.ldap.client.template;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+
+/**
+ * A callback for processing entries from a search result.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface EntryMapper<T>
+{
+    /**
+     * Will be called once for each entry in the search result.
+     *
+     * @param entry An entry from the search result
+     * @return A object modeling the entry
+     * @throws LdapException If something goes wrong
+     */
+    public T map( Entry entry ) throws LdapException;
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java?rev=1630920&r1=1630919&r2=1630920&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java Fri Oct 10 15:09:35 2014
@@ -1,454 +1,454 @@
-/*
- *   Licensed to the Apache Software Foundation (ASF) under one
- *   or more contributor license agreements.  See the NOTICE file
- *   distributed with this work for additional information
- *   regarding copyright ownership.  The ASF licenses this file
- *   to you under the Apache License, Version 2.0 (the
- *   "License"); you may not use this file except in compliance
- *   with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing,
- *   software distributed under the License is distributed on an
- *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *   KIND, either express or implied.  See the License for the
- *   specific language governing permissions and limitations
- *   under the License.
- *
- */
-package org.apache.directory.ldap.client.template;
-
-
-import java.util.List;
-
-import org.apache.directory.api.ldap.model.entry.Attribute;
-import org.apache.directory.api.ldap.model.message.AddRequest;
-import org.apache.directory.api.ldap.model.message.AddResponse;
-import org.apache.directory.api.ldap.model.message.DeleteRequest;
-import org.apache.directory.api.ldap.model.message.DeleteResponse;
-import org.apache.directory.api.ldap.model.message.ModifyRequest;
-import org.apache.directory.api.ldap.model.message.ModifyResponse;
-import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
-import org.apache.directory.api.ldap.model.message.ResultResponse;
-import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.ldap.client.template.exception.LdapRequestUnsuccessfulException;
-import org.apache.directory.ldap.client.template.exception.PasswordException;
-
-
-/**
- * Specifies the set of operations available on
- * {@link org.apache.directory.ldap.client.template.LdapConnectionTemplate
- * LdapConnectionTemplate}.  This interface can be useful for unit testing
- * in order to stub out methods.
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public interface LdapConnectionOperations
-{
-
-    /**
-     * Adds an entry specified by an AddRequest to the LDAP server.
-     *
-     * @param addRequest The request
-     * @return An AddResponse
-     */
-    public abstract AddResponse add( AddRequest addRequest );
-
-
-    /**
-     * Adds an entry specified by a Dn and an array of Attribute's to the LDAP
-     * server.
-     *
-     * @param dn The distinguished name of the new entry
-     * @param attributes The attributes of the new entry
-     * @return An AddResponse
-     */
-    public abstract AddResponse add( Dn dn, Attribute... attributes );
-
-
-    /**
-     * Adds an entry specified by a Dn, to be filled out by a RequestBuilder,
-     * to the LDAP server.
-     *
-     * @param dn The distinguished name of the new entry
-     * @param requestBuilder The request builder
-     * @return An AddResponse
-     */
-    public abstract AddResponse add( Dn dn, RequestBuilder<AddRequest> requestBuilder );
-
-
-    /**
-     * Attempts to authenticate the supplied credentials against the first 
-     * entry found matching the search criteria.  If authentication fails, 
-     * a PasswordException is thrown.  If successful, the response is 
-     * checked for warnings, and if present, a PasswordWarning is returned.
-     * Otherwise, null is returned.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param password
-     * @return
-     * @throws PasswordException
-     * @see {@link #authenticate(Dn, char[])}
-     * @see {@link #searchFirst(String, String, SearchScope, EntryMapper)}
-     */
-    public PasswordWarning authenticate( String baseDn, String filter, SearchScope scope, char[] password ) throws PasswordException;
-
-
-    /**
-     * Attempts to authenticate the supplied credentials against the first 
-     * entry found matching the search criteria.  If authentication fails, 
-     * a PasswordException is thrown.  If successful, the response is 
-     * checked for warnings, and if present, a PasswordWarning is returned.
-     * Otherwise, null is returned.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param password
-     * @return
-     * @throws PasswordException
-     * @see {@link #authenticate(Dn, char[])}
-     * @see {@link #searchFirst(Dn, String, SearchScope, EntryMapper)}
-     */
-    public PasswordWarning authenticate( Dn baseDn, String filter, SearchScope scope, char[] password ) throws PasswordException;
-    
-    
-    /**
-     * Attempts to authenticate the supplied credentials against the first 
-     * entry found matching the search criteria.  If authentication fails, 
-     * a PasswordException is thrown.  If successful, the response is 
-     * checked for warnings, and if present, a PasswordWarning is returned.
-     * Otherwise, null is returned.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param password
-     * @return
-     * @throws PasswordException
-     * @see {@link #authenticate(Dn, char[])}
-     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
-     */
-    public PasswordWarning authenticate( SearchRequest searchRequest, char[] password ) throws PasswordException;
-
-
-    /**
-     * Attempts to authenticate the supplied credentials.  If authentication
-     * fails, a PasswordException is thrown.  If successful, the response is 
-     * checked for warnings, and if present, a PasswordWarning is returned.
-     * Otherwise, null is returned.
-     *
-     * @param userDn The distinguished name of the user
-     * @param password The password
-     * @return A PasswordWarning or null
-     * @throws PasswordException If authentication fails
-     */
-    public abstract PasswordWarning authenticate( Dn userDn, char[] password ) throws PasswordException;
-
-
-    /**
-     * Deletes an entry specified by a DeleteRequest from the LDAP server.
-     *
-     * @param deleteRequest The request
-     * @return A DeleteResponse
-     */
-    public abstract DeleteResponse delete( DeleteRequest deleteRequest );
-
-
-    /**
-     * Deletes an entry specified by Dn from the LDAP server.
-     *
-     * @param dn The distinguished name of the entry
-     * @return A DeleteResponse
-     */
-    public abstract DeleteResponse delete( Dn dn );
-
-
-    /**
-     * Deletes an entry specified by Dn, and whose request is configured
-     * by a RequestBuilder, from the LDAP server.
-     *
-     * @param dn The distinguished name of the entry
-     * @param requestBuilder The RequestBuilder
-     * @return A DeleteResponse
-     */
-    public abstract DeleteResponse delete( Dn dn, RequestBuilder<DeleteRequest> requestBuilder );
-
-
-    /**
-     * Executes the <code>connectionCallback</code>, supplying it a managed
-     * connection.
-     *
-     * @param connectionCallback The callback
-     * @return Whatever the callback returns
-     */
-    public abstract <T> T execute( ConnectionCallback<T> connectionCallback );
-
-
-    /**
-     * Performs a lookup, and supplies the matching entry to the 
-     * <code>entryMapper</code>.
-     *
-     * @param dn The distinguished name of the entry
-     * @param entryMapper The mapper from entry to model object
-     * @return Whatever the <code>entryMapper</code> returns
-     */
-    public abstract <T> T lookup( Dn dn, EntryMapper<T> entryMapper );
-
-
-    /**
-     * Performs a lookup, requesting <code>attributes</code>, and supplies 
-     * the matching entry to the <code>entryMapper</code>.
-     *
-     * @param dn The distinguished name of the entry
-     * @param attributes The attributes to be fetched
-     * @param entryMapper The mapper from entry to model object
-     * @return Whatever the <code>entryMapper</code> returns
-     */
-    public abstract <T> T lookup( Dn dn, String[] attributes, EntryMapper<T> entryMapper );
-
-
-    /**
-     * Modifies the password for <code>userDn</code> to
-     * <code>newPassword</code> using the admin account.
-     *
-     * @param userDn
-     * @param newPassword
-     * @throws PasswordException
-     * @see {@link #modifyPassword(Dn, char[], char[], boolean)}
-     */
-    public void modifyPassword( Dn userDn, char[] newPassword ) 
-        throws PasswordException;
-
-
-    /**
-     * Modifies the password for <code>userDn</code> from 
-     * <code>oldPassword</code> to <code>newPassword</code>.
-     *
-     * @param userDn
-     * @param oldPassword
-     * @param newPassword
-     * @throws PasswordException
-     * @see {@link #modifyPassword(Dn, char[], char[], boolean)}
-     */
-    public void modifyPassword( Dn userDn, char[] oldPassword,
-        char[] newPassword ) throws PasswordException;
-
-
-    /**
-     * Modifies the password for <code>userDn</code> from 
-     * <code>oldPassword</code> to <code>newPassword</code>, optionally using
-     * an admin account.  If <code>asAdmin</code> is true, then the operation
-     * is performed in admin context which means <code>oldPassword</code> is
-     * may be <code>null</code>.
-     *
-     * @param userDn The distinguished name of the user
-     * @param oldPassword The users old password (optional if asAdmin is true)
-     * @param newPassword The users new password
-     * @param asAdmin If true, execute in admin context
-     * @throws PasswordException If the password modification fails
-     */
-    public abstract void modifyPassword( Dn userDn, char[] oldPassword, char[] newPassword,
-        boolean asAdmin ) throws PasswordException;
-
-
-    /**
-     * Modifies an entry specified by a ModifyRequest on the LDAP server.
-     *
-     * @param modifyRequest The request
-     * @return A ModifyResponse
-     */
-    public abstract ModifyResponse modify( ModifyRequest modifyRequest );
-
-
-    /**
-     * Modifies an entry specified by Dn, and whose request is configured
-     * by a RequestBuilder, on the LDAP server.
-     *
-     * @param dn The distinguished name of the entry
-     * @param requestBuilder The RequestBuilder
-     * @return A ModifyResponse
-     */
-    public abstract ModifyResponse modify( Dn dn, RequestBuilder<ModifyRequest> requestBuilder );
-
-    
-    /**
-     * Checks the supplied response for its result code, and if not 
-     * {@link ResultCodeEnum#SUCCESS}, an exception is thrown. This method is 
-     * intened to be used inline:
-     * 
-     * <pre>
-     * template.responseOrException( template.delete( dn ) );
-     * </pre>
-     *
-     * @param response The response to check for success
-     * @return The supplied <code>response</code>
-     * @throws LdapRequestUnsuccessfulException If the response is not
-     * {@link ResultCodeEnum#SUCCESS}
-     */
-    public abstract <T extends ResultResponse> T responseOrException( T response );
-
-
-    /**
-     * Searches for the entries matching the supplied criteria, feeding the 
-     * result into the <code>entryMapper</code>.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param entryMapper
-     * @return The mapped entries
-     * @see {@link #search(SearchRequest, EntryMapper)}
-     */
-    public abstract <T> List<T> search( String baseDn, String filter, SearchScope scope,
-        EntryMapper<T> entryMapper );
-
-
-    /**
-     * Searches for the entries matching the supplied criteria, feeding the 
-     * result into the <code>entryMapper</code>.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param entryMapper
-     * @return The mapped entries
-     * @see {@link #search(SearchRequest, EntryMapper)}
-     */
-    public abstract <T> List<T> search( Dn baseDn, String filter, SearchScope scope,
-        EntryMapper<T> entryMapper );
-
-
-    /**
-     * Searches for the entries matching the supplied criteria, feeding the 
-     * result into the <code>entryMapper</code>, querying only the requested 
-     * attributes.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param attributes
-     * @param entryMapper
-     * @return The mapped entries
-     * @see {@link #search(SearchRequest, EntryMapper)}
-     */
-    public abstract <T> List<T> search( String baseDn, String filter, SearchScope scope,
-        String[] attributes, EntryMapper<T> entryMapper );
-
-
-    /**
-     * Searches for the entries matching the supplied criteria, feeding the 
-     * result into the <code>entryMapper</code>, querying only the requested 
-     * attributes.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param attributes
-     * @param entryMapper
-     * @return The mapped entries
-     * @see {@link #search(SearchRequest, EntryMapper)}
-     */
-    public abstract <T> List<T> search( Dn baseDn, String filter, SearchScope scope,
-        String[] attributes, EntryMapper<T> entryMapper );
-
-
-    /**
-     * Searches for the entries matching the supplied 
-     * <code>searchRequest</code>, feeding the result into the 
-     * <code>entryMapper</code>.
-     *
-     * @param searchRequest The search request
-     * @param entryMapper The mapper
-     * @return The mapped entries
-     */
-    public abstract <T> List<T> search( SearchRequest searchRequest,
-        EntryMapper<T> entryMapper );
-    
-    
-    /**
-     * Searches for the first entry matching the supplied criteria, feeding the 
-     * result into the <code>entryMapper</code>.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param entryMapper
-     * @return The mapped entries
-     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
-     */
-    public abstract <T> T searchFirst( String baseDn, String filter, SearchScope scope,
-        EntryMapper<T> entryMapper );
-
-
-    /**
-     * Searches for the first entry matching the supplied criteria, feeding the 
-     * result into the <code>entryMapper</code>.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param entryMapper
-     * @return The mapped entries
-     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
-     */
-    public abstract <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
-        EntryMapper<T> entryMapper );
-
-
-    /**
-     * Searches for the first entry matching the supplied criteria, feeding the 
-     * result into the <code>entryMapper</code>, querying only the requested 
-     * attributes.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param attributes
-     * @param entryMapper
-     * @return The mapped entries
-     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
-     */
-    public abstract <T> T searchFirst( String baseDn, String filter, SearchScope scope,
-        String[] attributes, EntryMapper<T> entryMapper );
-
-
-    /**
-     * Searches for the first entry matching the supplied criteria, feeding the 
-     * result into the <code>entryMapper</code>, querying only the requested 
-     * attributes.
-     *
-     * @param baseDn
-     * @param filter
-     * @param scope
-     * @param attributes
-     * @param entryMapper
-     * @return The mapped entries
-     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
-     */
-    public abstract <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
-        String[] attributes, EntryMapper<T> entryMapper );
-    
-
-    /**
-     * Searches for the first entry matching the supplied 
-     * <code>searchRequest</code>, feeding the result into the 
-     * <code>entryMapper</code>. This is basically the same as 
-     * {@link #search(SearchRequest, EntryMapper)}, but is optimized by
-     * modifying the <code>searchRequest</code> to set its size limit to 1.
-     * The <code>searchRequest</code> is returned to its original size limit
-     * before this method returns (or throws an exception).
-     *
-     * @param searchRequest The search request
-     * @param entryMapper The mapper
-     * @return The mapped entry
-     */
-    public abstract <T> T searchFirst( SearchRequest searchRequest,
-        EntryMapper<T> entryMapper );
-
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.ldap.client.template;
+
+
+import java.util.List;
+
+import org.apache.directory.api.ldap.model.entry.Attribute;
+import org.apache.directory.api.ldap.model.message.AddRequest;
+import org.apache.directory.api.ldap.model.message.AddResponse;
+import org.apache.directory.api.ldap.model.message.DeleteRequest;
+import org.apache.directory.api.ldap.model.message.DeleteResponse;
+import org.apache.directory.api.ldap.model.message.ModifyRequest;
+import org.apache.directory.api.ldap.model.message.ModifyResponse;
+import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.api.ldap.model.message.ResultResponse;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.template.exception.LdapRequestUnsuccessfulException;
+import org.apache.directory.ldap.client.template.exception.PasswordException;
+
+
+/**
+ * Specifies the set of operations available on
+ * {@link org.apache.directory.ldap.client.template.LdapConnectionTemplate
+ * LdapConnectionTemplate}.  This interface can be useful for unit testing
+ * in order to stub out methods.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface LdapConnectionOperations
+{
+
+    /**
+     * Adds an entry specified by an AddRequest to the LDAP server.
+     *
+     * @param addRequest The request
+     * @return An AddResponse
+     */
+    public abstract AddResponse add( AddRequest addRequest );
+
+
+    /**
+     * Adds an entry specified by a Dn and an array of Attribute's to the LDAP
+     * server.
+     *
+     * @param dn The distinguished name of the new entry
+     * @param attributes The attributes of the new entry
+     * @return An AddResponse
+     */
+    public abstract AddResponse add( Dn dn, Attribute... attributes );
+
+
+    /**
+     * Adds an entry specified by a Dn, to be filled out by a RequestBuilder,
+     * to the LDAP server.
+     *
+     * @param dn The distinguished name of the new entry
+     * @param requestBuilder The request builder
+     * @return An AddResponse
+     */
+    public abstract AddResponse add( Dn dn, RequestBuilder<AddRequest> requestBuilder );
+
+
+    /**
+     * Attempts to authenticate the supplied credentials against the first 
+     * entry found matching the search criteria.  If authentication fails, 
+     * a PasswordException is thrown.  If successful, the response is 
+     * checked for warnings, and if present, a PasswordWarning is returned.
+     * Otherwise, null is returned.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param password
+     * @return
+     * @throws PasswordException
+     * @see {@link #authenticate(Dn, char[])}
+     * @see {@link #searchFirst(String, String, SearchScope, EntryMapper)}
+     */
+    public PasswordWarning authenticate( String baseDn, String filter, SearchScope scope, char[] password ) throws PasswordException;
+
+
+    /**
+     * Attempts to authenticate the supplied credentials against the first 
+     * entry found matching the search criteria.  If authentication fails, 
+     * a PasswordException is thrown.  If successful, the response is 
+     * checked for warnings, and if present, a PasswordWarning is returned.
+     * Otherwise, null is returned.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param password
+     * @return
+     * @throws PasswordException
+     * @see {@link #authenticate(Dn, char[])}
+     * @see {@link #searchFirst(Dn, String, SearchScope, EntryMapper)}
+     */
+    public PasswordWarning authenticate( Dn baseDn, String filter, SearchScope scope, char[] password ) throws PasswordException;
+    
+    
+    /**
+     * Attempts to authenticate the supplied credentials against the first 
+     * entry found matching the search criteria.  If authentication fails, 
+     * a PasswordException is thrown.  If successful, the response is 
+     * checked for warnings, and if present, a PasswordWarning is returned.
+     * Otherwise, null is returned.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param password
+     * @return
+     * @throws PasswordException
+     * @see {@link #authenticate(Dn, char[])}
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public PasswordWarning authenticate( SearchRequest searchRequest, char[] password ) throws PasswordException;
+
+
+    /**
+     * Attempts to authenticate the supplied credentials.  If authentication
+     * fails, a PasswordException is thrown.  If successful, the response is 
+     * checked for warnings, and if present, a PasswordWarning is returned.
+     * Otherwise, null is returned.
+     *
+     * @param userDn The distinguished name of the user
+     * @param password The password
+     * @return A PasswordWarning or null
+     * @throws PasswordException If authentication fails
+     */
+    public abstract PasswordWarning authenticate( Dn userDn, char[] password ) throws PasswordException;
+
+
+    /**
+     * Deletes an entry specified by a DeleteRequest from the LDAP server.
+     *
+     * @param deleteRequest The request
+     * @return A DeleteResponse
+     */
+    public abstract DeleteResponse delete( DeleteRequest deleteRequest );
+
+
+    /**
+     * Deletes an entry specified by Dn from the LDAP server.
+     *
+     * @param dn The distinguished name of the entry
+     * @return A DeleteResponse
+     */
+    public abstract DeleteResponse delete( Dn dn );
+
+
+    /**
+     * Deletes an entry specified by Dn, and whose request is configured
+     * by a RequestBuilder, from the LDAP server.
+     *
+     * @param dn The distinguished name of the entry
+     * @param requestBuilder The RequestBuilder
+     * @return A DeleteResponse
+     */
+    public abstract DeleteResponse delete( Dn dn, RequestBuilder<DeleteRequest> requestBuilder );
+
+
+    /**
+     * Executes the <code>connectionCallback</code>, supplying it a managed
+     * connection.
+     *
+     * @param connectionCallback The callback
+     * @return Whatever the callback returns
+     */
+    public abstract <T> T execute( ConnectionCallback<T> connectionCallback );
+
+
+    /**
+     * Performs a lookup, and supplies the matching entry to the 
+     * <code>entryMapper</code>.
+     *
+     * @param dn The distinguished name of the entry
+     * @param entryMapper The mapper from entry to model object
+     * @return Whatever the <code>entryMapper</code> returns
+     */
+    public abstract <T> T lookup( Dn dn, EntryMapper<T> entryMapper );
+
+
+    /**
+     * Performs a lookup, requesting <code>attributes</code>, and supplies 
+     * the matching entry to the <code>entryMapper</code>.
+     *
+     * @param dn The distinguished name of the entry
+     * @param attributes The attributes to be fetched
+     * @param entryMapper The mapper from entry to model object
+     * @return Whatever the <code>entryMapper</code> returns
+     */
+    public abstract <T> T lookup( Dn dn, String[] attributes, EntryMapper<T> entryMapper );
+
+
+    /**
+     * Modifies the password for <code>userDn</code> to
+     * <code>newPassword</code> using the admin account.
+     *
+     * @param userDn
+     * @param newPassword
+     * @throws PasswordException
+     * @see {@link #modifyPassword(Dn, char[], char[], boolean)}
+     */
+    public void modifyPassword( Dn userDn, char[] newPassword ) 
+        throws PasswordException;
+
+
+    /**
+     * Modifies the password for <code>userDn</code> from 
+     * <code>oldPassword</code> to <code>newPassword</code>.
+     *
+     * @param userDn
+     * @param oldPassword
+     * @param newPassword
+     * @throws PasswordException
+     * @see {@link #modifyPassword(Dn, char[], char[], boolean)}
+     */
+    public void modifyPassword( Dn userDn, char[] oldPassword,
+        char[] newPassword ) throws PasswordException;
+
+
+    /**
+     * Modifies the password for <code>userDn</code> from 
+     * <code>oldPassword</code> to <code>newPassword</code>, optionally using
+     * an admin account.  If <code>asAdmin</code> is true, then the operation
+     * is performed in admin context which means <code>oldPassword</code> is
+     * may be <code>null</code>.
+     *
+     * @param userDn The distinguished name of the user
+     * @param oldPassword The users old password (optional if asAdmin is true)
+     * @param newPassword The users new password
+     * @param asAdmin If true, execute in admin context
+     * @throws PasswordException If the password modification fails
+     */
+    public abstract void modifyPassword( Dn userDn, char[] oldPassword, char[] newPassword,
+        boolean asAdmin ) throws PasswordException;
+
+
+    /**
+     * Modifies an entry specified by a ModifyRequest on the LDAP server.
+     *
+     * @param modifyRequest The request
+     * @return A ModifyResponse
+     */
+    public abstract ModifyResponse modify( ModifyRequest modifyRequest );
+
+
+    /**
+     * Modifies an entry specified by Dn, and whose request is configured
+     * by a RequestBuilder, on the LDAP server.
+     *
+     * @param dn The distinguished name of the entry
+     * @param requestBuilder The RequestBuilder
+     * @return A ModifyResponse
+     */
+    public abstract ModifyResponse modify( Dn dn, RequestBuilder<ModifyRequest> requestBuilder );
+
+    
+    /**
+     * Checks the supplied response for its result code, and if not 
+     * {@link ResultCodeEnum#SUCCESS}, an exception is thrown. This method is 
+     * intened to be used inline:
+     * 
+     * <pre>
+     * template.responseOrException( template.delete( dn ) );
+     * </pre>
+     *
+     * @param response The response to check for success
+     * @return The supplied <code>response</code>
+     * @throws LdapRequestUnsuccessfulException If the response is not
+     * {@link ResultCodeEnum#SUCCESS}
+     */
+    public abstract <T extends ResultResponse> T responseOrException( T response );
+
+
+    /**
+     * Searches for the entries matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #search(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> List<T> search( String baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the entries matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #search(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> List<T> search( Dn baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the entries matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>, querying only the requested 
+     * attributes.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param attributes
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #search(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> List<T> search( String baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the entries matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>, querying only the requested 
+     * attributes.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param attributes
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #search(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> List<T> search( Dn baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the entries matching the supplied 
+     * <code>searchRequest</code>, feeding the result into the 
+     * <code>entryMapper</code>.
+     *
+     * @param searchRequest The search request
+     * @param entryMapper The mapper
+     * @return The mapped entries
+     */
+    public abstract <T> List<T> search( SearchRequest searchRequest,
+        EntryMapper<T> entryMapper );
+    
+    
+    /**
+     * Searches for the first entry matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> T searchFirst( String baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the first entry matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the first entry matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>, querying only the requested 
+     * attributes.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param attributes
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> T searchFirst( String baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the first entry matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>, querying only the requested 
+     * attributes.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param attributes
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper );
+    
+
+    /**
+     * Searches for the first entry matching the supplied 
+     * <code>searchRequest</code>, feeding the result into the 
+     * <code>entryMapper</code>. This is basically the same as 
+     * {@link #search(SearchRequest, EntryMapper)}, but is optimized by
+     * modifying the <code>searchRequest</code> to set its size limit to 1.
+     * The <code>searchRequest</code> is returned to its original size limit
+     * before this method returns (or throws an exception).
+     *
+     * @param searchRequest The search request
+     * @param entryMapper The mapper
+     * @return The mapped entry
+     */
+    public abstract <T> T searchFirst( SearchRequest searchRequest,
+        EntryMapper<T> entryMapper );
+
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java?rev=1630920&r1=1630919&r2=1630920&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java Fri Oct 10 15:09:35 2014
@@ -20,7 +20,6 @@
 package org.apache.directory.ldap.client.template;
 
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -64,7 +63,8 @@ import org.slf4j.LoggerFactory;
 public class LdapConnectionTemplate implements LdapConnectionOperations, ModelFactory
 {
     private static Logger logger = LoggerFactory.getLogger( LdapConnectionTemplate.class );
-    private static final EntryMapper<Dn> dnEntryMapper = new EntryMapper<Dn>() {
+    private static final EntryMapper<Dn> dnEntryMapper = new EntryMapper<Dn>()
+    {
         @Override
         public Dn map( Entry entry ) throws LdapException
         {
@@ -147,31 +147,34 @@ public class LdapConnectionTemplate impl
 
 
     @Override
-    public PasswordWarning authenticate( String baseDn, String filter, SearchScope scope, char[] password ) throws PasswordException
+    public PasswordWarning authenticate( String baseDn, String filter, SearchScope scope, char[] password )
+        throws PasswordException
     {
         return authenticate( newSearchRequest( baseDn, filter, scope ), password );
     }
 
 
     @Override
-    public PasswordWarning authenticate( Dn baseDn, String filter, SearchScope scope, char[] password ) throws PasswordException
+    public PasswordWarning authenticate( Dn baseDn, String filter, SearchScope scope, char[] password )
+        throws PasswordException
     {
         return authenticate( newSearchRequest( baseDn, filter, scope ), password );
     }
-    
-    
+
+
     @Override
     public PasswordWarning authenticate( SearchRequest searchRequest, char[] password ) throws PasswordException
     {
         Dn userDn = searchFirst( searchRequest, dnEntryMapper );
-        if ( userDn == null ) {
+        if ( userDn == null )
+        {
             throw new PasswordException().setResultCode( ResultCodeEnum.INVALID_CREDENTIALS );
         }
-        
+
         return authenticate( userDn, password );
     }
-    
-    
+
+
     @Override
     public PasswordWarning authenticate( Dn userDn, char[] password ) throws PasswordException
     {
@@ -347,13 +350,15 @@ public class LdapConnectionTemplate impl
 
     }
 
+
     @Override
-    public void modifyPassword( Dn userDn, char[] newPassword ) 
+    public void modifyPassword( Dn userDn, char[] newPassword )
         throws PasswordException
     {
         modifyPassword( userDn, null, newPassword, true );
     }
 
+
     @Override
     public void modifyPassword( Dn userDn, char[] oldPassword,
         char[] newPassword ) throws PasswordException
@@ -361,6 +366,7 @@ public class LdapConnectionTemplate impl
         modifyPassword( userDn, oldPassword, newPassword, false );
     }
 
+
     @Override
     public void modifyPassword( Dn userDn, char[] oldPassword,
         char[] newPassword, boolean asAdmin ) throws PasswordException
@@ -552,8 +558,8 @@ public class LdapConnectionTemplate impl
     public <T> T searchFirst( String baseDn, String filter, SearchScope scope,
         EntryMapper<T> entryMapper )
     {
-        return searchFirst( 
-            modelFactory.newSearchRequest( baseDn, filter, scope ), 
+        return searchFirst(
+            modelFactory.newSearchRequest( baseDn, filter, scope ),
             entryMapper );
     }
 
@@ -562,8 +568,8 @@ public class LdapConnectionTemplate impl
     public <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
         EntryMapper<T> entryMapper )
     {
-        return searchFirst( 
-            modelFactory.newSearchRequest( baseDn, filter, scope ), 
+        return searchFirst(
+            modelFactory.newSearchRequest( baseDn, filter, scope ),
             entryMapper );
     }
 
@@ -573,7 +579,7 @@ public class LdapConnectionTemplate impl
         String[] attributes, EntryMapper<T> entryMapper )
     {
         return searchFirst(
-            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ), 
+            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ),
             entryMapper );
     }
 
@@ -583,11 +589,11 @@ public class LdapConnectionTemplate impl
         String[] attributes, EntryMapper<T> entryMapper )
     {
         return searchFirst(
-            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ), 
+            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ),
             entryMapper );
     }
-    
-    
+
+
     @Override
     public <T> T searchFirst( SearchRequest searchRequest,
         EntryMapper<T> entryMapper )
@@ -612,8 +618,8 @@ public class LdapConnectionTemplate impl
     public <T> List<T> search( String baseDn, String filter, SearchScope scope,
         EntryMapper<T> entryMapper )
     {
-        return search( 
-            modelFactory.newSearchRequest( baseDn, filter, scope ), 
+        return search(
+            modelFactory.newSearchRequest( baseDn, filter, scope ),
             entryMapper );
     }
 
@@ -622,8 +628,8 @@ public class LdapConnectionTemplate impl
     public <T> List<T> search( Dn baseDn, String filter, SearchScope scope,
         EntryMapper<T> entryMapper )
     {
-        return search( 
-            modelFactory.newSearchRequest( baseDn, filter, scope ), 
+        return search(
+            modelFactory.newSearchRequest( baseDn, filter, scope ),
             entryMapper );
     }
 
@@ -633,7 +639,7 @@ public class LdapConnectionTemplate impl
         String[] attributes, EntryMapper<T> entryMapper )
     {
         return search(
-            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ), 
+            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ),
             entryMapper );
     }
 
@@ -643,7 +649,7 @@ public class LdapConnectionTemplate impl
         String[] attributes, EntryMapper<T> entryMapper )
     {
         return search(
-            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ), 
+            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ),
             entryMapper );
     }
 

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/MemoryClearingBuffer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/MemoryClearingBuffer.java?rev=1630920&r1=1630919&r2=1630920&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/MemoryClearingBuffer.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/MemoryClearingBuffer.java Fri Oct 10 15:09:35 2014
@@ -1,245 +1,245 @@
-/*
- *   Licensed to the Apache Software Foundation (ASF) under one
- *   or more contributor license agreements.  See the NOTICE file
- *   distributed with this work for additional information
- *   regarding copyright ownership.  The ASF licenses this file
- *   to you under the Apache License, Version 2.0 (the
- *   "License"); you may not use this file except in compliance
- *   with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing,
- *   software distributed under the License is distributed on an
- *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *   KIND, either express or implied.  See the License for the
- *   specific language governing permissions and limitations
- *   under the License.
- *
- */
-package org.apache.directory.ldap.client.template;
-
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-
-
-/**
- * A buffer for storing sensitive information like passwords.  It provides 
- * useful operations for characters such as character encoding/decoding, 
- * whitespace trimming, and lowercasing.  It can be cleared out when operations
- * are complete.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class MemoryClearingBuffer
-{
-    private static final Charset UTF8 = Charset.forName( "UTF-8" );
-    private byte[] computedBytes;
-    private char[] computedChars;
-    private byte[] originalBytes;
-    private char[] originalChars;
-    private char[] precomputedChars;
-
-
-    private MemoryClearingBuffer( byte[] originalBytes, char[] originalChars, boolean trim, boolean lowerCase )
-    {
-        this.originalBytes = originalBytes;
-        this.originalChars = originalChars;
-
-        if ( trim || lowerCase )
-        {
-            if ( this.originalChars == null )
-            {
-                throw new UnsupportedOperationException( "trim and lowerCase only applicable to char[]" );
-            }
-
-            char[] working = Arrays.copyOf( originalChars, originalChars.length );
-            int startIndex = 0;
-            int endIndex = working.length;
-
-            if ( trim )
-            {
-                // ltrim
-                for ( ; startIndex < working.length; startIndex++ )
-                {
-                    if ( !Character.isWhitespace( working[startIndex] ) )
-                        break;
-                }
-
-                // rtrim
-                for ( endIndex--; endIndex > startIndex; endIndex-- )
-                {
-                    if ( !Character.isWhitespace( working[endIndex] ) )
-                        break;
-                }
-                endIndex++;
-            }
-
-            if ( lowerCase )
-            {
-                // lower case
-                for ( int i = startIndex; i < endIndex; i++ )
-                {
-                    working[i] = Character.toLowerCase( working[i] );
-                }
-            }
-
-            this.precomputedChars = new char[endIndex - startIndex];
-            System.arraycopy( working, startIndex, this.precomputedChars, 0, endIndex - startIndex );
-        }
-        else
-        {
-            this.precomputedChars = this.originalChars;
-        }
-    }
-
-
-    /**
-     * Creates a new instance of MemoryClearingBuffer from a 
-     * <code>byte[]</code>.
-     *
-     * @param bytes A byte[]
-     * @return A buffer
-     */
-    public static MemoryClearingBuffer newInstance( byte[] bytes )
-    {
-        return new MemoryClearingBuffer( bytes, null, false, false );
-    }
-
-
-    /**
-     * Creates a new instance of MemoryClearingBuffer from a 
-     * <code>char[]</code>.
-     *
-     * @param chars A char[]
-     * @return A buffer
-     */
-    public static MemoryClearingBuffer newInstance( char[] chars )
-    {
-        return new MemoryClearingBuffer( null, chars, false, false );
-    }
-
-
-    /**
-     * Creates a new instance of MemoryClearingBuffer from a 
-     * <code>char[]</code>, optionally performing whitespace trimming and
-     * conversion to lower case.
-     *
-     * @param chars A char[]
-     * @param trim If true, whitespace will be trimmed off of both ends of the
-     * <code>char[]</code>
-     * @param lowerCase If true, the characters will be converted to lower case
-     * @return A buffer
-     */
-    public static MemoryClearingBuffer newInstance( char[] chars, boolean trim, boolean lowerCase )
-    {
-        return new MemoryClearingBuffer( null, chars, trim, lowerCase );
-    }
-
-
-    /**
-     *  Clears the buffer out, filling its cells with null.
-     */
-    public void clear()
-    {
-        // clear out computed memory
-        if ( computedBytes != null )
-        {
-            Arrays.fill( computedBytes, ( byte ) 0 );
-        }
-        if ( computedChars != null )
-        {
-            Arrays.fill( computedChars, '0' );
-        }
-        if ( precomputedChars != null )
-        {
-            Arrays.fill( precomputedChars, '0' );
-        }
-
-        computedBytes = null;
-        computedChars = null;
-        originalBytes = null;
-        originalChars = null;
-        precomputedChars = null;
-    }
-
-
-    /**
-     * Returns a UTF8 encoded <code>byte[]</code> representation of the 
-     * <code>char[]</code> used to create this buffer.
-     * 
-     * @return A byte[]
-     */
-    byte[] getComputedBytes()
-    {
-        if ( computedBytes == null )
-        {
-            ByteBuffer byteBuffer = UTF8.encode(
-                CharBuffer.wrap( precomputedChars, 0, precomputedChars.length ) );
-            computedBytes = new byte[byteBuffer.remaining()];
-            byteBuffer.get( computedBytes );
-
-            // clear out the temporary bytebuffer
-            byteBuffer.flip();
-            byte[] nullifier = new byte[byteBuffer.limit()];
-            Arrays.fill( nullifier, ( byte ) 0 );
-            byteBuffer.put( nullifier );
-        }
-        return computedBytes;
-    }
-
-
-    /**
-     * Returns a UTF8 decoded <code>char[]</code> representation of the 
-     * <code>byte[]</code> used to create this buffer.
-     *
-     * @return A char[]
-     */
-    private char[] getComputedChars()
-    {
-        if ( computedChars == null )
-        {
-            CharBuffer charBuffer = UTF8.decode(
-                ByteBuffer.wrap( originalBytes, 0, originalBytes.length ) );
-            computedChars = new char[charBuffer.remaining()];
-            charBuffer.get( computedChars );
-
-            // clear out the temporary bytebuffer
-            charBuffer.flip();
-            char[] nullifier = new char[charBuffer.limit()];
-            Arrays.fill( nullifier, ( char ) 0 );
-            charBuffer.put( nullifier );
-        }
-        return computedChars;
-    }
-
-
-    /**
-     * Returns the <code>byte[]</code> used to create this buffer, or 
-     * {@link #getComputedBytes()} if created with a <code>char[]</code>.
-     *
-     * @return A byte[]
-     */
-    public byte[] getBytes()
-    {
-        return originalBytes == null
-            ? getComputedBytes()
-            : originalBytes;
-    }
-
-    /**
-     * Returns the <code>char[]</code> used to create this buffer, or 
-     * {@link #getComputedChars()} if created with a <code>byte[]</code>.
-     *
-     * @return A byte[]
-     */
-    public char[] getChars()
-    {
-        return precomputedChars == null
-            ? getComputedChars()
-            : precomputedChars;
-    }
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.ldap.client.template;
+
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+
+/**
+ * A buffer for storing sensitive information like passwords.  It provides 
+ * useful operations for characters such as character encoding/decoding, 
+ * whitespace trimming, and lowercasing.  It can be cleared out when operations
+ * are complete.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MemoryClearingBuffer
+{
+    private static final Charset UTF8 = Charset.forName( "UTF-8" );
+    private byte[] computedBytes;
+    private char[] computedChars;
+    private byte[] originalBytes;
+    private char[] originalChars;
+    private char[] precomputedChars;
+
+
+    private MemoryClearingBuffer( byte[] originalBytes, char[] originalChars, boolean trim, boolean lowerCase )
+    {
+        this.originalBytes = originalBytes;
+        this.originalChars = originalChars;
+
+        if ( trim || lowerCase )
+        {
+            if ( this.originalChars == null )
+            {
+                throw new UnsupportedOperationException( "trim and lowerCase only applicable to char[]" );
+            }
+
+            char[] working = Arrays.copyOf( originalChars, originalChars.length );
+            int startIndex = 0;
+            int endIndex = working.length;
+
+            if ( trim )
+            {
+                // ltrim
+                for ( ; startIndex < working.length; startIndex++ )
+                {
+                    if ( !Character.isWhitespace( working[startIndex] ) )
+                        break;
+                }
+
+                // rtrim
+                for ( endIndex--; endIndex > startIndex; endIndex-- )
+                {
+                    if ( !Character.isWhitespace( working[endIndex] ) )
+                        break;
+                }
+                endIndex++;
+            }
+
+            if ( lowerCase )
+            {
+                // lower case
+                for ( int i = startIndex; i < endIndex; i++ )
+                {
+                    working[i] = Character.toLowerCase( working[i] );
+                }
+            }
+
+            this.precomputedChars = new char[endIndex - startIndex];
+            System.arraycopy( working, startIndex, this.precomputedChars, 0, endIndex - startIndex );
+        }
+        else
+        {
+            this.precomputedChars = this.originalChars;
+        }
+    }
+
+
+    /**
+     * Creates a new instance of MemoryClearingBuffer from a 
+     * <code>byte[]</code>.
+     *
+     * @param bytes A byte[]
+     * @return A buffer
+     */
+    public static MemoryClearingBuffer newInstance( byte[] bytes )
+    {
+        return new MemoryClearingBuffer( bytes, null, false, false );
+    }
+
+
+    /**
+     * Creates a new instance of MemoryClearingBuffer from a 
+     * <code>char[]</code>.
+     *
+     * @param chars A char[]
+     * @return A buffer
+     */
+    public static MemoryClearingBuffer newInstance( char[] chars )
+    {
+        return new MemoryClearingBuffer( null, chars, false, false );
+    }
+
+
+    /**
+     * Creates a new instance of MemoryClearingBuffer from a 
+     * <code>char[]</code>, optionally performing whitespace trimming and
+     * conversion to lower case.
+     *
+     * @param chars A char[]
+     * @param trim If true, whitespace will be trimmed off of both ends of the
+     * <code>char[]</code>
+     * @param lowerCase If true, the characters will be converted to lower case
+     * @return A buffer
+     */
+    public static MemoryClearingBuffer newInstance( char[] chars, boolean trim, boolean lowerCase )
+    {
+        return new MemoryClearingBuffer( null, chars, trim, lowerCase );
+    }
+
+
+    /**
+     *  Clears the buffer out, filling its cells with null.
+     */
+    public void clear()
+    {
+        // clear out computed memory
+        if ( computedBytes != null )
+        {
+            Arrays.fill( computedBytes, ( byte ) 0 );
+        }
+        if ( computedChars != null )
+        {
+            Arrays.fill( computedChars, '0' );
+        }
+        if ( precomputedChars != null )
+        {
+            Arrays.fill( precomputedChars, '0' );
+        }
+
+        computedBytes = null;
+        computedChars = null;
+        originalBytes = null;
+        originalChars = null;
+        precomputedChars = null;
+    }
+
+
+    /**
+     * Returns a UTF8 encoded <code>byte[]</code> representation of the 
+     * <code>char[]</code> used to create this buffer.
+     * 
+     * @return A byte[]
+     */
+    byte[] getComputedBytes()
+    {
+        if ( computedBytes == null )
+        {
+            ByteBuffer byteBuffer = UTF8.encode(
+                CharBuffer.wrap( precomputedChars, 0, precomputedChars.length ) );
+            computedBytes = new byte[byteBuffer.remaining()];
+            byteBuffer.get( computedBytes );
+
+            // clear out the temporary bytebuffer
+            byteBuffer.flip();
+            byte[] nullifier = new byte[byteBuffer.limit()];
+            Arrays.fill( nullifier, ( byte ) 0 );
+            byteBuffer.put( nullifier );
+        }
+        return computedBytes;
+    }
+
+
+    /**
+     * Returns a UTF8 decoded <code>char[]</code> representation of the 
+     * <code>byte[]</code> used to create this buffer.
+     *
+     * @return A char[]
+     */
+    private char[] getComputedChars()
+    {
+        if ( computedChars == null )
+        {
+            CharBuffer charBuffer = UTF8.decode(
+                ByteBuffer.wrap( originalBytes, 0, originalBytes.length ) );
+            computedChars = new char[charBuffer.remaining()];
+            charBuffer.get( computedChars );
+
+            // clear out the temporary bytebuffer
+            charBuffer.flip();
+            char[] nullifier = new char[charBuffer.limit()];
+            Arrays.fill( nullifier, ( char ) 0 );
+            charBuffer.put( nullifier );
+        }
+        return computedChars;
+    }
+
+
+    /**
+     * Returns the <code>byte[]</code> used to create this buffer, or 
+     * {@link #getComputedBytes()} if created with a <code>char[]</code>.
+     *
+     * @return A byte[]
+     */
+    public byte[] getBytes()
+    {
+        return originalBytes == null
+            ? getComputedBytes()
+            : originalBytes;
+    }
+
+    /**
+     * Returns the <code>char[]</code> used to create this buffer, or 
+     * {@link #getComputedChars()} if created with a <code>byte[]</code>.
+     *
+     * @return A byte[]
+     */
+    public char[] getChars()
+    {
+        return precomputedChars == null
+            ? getComputedChars()
+            : precomputedChars;
+    }
 }
\ No newline at end of file