Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 49821 invoked from network); 24 Feb 2011 17:47:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Feb 2011 17:47:27 -0000 Received: (qmail 51177 invoked by uid 500); 24 Feb 2011 17:47:27 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 51107 invoked by uid 500); 24 Feb 2011 17:47:26 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 51097 invoked by uid 99); 24 Feb 2011 17:47:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Feb 2011 17:47:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Feb 2011 17:47:25 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A6E07238896F; Thu, 24 Feb 2011 17:47:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1074231 - /directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ServerTypeDetector.java Date: Thu, 24 Feb 2011 17:47:05 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110224174705.A6E07238896F@eris.apache.org> Author: pamarcelot Date: Thu Feb 24 17:47:05 2011 New Revision: 1074231 URL: http://svn.apache.org/viewvc?rev=1074231&view=rev Log: Moved and refactored the code for server type detection to a dedicated class, now returning a ConnectionServerType enum instance. Used this class during the Root DSE initialization to set the server type detected property. [2/2] - (Missed one class) Added: directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ServerTypeDetector.java Added: directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ServerTypeDetector.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ServerTypeDetector.java?rev=1074231&view=auto ============================================================================== --- directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ServerTypeDetector.java (added) +++ directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ServerTypeDetector.java Thu Feb 24 17:47:05 2011 @@ -0,0 +1,369 @@ +/* + * 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.ldapbrowser.core.jobs; + + +import org.apache.directory.studio.connection.core.ConnectionServerType; +import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; +import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; + + +/** + * Utility class for detecting the type of server based on its Root DSE. + * + * @author Apache Directory Project + */ +public class ServerTypeDetector +{ + /** + * Detects the type of the server. + * + * @param rootDSE the Root DSE + * @return the corresponding server type or 'UNKNOWN' + */ + public static ConnectionServerType detectServerType( IRootDSE rootDSE ) + { + ConnectionServerType serverType = ConnectionServerType.UNKNOWN; + + IAttribute vnAttribute = rootDSE.getAttribute( "vendorName" ); //$NON-NLS-1$ + IAttribute vvAttribute = rootDSE.getAttribute( "vendorVersion" ); //$NON-NLS-1$ + + if ( vnAttribute != null && vnAttribute.getStringValues().length > 0 && vvAttribute != null + && vvAttribute.getStringValues().length > 0 ) + { + String vendorName = vnAttribute.getStringValues()[0]; + String vendorVersion = vvAttribute.getStringValues()[0]; + + // Apache DS + serverType = detectApacheDS( vendorName ); + if ( !ConnectionServerType.UNKNOWN.equals( serverType ) ) + { + return serverType; + } + + // IBM + serverType = detectIbm( vendorName, vendorVersion ); + if ( !ConnectionServerType.UNKNOWN.equals( serverType ) ) + { + return serverType; + } + + // Netscape + serverType = detectNetscape( vendorName, vendorVersion ); + if ( !ConnectionServerType.UNKNOWN.equals( serverType ) ) + { + return serverType; + } + + // Novell + serverType = detectNovell( vendorName, vendorVersion ); + if ( !ConnectionServerType.UNKNOWN.equals( serverType ) ) + { + return serverType; + } + + // Sun + serverType = detectSun( vendorName, vendorVersion ); + if ( !ConnectionServerType.UNKNOWN.equals( serverType ) ) + { + return serverType; + } + } + + // Microsoft + serverType = detectMicrosoft( rootDSE ); + if ( !ConnectionServerType.UNKNOWN.equals( serverType ) ) + { + return serverType; + } + + // OpenLDAP + serverType = detectOpenLdap( rootDSE ); + if ( !ConnectionServerType.UNKNOWN.equals( serverType ) ) + { + return serverType; + } + + // Siemens + serverType = detectSiemens( rootDSE ); + if ( !ConnectionServerType.UNKNOWN.equals( serverType ) ) + { + return serverType; + } + + return ConnectionServerType.UNKNOWN; + } + + + /** + * Detects ApacheDS. + * + * @param vendorName the vendor name + * @return the corresponding server type or 'UNKNOWN' + */ + private static ConnectionServerType detectApacheDS( String vendorName ) + { + if ( vendorName.indexOf( "Apache Software Foundation" ) > -1 ) //$NON-NLS-1$ + { + return ConnectionServerType.APACHEDS; + } + + return ConnectionServerType.UNKNOWN; + } + + + /** + * Detects the following IBM directory servers: + *
    + *
  • IBM Directory Server
  • + *
  • IBM Secureway Directory
  • + *
  • IBM Tivoli Directory Server
  • + *
