directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1027916 - in /directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core: ./ io/api/
Date Wed, 27 Oct 2010 11:22:05 GMT
Author: pamarcelot
Date: Wed Oct 27 11:22:05 2010
New Revision: 1027916

URL: http://svn.apache.org/viewvc?rev=1027916&view=rev
Log:
Added support for non simple binds (needs to be polished a little more).
Added support for PagedSearchControl in the Directory API connection wrapper.

Added:
    directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/DirectoryServerInfo.java
Modified:
    directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/CursorStudioNamingEnumeration.java
    directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java

Added: directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/DirectoryServerInfo.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/DirectoryServerInfo.java?rev=1027916&view=auto
==============================================================================
--- directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/DirectoryServerInfo.java
(added)
+++ directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/DirectoryServerInfo.java
Wed Oct 27 11:22:05 2010
@@ -0,0 +1,115 @@
+/*
+ *  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.studio.connection.core;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
+
+
+/**
+ * This class holds information about a directory server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DirectoryServerInfo
+{
+    /**
+     * This enum contains all detectable directory server types.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     */
+    public static enum DirectoryServerType
+    {
+        APACHEDS,
+        IBM_DIRECTORY_SERVER,
+        IBM_SECUREWAY_DIRECTORY,
+        IBM_TIVOLI_DIRECTORY_SERVER,
+        MICROSOFT_ACTIVE_DIRECTORY_2000,
+        MICROSOFT_ACTIVE_DIRECTORY_2003,
+        NETSCAPE,
+        NOVELL,
+        OPENLDAP,
+        OPENDS,
+        OPENDJ,
+        SIEMENS_DIRX,
+        SUN_DIRECTORY_SERVER,
+        UNKNOWN
+    }
+
+    /** The type */
+    private DirectoryServerType type;
+
+    /** The version */
+    private String version;
+
+
+    /**
+     * Gets the type.
+     *
+     * @return
+     *      the type
+     */
+    public DirectoryServerType getType()
+    {
+        return type;
+    }
+
+
+    /**
+     * Sets the type.
+     *
+     * @param type
+     *      the type
+     */
+    public void setType( DirectoryServerType type )
+    {
+        this.type = type;
+    }
+
+
+    /**
+     * Gets the version.
+     *
+     * @return
+     *      the version
+     */
+    public String getVersion()
+    {
+        return version;
+    }
+
+
+    /**
+     * Sets the version.
+     *
+     * @param version
+     *      the version
+     */
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
+
+}

Modified: directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/CursorStudioNamingEnumeration.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/CursorStudioNamingEnumeration.java?rev=1027916&r1=1027915&r2=1027916&view=diff
==============================================================================
--- directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/CursorStudioNamingEnumeration.java
(original)
+++ directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/CursorStudioNamingEnumeration.java
Wed Oct 27 11:22:05 2010
@@ -20,18 +20,26 @@
 package org.apache.directory.studio.connection.core.io.api;
 
 
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 import javax.naming.NamingException;
 import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
+import javax.naming.ldap.BasicControl;
 import javax.naming.ldap.Control;
+import javax.naming.ldap.PagedResultsResponseControl;
 
+import org.apache.directory.ldap.client.api.SearchCursor;
+import org.apache.directory.shared.ldap.codec.search.controls.pagedSearch.PagedResultsControl;
 import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.message.Referral;
 import org.apache.directory.shared.ldap.message.Response;
+import org.apache.directory.shared.ldap.message.SearchResultDone;
 import org.apache.directory.shared.ldap.message.SearchResultEntry;
 import org.apache.directory.shared.ldap.message.SearchResultReference;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
@@ -61,6 +69,7 @@ public class CursorStudioNamingEnumerati
     private List<Referral> referralsList = new ArrayList<Referral>();
     private List<String> currentReferralUrlsList;
     private StudioNamingEnumeration cursorNamingEnumeration;