+ * + * @param vendorName the vendor name + * @param vendorVersion the vendor version + * @return the corresponding server type or 'UNKNOWN' + */ + private static ConnectionServerType detectIbm( String vendorName, String vendorVersion ) + { + // IBM + if ( vendorName.indexOf( "International Business Machines" ) > -1 ) //$NON-NLS-1$ + { + // IBM SecureWay Directory + String[] iswVersions = + { "3.2", "3.2.1", "3.2.2" }; //$NON-NLS-1$ + for ( String version : iswVersions ) + { + if ( vendorVersion.indexOf( version ) > -1 ) + { + return ConnectionServerType.IBM_SECUREWAY_DIRECTORY; + } + } + + // IBM Directory Server + String[] idsVersions = + { "4.1", "5.1" }; //$NON-NLS-1$ + for ( String version : idsVersions ) + { + if ( vendorVersion.indexOf( version ) > -1 ) + { + return ConnectionServerType.IBM_DIRECTORY_SERVER; + } + } + + // IBM Tivoli Directory Server + String[] tdsVersions = + { "5.2", "6.0", "6.1", "6.2" }; //$NON-NLS-1$ + for ( String version : tdsVersions ) + { + if ( vendorVersion.indexOf( version ) > -1 ) + { + return ConnectionServerType.IBM_TIVOLI_DIRECTORY_SERVER; + } + } + } + + return ConnectionServerType.UNKNOWN; + } + + + /** + * Detects the following Microsoft directory servers: + *
    + *
  • Microsoft Active Directory 2000
  • + *
  • Microsoft Active Directory 2003
  • + *
+ * + * @param rootDSE the Root DSE + * @return the corresponding server type or 'UNKNOWN' + */ + private static ConnectionServerType detectMicrosoft( IRootDSE rootDSE ) + { + IAttribute rdncAttribute = rootDSE.getAttribute( "rootDomainNamingContext" ); //$NON-NLS-1$ + if ( rdncAttribute != null ) + { + IAttribute ffAttribute = rootDSE.getAttribute( "forestFunctionality" ); //$NON-NLS-1$ + if ( ffAttribute != null ) + { + return ConnectionServerType.MICROSOFT_ACTIVE_DIRECTORY_2003; + } + else + { + return ConnectionServerType.MICROSOFT_ACTIVE_DIRECTORY_2000; + } + } + + return ConnectionServerType.UNKNOWN; + } + + + /** + * Detects Netscape directory server. + * + * @param vendorName the vendor name + * @param vendorVersion the vendor version + * @return the corresponding server type or 'UNKNOWN' + */ + private static ConnectionServerType detectNetscape( String vendorName, String vendorVersion ) + { + if ( vendorName.indexOf( "Netscape" ) > -1 //$NON-NLS-1$ + || vendorVersion.indexOf( "Netscape" ) > -1 ) //$NON-NLS-1$ + { + return ConnectionServerType.NETSCAPE; + } + + return ConnectionServerType.UNKNOWN; + } + + + /** + * Detects Novell directory server. + * + * @param vendorName the vendor name + * @param vendorVersion the vendor version + * @return the corresponding server type or 'UNKNOWN' + */ + private static ConnectionServerType detectNovell( String vendorName, String vendorVersion ) + { + if ( vendorName.indexOf( "Novell" ) > -1 //$NON-NLS-1$ + || vendorVersion.indexOf( "eDirectory" ) > -1 ) //$NON-NLS-1$ + { + return ConnectionServerType.NOVELL; + } + + return ConnectionServerType.UNKNOWN; + } + + + /** + * Detects the following Microsoft directory servers: + *
    + *
  • OpenLDAP 2.3
  • + *
  • OpenLDAP 2.2
  • + *
  • OpenLDAP 2.1
  • + *
  • OpenLDAP 2.0
  • + *
  • OpenLDAP
  • + *
+ * + * @param rootDSE the Root DSE + * @return the corresponding server type or 'UNKNOWN' + */ + private static ConnectionServerType detectOpenLdap( IRootDSE rootDSE ) + { + IAttribute ocAttribute = rootDSE.getAttribute( "objectClass" ); //$NON-NLS-1$ + if ( ocAttribute != null ) + { + for ( int i = 0; i < ocAttribute.getStringValues().length; i++ ) + { + if ( "OpenLDAProotDSE".equals( ocAttribute.getStringValues()[i] ) ) //$NON-NLS-1$ + { + IAttribute ccAttribute = rootDSE.getAttribute( "configContext" ); //$NON-NLS-1$ + if ( ccAttribute != null ) + { + return ConnectionServerType.OPENLDAP_2_3; + } + + IAttribute scAttribute = rootDSE.getAttribute( "supportedControl" ); //$NON-NLS-1$ + if ( scAttribute != null ) + { + for ( int sci = 0; sci < scAttribute.getStringValues().length; sci++ ) + { + if ( "2.16.840.1.113730.3.4.18".equals( scAttribute.getStringValues()[sci] ) ) //$NON-NLS-1$ + { + return ConnectionServerType.OPENLDAP_2_2; + } + } + } + + IAttribute seAttribute = rootDSE.getAttribute( "supportedExtension" ); //$NON-NLS-1$ + if ( seAttribute != null ) + { + for ( int sei = 0; sei < seAttribute.getStringValues().length; sei++ ) + { + if ( "1.3.6.1.4.1.4203.1.11.3".equals( seAttribute.getStringValues()[sei] ) ) //$NON-NLS-1$ + { + return ConnectionServerType.OPENLDAP_2_1; + } + } + } + + IAttribute sfAttribute = rootDSE.getAttribute( "supportedFeatures" ); //$NON-NLS-1$ + if ( sfAttribute != null ) + { + for ( int sfi = 0; sfi < sfAttribute.getStringValues().length; sfi++ ) + { + if ( "1.3.6.1.4.1.4203.1.5.4".equals( sfAttribute.getStringValues()[sfi] ) ) //$NON-NLS-1$ + { + return ConnectionServerType.OPENLDAP_2_0; + } + } + } + + return ConnectionServerType.OPENLDAP; + } + } + } + + return ConnectionServerType.UNKNOWN; + } + + + /** + * Detects Siemens directory server. + * + * @param rootDSE the Root DSE + * @return the corresponding server type or 'UNKNOWN' + */ + private static ConnectionServerType detectSiemens( IRootDSE rootDSE ) + { + IAttribute ssseAttribute = rootDSE.getAttribute( "subSchemaSubentry" ); //$NON-NLS-1$ + if ( ssseAttribute != null ) + { + for ( int i = 0; i < ssseAttribute.getStringValues().length; i++ ) + { + if ( "cn=LDAPGlobalSchemaSubentry".equals( ssseAttribute.getStringValues()[i] ) ) //$NON-NLS-1$ + { + return ConnectionServerType.SIEMENS_DIRX; + } + } + } + + return ConnectionServerType.UNKNOWN; + } + + + /** + * Detects Sun directory server. + * + * @param vendorName the vendor name + * @param vendorVersion the vendor version + * @return the corresponding server type or 'UNKNOWN' + */ + private static ConnectionServerType detectSun( String vendorName, String vendorVersion ) + { + if ( vendorName.indexOf( "Sun" ) > -1 //$NON-NLS-1$ + || vendorVersion.indexOf( "Sun" ) > -1 ) //$NON-NLS-1$ + { + return ConnectionServerType.SUN_DIRECTORY_SERVER; + } + return ConnectionServerType.UNKNOWN; + } +}