+    private SearchResultDone searchResultDone;
 
 
     /**
@@ -149,6 +158,12 @@ public class CursorStudioNamingEnumerati
                 }
             }
 
+            // Storing the search result done (if needed)
+            if ( searchResultDone == null )
+            {
+                searchResultDone = ( ( SearchCursor ) cursor ).getSearchDone();
+            }
+
             // Are we following referrals manually?
             if ( referralsHandlingMethod == ReferralHandlingMethod.FOLLOW_MANUALLY )
             {
@@ -322,8 +337,66 @@ public class CursorStudioNamingEnumerati
      */
     public Control[] getResponseControls() throws NamingException
     {
-        //        return ctx != null ? ctx.getResponseControls() : null;
-        // TODO implement
+        if ( searchResultDone != null )
+        {
+            Map<String, org.apache.directory.shared.ldap.message.control.Control> controlsMap
= searchResultDone
+                .getControls();
+            if ( ( controlsMap != null ) && ( controlsMap.size() > 0 ) )
+            {
+                return convertControls( controlsMap.values() );
+            }
+        }
+
         return new Control[0];
     }
+
+
+    /**
+     * Converts the controls.
+     *
+     * @param controls
+     *      an array of controls
+     * @return
+     *      an array of converted controls
+     */
+    private Control[] convertControls( Collection<org.apache.directory.shared.ldap.message.control.Control>
controls )
+    {
+        if ( controls != null )
+        {
+            List<Control> convertedControls = new ArrayList<Control>();
+
+            for ( org.apache.directory.shared.ldap.message.control.Control control : controls
)
+            {
+                if ( PagedResultsResponseControl.OID.equals( control.getOid() ) )
+                {
+                    // Special case for the PagedResultsResponseControl
+                    try
+                    {
+                        PagedResultsResponseControl convertedControl = new PagedResultsResponseControl(
+                            control.getOid(),
+                            control.isCritical(), control.getValue() );
+                        convertedControls.add( convertedControl );
+                    }
+                    catch ( IOException e )
+                    {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                }
+                else
+                {
+                    // Default case
+                    Control convertedControl = new BasicControl( control.getOid(), control.isCritical(),
+                        control.getValue() );
+                    convertedControls.add( convertedControl );
+                }
+            }
+
+            return convertedControls.toArray( new Control[0] );
+        }
+        else
+        {
+            return new Control[0];
+        }
+    }
 }

Modified: directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java?rev=1027916&r1=1027915&r2=1027916&view=diff
==============================================================================
--- directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
(original)
+++ directory/studio/branches/studio-connection-refactoring/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
Wed Oct 27 11:22:05 2010
@@ -48,14 +48,21 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.AddRequest;
 import org.apache.directory.shared.ldap.message.AddRequestImpl;
+import org.apache.directory.shared.ldap.message.AddResponse;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.DeleteRequest;
 import org.apache.directory.shared.ldap.message.DeleteRequestImpl;
+import org.apache.directory.shared.ldap.message.DeleteResponse;
+import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ModifyDnRequest;
 import org.apache.directory.shared.ldap.message.ModifyDnRequestImpl;
+import org.apache.directory.shared.ldap.message.ModifyDnResponse;
 import org.apache.directory.shared.ldap.message.ModifyRequest;
 import org.apache.directory.shared.ldap.message.ModifyRequestImpl;
+import org.apache.directory.shared.ldap.message.ModifyResponse;
 import org.apache.directory.shared.ldap.message.Response;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.message.ResultResponse;
 import org.apache.directory.shared.ldap.message.SearchRequest;
 import org.apache.directory.shared.ldap.message.SearchRequestImpl;
 import org.apache.directory.shared.ldap.name.DN;
@@ -65,6 +72,7 @@ import org.apache.directory.studio.conne
 import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
 import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionParameter;
 import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
 import org.apache.directory.studio.connection.core.IAuthHandler;
 import org.apache.directory.studio.connection.core.ICredentials;
@@ -295,7 +303,22 @@ public class DirectoryApiConnectionWrapp
                         bindPrincipal = credentials.getBindPrincipal();
                         bindPassword = credentials.getBindPassword();
 
-                        getLdapConnection().bind( bindPrincipal, bindPassword );
+                        // Simple Authentication
+                        if ( connection.getConnectionParameter().getAuthMethod() == ConnectionParameter.AuthenticationMethod.SIMPLE
)
+                        {
+                            getLdapConnection().bind( bindPrincipal, bindPassword );
+                        }
+                        // CRAM-MD5 Authentication
+                        else if ( connection.getConnectionParameter().getAuthMethod() ==
ConnectionParameter.AuthenticationMethod.SASL_CRAM_MD5 )
+                        {
+                            getLdapConnection().bindCramMd5( bindPrincipal, bindPassword,
null );
+                        }
+                        // DIGEST-MD5 Authentication
+                        else if ( connection.getConnectionParameter().getAuthMethod() ==
ConnectionParameter.AuthenticationMethod.SASL_DIGEST_MD5 )
+                        {
+                            getLdapConnection().bindDigestMd5( bindPrincipal, bindPassword,
null,
+                                connection.getConnectionParameter().getSaslRealm() );
+                        }
                     }
                     catch ( Exception e )
                     {
@@ -556,7 +579,10 @@ public class DirectoryApiConnectionWrapp
                     request.addAllControls( convertControls( controls ) );
 
                     // Performing the modify operation
-                    getLdapConnection().modify( request );
+                    ModifyResponse modifyResponse = getLdapConnection().modify( request );
+
+                    // Checking the response
+                    checkResponse( modifyResponse );
                 }
                 catch ( Exception e )
                 {
@@ -682,7 +708,10 @@ public class DirectoryApiConnectionWrapp
                     request.addAllControls( convertControls( controls ) );
 
                     // Performing the rename operation
-                    getLdapConnection().modifyDn( request );
+                    ModifyDnResponse modifyDnResponse = getLdapConnection().modifyDn( request
);
+
+                    // Checking the response
+                    checkResponse( modifyDnResponse );
                 }
                 catch ( Exception e )
                 {
@@ -747,7 +776,10 @@ public class DirectoryApiConnectionWrapp
                     request.addAllControls( convertControls( controls ) );
 
                     // Performing the add operation
-                    getLdapConnection().add( request );
+                    AddResponse addResponse = getLdapConnection().add( request );
+
+                    // Checking the response
+                    checkResponse( addResponse );
                 }
                 catch ( Exception e )
                 {
@@ -811,7 +843,10 @@ public class DirectoryApiConnectionWrapp
                     request.addAllControls( convertControls( controls ) );
 
                     // Performing the delete operation
-                    getLdapConnection().delete( request );
+                    DeleteResponse deleteResponse = getLdapConnection().delete( request );
+
+                    // Checking the response
+                    checkResponse( deleteResponse );
                 }
                 catch ( Exception e )
                 {
@@ -1013,4 +1048,25 @@ public class DirectoryApiConnectionWrapp
     {
         return ConnectionCorePlugin.getDefault().getJndiLoggers();
     }
+
+
+    /**
+     * Checks the given response.
+     *
+     * @param response
+     *      the response
+     * @throws Exception
+     *      if the LDAP result associated with the response is not a success
+     */
+    private void checkResponse( ResultResponse response ) throws Exception
+    {
+        if ( response != null )
+        {
+            LdapResult ldapResult = response.getLdapResult();
+            if ( ( ldapResult != null ) && !( ResultCodeEnum.SUCCESS.equals( ldapResult.getResultCode()
) ) )
+            {
+                throw new Exception( ldapResult.getResultCode().getResultCode() + " " + ldapResult.getErrorMessage()
);
+            }
+        }
+    }
 }



Mime
View raw message