directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1805170 - in /directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core: ./ io/ io/api/ io/jndi/
Date Wed, 16 Aug 2017 10:44:25 GMT
Author: elecharny
Date: Wed Aug 16 10:44:25 2017
New Revision: 1805170

URL: http://svn.apache.org/viewvc?rev=1805170&view=rev
Log:
o Added a 'timeout' parameter to a connection (useful when debugging a server)
o Some formating
o Sonar warnings removal
o Switch to Java 8 syntax (lambda)

Modified:
    directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Connection.java
    directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
    directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java
    directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
    directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
    directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java

Modified: directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Connection.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Connection.java?rev=1805170&r1=1805169&r2=1805170&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Connection.java (original)
+++ directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Connection.java Wed Aug 16 10:44:25 2017
@@ -49,7 +49,7 @@ public class Connection implements Conne
      * 
      * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
      */
-    public static enum AliasDereferencingMethod
+    public enum AliasDereferencingMethod
     {
         /** Never. */
         NEVER(0),
@@ -96,12 +96,16 @@ public class Connection implements Conne
             {
                 case 0:
                     return NEVER;
+                    
                 case 1:
                     return ALWAYS;
+                    
                 case 2:
                     return FINDING;
+                    
                 case 3:
                     return SEARCH;
+                    
                 default:
                     return null;
             }
@@ -113,7 +117,7 @@ public class Connection implements Conne
      * 
      * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
      */
-    public static enum ReferralHandlingMethod
+    public enum ReferralHandlingMethod
     {
         /** Ignore. */
         IGNORE(0),
@@ -160,12 +164,16 @@ public class Connection implements Conne
             {
                 case 0:
                     return IGNORE;
+                    
                 case 1:
                     return FOLLOW;
+                    
                 case 2:
                     return FOLLOW_MANUALLY;
+                    
                 case 3:
                     return FOLLOW_MANUALLY;
+                    
                 default:
                     return null;
             }
@@ -201,11 +209,9 @@ public class Connection implements Conne
     {
         ConnectionParameter cp = new ConnectionParameter( getName(), getHost(), getPort(), getEncryptionMethod(),
             getNetworkProvider(), getAuthMethod(), getBindPrincipal(), getBindPassword(), getSaslRealm(), isReadOnly(),
-            getConnectionParameter().getExtendedProperties() );
+            getConnectionParameter().getExtendedProperties() , getTimeout() );
 
-        Connection clone = new Connection( cp );
-
-        return clone;
+        return new Connection( cp );
     }
 
 
@@ -220,6 +226,7 @@ public class Connection implements Conne
         {
             case JNDI:
                 return getJndiConnectionWrapper();
+                
             case APACHE_DIRECTORY_LDAP_API:
                 return getDirectoryApiConnectionWrapper();
         }
@@ -528,6 +535,17 @@ public class Connection implements Conne
 
 
     /**
+     * Gets the timeout.
+     * 
+     * @return the timeout
+     */
+    public long getTimeout()
+    {
+        return connectionParameter.getTimeout();
+    }
+
+
+    /**
      * Sets the auth method.
      * 
      * @param authMethod the auth method
@@ -634,6 +652,18 @@ public class Connection implements Conne
         ConnectionEventRegistry.fireConnectionUpdated( this, this );
     }
 
+    
+    /**
+     * Sets the timeout.
+     * 
+     * @param timeout the timeout
+     */
+    public void setTimeout( long timeout )
+    {
+        connectionParameter.setTimeout( timeout );
+        ConnectionEventRegistry.fireConnectionUpdated( this, this );
+    }
+
 
     /**
      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
@@ -641,10 +671,6 @@ public class Connection implements Conne
     @SuppressWarnings("unchecked")
     public Object getAdapter( Class adapter )
     {
-        //        if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) )
-        //        {
-        //            return new LdapSearchPageScoreComputer();
-        //        }
         if ( adapter == Connection.class )
         {
             return this;
@@ -668,6 +694,7 @@ public class Connection implements Conne
         LdapUrl url = new LdapUrl();
         url.setHost( getHost() );
         url.setPort( getPort() );
+        
         return url;
     }
 

Modified: directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java?rev=1805170&r1=1805169&r2=1805170&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java (original)
+++ directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java Wed Aug 16 10:44:25 2017
@@ -73,7 +73,7 @@ public class ConnectionManager implement
      */
     public ConnectionManager()
     {
-        this.connectionList = new HashSet<Connection>();
+        this.connectionList = new HashSet<>();
         loadInitializers();
         loadConnections();
         ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner() );
@@ -180,8 +180,7 @@ public class ConnectionManager implement
      */
     public static final String getConnectionStoreFileName()
     {
-        String filename = ConnectionCorePlugin.getDefault().getStateLocation().append( CONNECTIONS_XML ).toOSString();
-        return filename;
+        return ConnectionCorePlugin.getDefault().getStateLocation().append( CONNECTIONS_XML ).toOSString();
     }
 
 
@@ -273,7 +272,7 @@ public class ConnectionManager implement
      */
     public Connection[] getConnections()
     {
-        return ( Connection[] ) connectionList.toArray( new Connection[0] );
+        return connectionList.toArray( new Connection[0] );
     }
 
 
@@ -361,7 +360,8 @@ public class ConnectionManager implement
      */
     public synchronized void saveConnections()
     {
-        Set<ConnectionParameter> connectionParameters = new HashSet<ConnectionParameter>();
+        Set<ConnectionParameter> connectionParameters = new HashSet<>();
+        
         for ( Connection connection : connectionList )
         {
             connectionParameters.add( connection.getConnectionParameter() );
@@ -383,6 +383,7 @@ public class ConnectionManager implement
         // move temp file to good file
         File file = new File( getConnectionStoreFileName() );
         File tempFile = new File( getConnectionStoreFileName() + TEMP_SUFFIX );
+        
         if ( file.exists() )
         {
             file.delete();

Modified: directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java?rev=1805170&r1=1805169&r2=1805170&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java (original)
+++ directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java Wed Aug 16 10:44:25 2017
@@ -91,7 +91,11 @@ public class ConnectionParameter
         SASL_CRAM_MD5(3),
 
         /** SASL authentication using GSSAPI. */
-        SASL_GSSAPI(4);
+        SASL_GSSAPI(4),
+        
+        /** SASL PLAIN authentication */
+        SASL_PLAIN(5);
+        
         
         private int value;
         
@@ -178,6 +182,9 @@ public class ConnectionParameter
 
     /** The extended properties. */
     private Map<String, String> extendedProperties;
+    
+    /** The connection timeout. Default to 30 seconds */
+    private long timeout = 30000L;
 
 
     /**
@@ -185,7 +192,7 @@ public class ConnectionParameter
      */
     public ConnectionParameter()
     {
-        this.extendedProperties = new HashMap<String, String>();
+        this.extendedProperties = new HashMap<>();
     }
 
 
@@ -205,7 +212,7 @@ public class ConnectionParameter
      */
     public ConnectionParameter( String name, String host, int port, EncryptionMethod encryptionMethod,
         NetworkProvider networkProvider, AuthenticationMethod authMethod, String bindPrincipal, String bindPassword,
-        String saslRealm, boolean isReadOnly, Map<String, String> extendedProperties )
+        String saslRealm, boolean isReadOnly, Map<String, String> extendedProperties, long timeout )
     {
         this.id = createId();
         this.name = name;
@@ -218,11 +225,14 @@ public class ConnectionParameter
         this.bindPassword = bindPassword;
         this.saslRealm = saslRealm;
         this.isReadOnly = isReadOnly;
-        this.extendedProperties = new HashMap<String, String>();
+        this.extendedProperties = new HashMap<>();
+
         if ( extendedProperties != null )
         {
             this.extendedProperties.putAll( extendedProperties );
         }
+
+        this.timeout = timeout;
     }
 
 
@@ -755,7 +765,7 @@ public class ConnectionParameter
             String[] array = s.split( ";" ); //$NON-NLS-1$
             if ( ( array != null ) && ( array.length > 0 ) )
             {
-                return new ArrayList<String>( Arrays.asList( array ) );
+                return new ArrayList<>( Arrays.asList( array ) );
             }
         }
 
@@ -771,7 +781,7 @@ public class ConnectionParameter
      */
     public void setExtendedIntProperty( String key, int value )
     {
-        extendedProperties.put( key, new Integer( value ).toString() );
+        extendedProperties.put( key, Integer.toString( value ) );
     }
 
 
@@ -785,9 +795,10 @@ public class ConnectionParameter
     public int getExtendedIntProperty( String key )
     {
         String s = extendedProperties.get( key );
+        
         if ( s != null )
         {
-            return new Integer( s ).intValue();
+            return Integer.parseInt( s );
         }
         else
         {
@@ -804,7 +815,7 @@ public class ConnectionParameter
      */
     public void setExtendedBoolProperty( String key, boolean value )
     {
-        extendedProperties.put( key, Boolean.valueOf( value ).toString() );
+        extendedProperties.put( key, Boolean.toString( value ) );
     }
 
 
@@ -818,9 +829,10 @@ public class ConnectionParameter
     public boolean getExtendedBoolProperty( String key )
     {
         String s = extendedProperties.get( key );
+        
         if ( s != null )
         {
-            return Boolean.valueOf( s ).booleanValue();
+            return Boolean.parseBoolean( s );
         }
         else
         {
@@ -829,6 +841,28 @@ public class ConnectionParameter
     }
 
 
+    /**
+     * Gets the timeout.
+     * 
+     * @return the timeout
+     */
+    public long getTimeout()
+    {
+        return timeout;
+    }
+
+
+    /**
+     * Sets the timeout.
+     * 
+     * @param timeout the timeout
+     */
+    public void setTimeout( long timeout )
+    {
+        this.timeout = timeout;
+    }
+
+
     /**
      * Creates a unique id.
      * 

Modified: directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java?rev=1805170&r1=1805169&r2=1805170&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java (original)
+++ directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java Wed Aug 16 10:44:25 2017
@@ -26,7 +26,6 @@ import java.io.OutputStream;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
 
 import org.apache.directory.api.ldap.model.constants.SaslQoP;
@@ -79,6 +78,7 @@ public class ConnectionIO
     private static final String KRB5_KDC_HOST_TAG = "krb5KdcHost"; //$NON-NLS-1$
     private static final String KRB5_KDC_PORT_TAG = "krb5KdcPort"; //$NON-NLS-1$
     private static final String READ_ONLY_TAG = "readOnly"; //$NON-NLS-1$
+    private static final String TIMEOUT_TAG = "timeout"; //$NON-NLS-1$
 
     private static final String EXTENDED_PROPERTIES_TAG = "extendedProperties"; //$NON-NLS-1$
     private static final String EXTENDED_PROPERTY_TAG = "extendedProperty"; //$NON-NLS-1$
@@ -94,16 +94,13 @@ public class ConnectionIO
     /**
      * Loads the connections using the reader
      *
-     * @param stream
-     *      the FileInputStream
-     * @return
-     *      the connections
-     * @throws ConnectionIOException 
-     *      if an error occurs when converting the document
+     * @param stream the FileInputStream
+     * @return the connections
+     * @throws ConnectionIOException if an error occurs when converting the document
      */
     public static Set<ConnectionParameter> load( InputStream stream ) throws ConnectionIOException
     {
-        Set<ConnectionParameter> connections = new HashSet<ConnectionParameter>();
+        Set<ConnectionParameter> connections = new HashSet<>();
 
         SAXReader saxReader = new SAXReader();
         Document document = null;
@@ -136,12 +133,9 @@ public class ConnectionIO
     /**
      * Reads a connection from the given Element.
      *
-     * @param element
-     *      the element
-     * @return
-     *      the corresponding connection
-     * @throws ConnectionIOException
-     *      if an error occurs when converting values
+     * @param element the element
+     * @return the corresponding connection
+     * @throws ConnectionIOException if an error occurs when converting values
      */
     private static ConnectionParameter readConnection( Element element ) throws ConnectionIOException
     {
@@ -149,6 +143,7 @@ public class ConnectionIO
 
         // ID
         Attribute idAttribute = element.attribute( ID_TAG );
+        
         if ( idAttribute != null )
         {
             connection.setId( idAttribute.getValue() );
@@ -156,6 +151,7 @@ public class ConnectionIO
 
         // Name
         Attribute nameAttribute = element.attribute( NAME_TAG );
+        
         if ( nameAttribute != null )
         {
             connection.setName( nameAttribute.getValue() );
@@ -163,6 +159,7 @@ public class ConnectionIO
 
         // Host        
         Attribute hostAttribute = element.attribute( HOST_TAG );
+        
         if ( hostAttribute != null )
         {
             connection.setHost( hostAttribute.getValue() );
@@ -170,6 +167,7 @@ public class ConnectionIO
 
         // Port
         Attribute portAttribute = element.attribute( PORT_TAG );
+        
         if ( portAttribute != null )
         {
             try
@@ -182,9 +180,26 @@ public class ConnectionIO
                     + "' as int value. Port value :" + portAttribute.getValue() ); //$NON-NLS-1$
             }
         }
+        
+        // Timeout
+        Attribute timeoutAttribute = element.attribute( TIMEOUT_TAG );
+        
+        if ( timeoutAttribute != null )
+        {
+            try
+            {
+                connection.setTimeout( Long.parseLong( timeoutAttribute.getValue() ) );
+            }
+            catch ( NumberFormatException e )
+            {
+                throw new ConnectionIOException( "Unable to parse 'Timeout' of connection '" + connection.getName() //$NON-NLS-1$
+                    + "' as int value. Timeout value :" + timeoutAttribute.getValue() ); //$NON-NLS-1$
+            }
+        }
 
         // Encryption Method
         Attribute encryptionMethodAttribute = element.attribute( ENCRYPTION_METHOD_TAG );
+        
         if ( encryptionMethodAttribute != null )
         {
             try
@@ -201,6 +216,7 @@ public class ConnectionIO
 
         // Network Provider
         Attribute networkProviderAttribute = element.attribute( NETWORK_PROVIDER_TAG );
+        
         if ( networkProviderAttribute != null )
         {
             try
@@ -221,6 +237,7 @@ public class ConnectionIO
 
         // Auth Method
         Attribute authMethodAttribute = element.attribute( AUTH_METHOD_TAG );
+        
         if ( authMethodAttribute != null )
         {
             try
@@ -237,6 +254,7 @@ public class ConnectionIO
 
         // Bind Principal        
         Attribute bindPrincipalAttribute = element.attribute( BIND_PRINCIPAL_TAG );
+        
         if ( bindPrincipalAttribute != null )
         {
             connection.setBindPrincipal( bindPrincipalAttribute.getValue() );
@@ -244,6 +262,7 @@ public class ConnectionIO
 
         // Bind Password
         Attribute bindPasswordAttribute = element.attribute( BIND_PASSWORD_TAG );
+        
         if ( bindPasswordAttribute != null )
         {
             connection.setBindPassword( bindPasswordAttribute.getValue() );
@@ -251,6 +270,7 @@ public class ConnectionIO
 
         // SASL Realm
         Attribute saslRealmAttribute = element.attribute( SASL_REALM_TAG );
+        
         if ( saslRealmAttribute != null )
         {
             connection.setSaslRealm( saslRealmAttribute.getValue() );
@@ -258,6 +278,7 @@ public class ConnectionIO
 
         // SASL Quality of Protection
         Attribute saslQopAttribute = element.attribute( SASL_QOP_TAG );
+        
         if ( saslQopAttribute != null )
         {
             if ( "AUTH_INT_PRIV".equals( saslQopAttribute.getValue() ) ) //$NON-NLS-1$
@@ -282,6 +303,7 @@ public class ConnectionIO
 
         // SASL Security Strength
         Attribute saslSecStrengthAttribute = element.attribute( SASL_SEC_STRENGTH_TAG );
+        
         if ( saslSecStrengthAttribute != null )
         {
             try
@@ -299,6 +321,7 @@ public class ConnectionIO
 
         // SASL Mutual Authentication
         Attribute saslMutualAuthAttribute = element.attribute( SASL_MUTUAL_AUTH_TAG );
+        
         if ( saslMutualAuthAttribute != null )
         {
             connection.setSaslMutualAuthentication( Boolean.parseBoolean( saslMutualAuthAttribute.getValue() ) );
@@ -306,6 +329,7 @@ public class ConnectionIO
 
         // KRB5 Credentials Conf
         Attribute krb5CredentialsConf = element.attribute( KRB5_CREDENTIALS_CONF_TAG );
+        
         if ( krb5CredentialsConf != null )
         {
             try
@@ -323,6 +347,7 @@ public class ConnectionIO
 
         // KRB5 Configuration
         Attribute krb5Config = element.attribute( KRB5_CONFIG_TAG );
+        
         if ( krb5Config != null )
         {
             try
@@ -339,6 +364,7 @@ public class ConnectionIO
 
         // KRB5 Configuration File
         Attribute krb5ConfigFile = element.attribute( KRB5_CONFIG_FILE_TAG );
+        
         if ( krb5ConfigFile != null )
         {
             connection.setKrb5ConfigurationFile( krb5ConfigFile.getValue() );
@@ -346,6 +372,7 @@ public class ConnectionIO
 
         // KRB5 REALM
         Attribute krb5Realm = element.attribute( KRB5_REALM_TAG );
+        
         if ( krb5Realm != null )
         {
             connection.setKrb5Realm( krb5Realm.getValue() );
@@ -353,6 +380,7 @@ public class ConnectionIO
 
         // KRB5 KDC Host
         Attribute krb5KdcHost = element.attribute( KRB5_KDC_HOST_TAG );
+        
         if ( krb5KdcHost != null )
         {
             connection.setKrb5KdcHost( krb5KdcHost.getValue() );
@@ -360,6 +388,7 @@ public class ConnectionIO
 
         // KRB5 KDC Port
         Attribute krb5KdcPort = element.attribute( KRB5_KDC_PORT_TAG );
+        
         if ( krb5KdcPort != null )
         {
             try
@@ -376,6 +405,7 @@ public class ConnectionIO
 
         // Read Only
         Attribute readOnly = element.attribute( READ_ONLY_TAG );
+        
         if ( readOnly != null )
         {
             connection.setReadOnly( Boolean.parseBoolean( readOnly.getValue() ) );
@@ -383,11 +413,12 @@ public class ConnectionIO
 
         // Extended Properties
         Element extendedPropertiesElement = element.element( EXTENDED_PROPERTIES_TAG );
+        
         if ( extendedPropertiesElement != null )
         {
-            for ( Iterator<?> i = extendedPropertiesElement.elementIterator( EXTENDED_PROPERTY_TAG ); i.hasNext(); )
+        		for ( Object elementObject : extendedPropertiesElement.elements( EXTENDED_PROPERTY_TAG ) )
             {
-                Element extendedPropertyElement = ( Element ) i.next();
+                Element extendedPropertyElement = ( Element ) elementObject;
 
                 Attribute keyAttribute = extendedPropertyElement.attribute( KEY_TAG );
                 Attribute valueAttribute = extendedPropertyElement.attribute( VALUE_TAG );
@@ -406,12 +437,9 @@ public class ConnectionIO
     /**
      * Saves the connections using the writer.
      *
-     * @param connections
-     *      the connections
-     * @param stream
-     *      the OutputStream
-     * @throws IOException
-     *      if an I/O error occurs
+     * @param connections the connections
+     * @param stream the OutputStream
+     * @throws IOException if an I/O error occurs
      */
     public static void save( Set<ConnectionParameter> connections, OutputStream stream ) throws IOException
     {
@@ -460,7 +488,7 @@ public class ConnectionIO
         connectionElement.addAttribute( HOST_TAG, connection.getHost() );
 
         // Port
-        connectionElement.addAttribute( PORT_TAG, "" + connection.getPort() ); //$NON-NLS-1$
+        connectionElement.addAttribute( PORT_TAG, Integer.toString( connection.getPort() ) ); //$NON-NLS-1$
 
         // Encryption Method
         connectionElement.addAttribute( ENCRYPTION_METHOD_TAG, connection.getEncryptionMethod().toString() );
@@ -487,7 +515,7 @@ public class ConnectionIO
         connectionElement.addAttribute( SASL_SEC_STRENGTH_TAG, connection.getSaslSecurityStrength().toString() );
 
         // SASL Mutual Authentication
-        connectionElement.addAttribute( SASL_MUTUAL_AUTH_TAG, "" + connection.isSaslMutualAuthentication() ); //$NON-NLS-1$
+        connectionElement.addAttribute( SASL_MUTUAL_AUTH_TAG, Boolean.toString( connection.isSaslMutualAuthentication() ) ); //$NON-NLS-1$
 
         // KRB5 Credentials Conf
         connectionElement.addAttribute( KRB5_CREDENTIALS_CONF_TAG, connection.getKrb5CredentialConfiguration()
@@ -506,20 +534,22 @@ public class ConnectionIO
         connectionElement.addAttribute( KRB5_KDC_HOST_TAG, connection.getKrb5KdcHost() );
 
         // KRB5 KDC Port
-        connectionElement.addAttribute( KRB5_KDC_PORT_TAG, "" + connection.getKrb5KdcPort() ); //$NON-NLS-1$
+        connectionElement.addAttribute( KRB5_KDC_PORT_TAG, Integer.toString( connection.getKrb5KdcPort() ) ); //$NON-NLS-1$
 
         // Read Only
-        connectionElement.addAttribute( READ_ONLY_TAG, "" + connection.isReadOnly() ); //$NON-NLS-1$
+        connectionElement.addAttribute( READ_ONLY_TAG, Boolean.toString( connection.isReadOnly() ) ); //$NON-NLS-1$
+        
+        // Connection timeout
+        connectionElement.addAttribute( TIMEOUT_TAG, Long.toString( connection.getTimeout() ) ); //$NON-NLS-1$
 
         // Extended Properties
         Element extendedPropertiesElement = connectionElement.addElement( EXTENDED_PROPERTIES_TAG );
         Map<String, String> extendedProperties = connection.getExtendedProperties();
+        
         if ( extendedProperties != null )
         {
-            for ( Iterator<Entry<String, String>> iter = extendedProperties.entrySet().iterator(); iter.hasNext(); )
+        	    for ( Map.Entry<String, String> element : extendedProperties.entrySet() )
             {
-                Map.Entry<String, String> element = ( Map.Entry<String, String> ) iter.next();
-
                 Element extendedPropertyElement = extendedPropertiesElement.addElement( EXTENDED_PROPERTY_TAG );
                 extendedPropertyElement.addAttribute( KEY_TAG, element.getKey() );
                 extendedPropertyElement.addAttribute( VALUE_TAG, element.getValue() );
@@ -531,16 +561,13 @@ public class ConnectionIO
     /**
      * Loads the connection folders using the reader
      *
-     * @param stream
-     *      the FileInputStream
-     * @return
-     *      the connection folders
-     * @throws ConnectionIOException 
-     *      if an error occurs when converting the document
+     * @param stream the FileInputStream
+     * @return the connection folders
+     * @throws ConnectionIOException if an error occurs when converting the document
      */
     public static Set<ConnectionFolder> loadConnectionFolders( InputStream stream ) throws ConnectionIOException
     {
-        Set<ConnectionFolder> connectionFolders = new HashSet<ConnectionFolder>();
+        Set<ConnectionFolder> connectionFolders = new HashSet<>();
 
         SAXReader saxReader = new SAXReader();
         Document document = null;
@@ -573,14 +600,10 @@ public class ConnectionIO
     /**
      * Reads a connection folder from the given Element.
      *
-     * @param element
-     *      the element
-     * @return
-     *      the corresponding connection folder
-     * @throws ConnectionIOException
-     *      if an error occurs when converting values
+     * @param element the element
+     * @return the corresponding connection folder
      */
-    private static ConnectionFolder readConnectionFolder( Element element ) throws ConnectionIOException
+    private static ConnectionFolder readConnectionFolder( Element element )
     {
         ConnectionFolder connectionFolder = new ConnectionFolder();
 
@@ -593,6 +616,7 @@ public class ConnectionIO
 
         // Name
         Attribute nameAttribute = element.attribute( NAME_TAG );
+        
         if ( nameAttribute != null )
         {
             connectionFolder.setName( nameAttribute.getValue() );
@@ -600,6 +624,7 @@ public class ConnectionIO
 
         // Connections
         Element connectionsElement = element.element( CONNECTIONS_TAG );
+        
         if ( connectionsElement != null )
         {
             for ( Iterator<?> i = connectionsElement.elementIterator( CONNECTION_TAG ); i.hasNext(); )
@@ -617,6 +642,7 @@ public class ConnectionIO
 
         // Sub-folders
         Element foldersElement = element.element( SUB_FOLDERS_TAG );
+        
         if ( foldersElement != null )
         {
             for ( Iterator<?> i = foldersElement.elementIterator( SUB_FOLDER_TAG ); i.hasNext(); )
@@ -639,12 +665,9 @@ public class ConnectionIO
     /**
      * Saves the connection folders using the writer.
      *
-     * @param connectionFolders
-     *      the connection folders
-     * @param stream
-     *      the OutputStream
-     * @throws IOException
-     *      if an I/O error occurs
+     * @param connectionFolders the connection folders
+     * @param stream the OutputStream
+     * @throws IOException if an I/O error occurs
      */
     public static void saveConnectionFolders( Set<ConnectionFolder> connectionFolders, OutputStream stream )
         throws IOException
@@ -675,10 +698,8 @@ public class ConnectionIO
     /**
      * Adds the given connection folder to the given parent Element.
      *
-     * @param parent
-     *      the parent Element
-     * @param connectionFolder
-     *      the connection folder
+     * @param parent the parent Element
+     * @param connectionFolder the connection folder
      */
     private static void addFolderConnection( Element parent, ConnectionFolder connectionFolder )
     {
@@ -692,6 +713,7 @@ public class ConnectionIO
 
         // Connections
         Element connectionsElement = connectionFolderElement.addElement( CONNECTIONS_TAG );
+        
         for ( String connectionId : connectionFolder.getConnectionIds() )
         {
             Element connectionElement = connectionsElement.addElement( CONNECTION_TAG );
@@ -700,11 +722,11 @@ public class ConnectionIO
 
         // Sub-folders
         Element foldersElement = connectionFolderElement.addElement( SUB_FOLDERS_TAG );
+        
         for ( String folderId : connectionFolder.getSubFolderIds() )
         {
             Element folderElement = foldersElement.addElement( SUB_FOLDER_TAG );
             folderElement.addAttribute( ID_TAG, folderId );
         }
     }
-
 }

Modified: directory/studio/branches/studio-value/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-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java?rev=1805170&r1=1805169&r2=1805170&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java (original)
+++ directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java Wed Aug 16 10:44:25 2017
@@ -49,6 +49,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.entry.DefaultModification;
 import org.apache.directory.api.ldap.model.entry.Modification;
 import org.apache.directory.api.ldap.model.entry.ModificationOperation;
+import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.api.ldap.model.exception.LdapURLEncodingException;
 import org.apache.directory.api.ldap.model.filter.ExprNode;
@@ -83,6 +84,7 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.SaslCramMd5Request;
 import org.apache.directory.ldap.client.api.SaslDigestMd5Request;
 import org.apache.directory.ldap.client.api.SaslGssApiRequest;
+import org.apache.directory.ldap.client.api.SaslPlainRequest;
 import org.apache.directory.ldap.client.api.exception.InvalidConnectionException;
 import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.connection.core.Connection;
@@ -115,7 +117,7 @@ import org.eclipse.osgi.util.NLS;
 public class DirectoryApiConnectionWrapper implements ConnectionWrapper
 {
     /** The search request number */
-    private static int SEARCH_RESQUEST_NUM = 0;
+    private static int searchRequestNum = 0;
 
     /** The connection*/
     private Connection connection;
@@ -141,6 +143,9 @@ public class DirectoryApiConnectionWrapp
     /** The bind password */
     private String bindPassword;
 
+    /** The SASL PLAIN authzid */
+    private String authzId;
+
 
     /**
      * Creates a new instance of JNDIConnectionContext.
@@ -182,8 +187,19 @@ public class DirectoryApiConnectionWrapp
         ldapConnectionConfig = new LdapConnectionConfig();
         ldapConnectionConfig.setLdapHost( connection.getHost() );
         ldapConnectionConfig.setLdapPort( connection.getPort() );
+        
+        long timeout = connection.getTimeout();
+        
+        if ( timeout < 0 ) 
+        {
+        		timeout = 30000L;
+        }
+        
+        ldapConnectionConfig.setTimeout( timeout );
+        
         binaryAttributeDetector = new DefaultConfigurableBinaryAttributeDetector();
         ldapConnectionConfig.setBinaryAttributeDetector( binaryAttributeDetector );
+        
         if ( ( connection.getEncryptionMethod() == EncryptionMethod.LDAPS )
             || ( connection.getEncryptionMethod() == EncryptionMethod.START_TLS ) )
         {
@@ -200,6 +216,7 @@ public class DirectoryApiConnectionWrapp
 
                 // create wrappers around the trust managers
                 StudioTrustManager[] trustManagers = new StudioTrustManager[defaultTrustManagers.length];
+        
                 for ( int i = 0; i < defaultTrustManagers.length; i++ )
                 {
                     trustManagers[i] = new StudioTrustManager( ( X509TrustManager ) defaultTrustManagers[i] );
@@ -228,6 +245,7 @@ public class DirectoryApiConnectionWrapp
                     // Connecting
                     ldapConnection = new LdapNetworkConnection( ldapConnectionConfig );
                     boolean connected = ldapConnection.connect();
+                    
                     if ( !connected )
                     {
                         throw new Exception( Messages.DirectoryApiConnectionWrapper_UnableToConnect );
@@ -239,6 +257,7 @@ public class DirectoryApiConnectionWrapp
                 catch ( Exception e )
                 {
                     exception = e;
+                    
                     try
                     {
                         if ( ldapConnection != null )
@@ -312,6 +331,32 @@ public class DirectoryApiConnectionWrapp
         }
     }
 
+    
+    private BindResponse bindSimple( String bindPrincipal, String bindPassword ) throws LdapException
+    {
+        BindRequest bindRequest = new BindRequestImpl();
+        bindRequest.setName( bindPrincipal );
+        bindRequest.setCredentials( bindPassword );
+        
+        return ldapConnection.bind( bindRequest );
+    }
+    
+    
+    private BindResponse bindSaslPlain() throws LdapException
+    {
+        SaslPlainRequest saslPlainRequest = new SaslPlainRequest();
+        saslPlainRequest.setUsername( bindPrincipal );
+        saslPlainRequest.setCredentials( bindPassword );
+        saslPlainRequest.setAuthorizationId( authzId );
+        saslPlainRequest
+            .setQualityOfProtection( connection.getConnectionParameter().getSaslQop() );
+        saslPlainRequest.setSecurityStrength( connection.getConnectionParameter()
+            .getSaslSecurityStrength() );
+        saslPlainRequest.setMutualAuthentication( connection.getConnectionParameter()
+            .isSaslMutualAuthentication() );
+        
+        return ldapConnection.bindSaslPlain( bindPrincipal, bindPassword, authzId );
+    }
 
     private void doBind( final StudioProgressMonitor monitor ) throws Exception
     {
@@ -359,92 +404,98 @@ public class DirectoryApiConnectionWrapp
                             bindPrincipal = credentials.getBindPrincipal();
                             bindPassword = credentials.getBindPassword();
 
-                            // Simple Authentication
-                            if ( connection.getConnectionParameter().getAuthMethod() == ConnectionParameter.AuthenticationMethod.SIMPLE )
-                            {
-                                BindRequest bindRequest = new BindRequestImpl();
-                                bindRequest.setName( bindPrincipal );
-                                bindRequest.setCredentials( bindPassword );
-                                bindResponse = ldapConnection.bind( bindRequest );
-                            }
-                            // CRAM-MD5 Authentication
-                            else if ( connection.getConnectionParameter().getAuthMethod() == ConnectionParameter.AuthenticationMethod.SASL_CRAM_MD5 )
-                            {
-                                SaslCramMd5Request cramMd5Request = new SaslCramMd5Request();
-                                cramMd5Request.setUsername( bindPrincipal );
-                                cramMd5Request.setCredentials( bindPassword );
-                                cramMd5Request
-                                    .setQualityOfProtection( connection.getConnectionParameter().getSaslQop() );
-                                cramMd5Request.setSecurityStrength( connection.getConnectionParameter()
-                                    .getSaslSecurityStrength() );
-                                cramMd5Request.setMutualAuthentication( connection.getConnectionParameter()
-                                    .isSaslMutualAuthentication() );
-
-                                bindResponse = ldapConnection.bind( cramMd5Request );
-                            }
-                            // DIGEST-MD5 Authentication
-                            else if ( connection.getConnectionParameter().getAuthMethod() == ConnectionParameter.AuthenticationMethod.SASL_DIGEST_MD5 )
+                            switch ( connection.getConnectionParameter().getAuthMethod() )
                             {
-                                SaslDigestMd5Request digestMd5Request = new SaslDigestMd5Request();
-                                digestMd5Request.setUsername( bindPrincipal );
-                                digestMd5Request.setCredentials( bindPassword );
-                                digestMd5Request.setRealmName( connection.getConnectionParameter().getSaslRealm() );
-                                digestMd5Request.setQualityOfProtection( connection.getConnectionParameter()
-                                    .getSaslQop() );
-                                digestMd5Request.setSecurityStrength( connection.getConnectionParameter()
-                                    .getSaslSecurityStrength() );
-                                digestMd5Request.setMutualAuthentication( connection.getConnectionParameter()
-                                    .isSaslMutualAuthentication() );
-
-                                bindResponse = ldapConnection.bind( digestMd5Request );
-                            }
-                            // GSSAPI Authentication
-                            else if ( connection.getConnectionParameter().getAuthMethod() == ConnectionParameter.AuthenticationMethod.SASL_GSSAPI )
-                            {
-                                SaslGssApiRequest gssApiRequest = new SaslGssApiRequest();
+                                case SIMPLE :
+                                    // Simple Authentication
+                                    bindResponse = bindSimple( bindPrincipal, bindPassword );
+                                    
+                                    break;
+                                    
+                                case SASL_PLAIN :
+                                    // SASL Plain authentication
+                                    bindResponse = bindSaslPlain();
+
+                                    break;
+                                    
+                                case SASL_CRAM_MD5 :
+                                    // CRAM-MD5 Authentication
+                                    SaslCramMd5Request cramMd5Request = new SaslCramMd5Request();
+                                    cramMd5Request.setUsername( bindPrincipal );
+                                    cramMd5Request.setCredentials( bindPassword );
+                                    cramMd5Request
+                                        .setQualityOfProtection( connection.getConnectionParameter().getSaslQop() );
+                                    cramMd5Request.setSecurityStrength( connection.getConnectionParameter()
+                                        .getSaslSecurityStrength() );
+                                    cramMd5Request.setMutualAuthentication( connection.getConnectionParameter()
+                                        .isSaslMutualAuthentication() );
 
-                                Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences();
-                                boolean useKrb5SystemProperties = preferences
-                                    .getBoolean( ConnectionCoreConstants.PREFERENCE_USE_KRB5_SYSTEM_PROPERTIES );
-                                String krb5LoginModule = preferences
-                                    .getString( ConnectionCoreConstants.PREFERENCE_KRB5_LOGIN_MODULE );
-
-                                if ( !useKrb5SystemProperties )
-                                {
-                                    gssApiRequest.setUsername( bindPrincipal );
-                                    gssApiRequest.setCredentials( bindPassword );
-                                    gssApiRequest.setQualityOfProtection( connection
-                                        .getConnectionParameter().getSaslQop() );
-                                    gssApiRequest.setSecurityStrength( connection
-                                        .getConnectionParameter()
+                                    bindResponse = ldapConnection.bind( cramMd5Request );
+                                    break;
+                                    
+                                case SASL_DIGEST_MD5 :
+                                    // DIGEST-MD5 Authentication
+                                    SaslDigestMd5Request digestMd5Request = new SaslDigestMd5Request();
+                                    digestMd5Request.setUsername( bindPrincipal );
+                                    digestMd5Request.setCredentials( bindPassword );
+                                    digestMd5Request.setRealmName( connection.getConnectionParameter().getSaslRealm() );
+                                    digestMd5Request.setQualityOfProtection( connection.getConnectionParameter()
+                                        .getSaslQop() );
+                                    digestMd5Request.setSecurityStrength( connection.getConnectionParameter()
                                         .getSaslSecurityStrength() );
-                                    gssApiRequest.setMutualAuthentication( connection
-                                        .getConnectionParameter()
+                                    digestMd5Request.setMutualAuthentication( connection.getConnectionParameter()
                                         .isSaslMutualAuthentication() );
-                                    gssApiRequest
-                                        .setLoginModuleConfiguration( new InnerConfiguration(
-                                            krb5LoginModule ) );
 
-                                    switch ( connection.getConnectionParameter().getKrb5Configuration() )
+                                    bindResponse = ldapConnection.bind( digestMd5Request );
+                                    break;
+                                    
+                                case SASL_GSSAPI :
+                                    // GSSAPI Authentication
+                                    SaslGssApiRequest gssApiRequest = new SaslGssApiRequest();
+
+                                    Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences();
+                                    boolean useKrb5SystemProperties = preferences
+                                        .getBoolean( ConnectionCoreConstants.PREFERENCE_USE_KRB5_SYSTEM_PROPERTIES );
+                                    String krb5LoginModule = preferences
+                                        .getString( ConnectionCoreConstants.PREFERENCE_KRB5_LOGIN_MODULE );
+
+                                    if ( !useKrb5SystemProperties )
                                     {
-                                        case FILE:
-                                            gssApiRequest.setKrb5ConfFilePath( connection.getConnectionParameter()
-                                                .getKrb5ConfigurationFile() );
-                                            break;
-                                        case MANUAL:
-                                            gssApiRequest.setRealmName( connection.getConnectionParameter()
-                                                .getKrb5Realm() );
-                                            gssApiRequest.setKdcHost( connection.getConnectionParameter()
-                                                .getKrb5KdcHost() );
-                                            gssApiRequest.setKdcPort( connection.getConnectionParameter()
-                                                .getKrb5KdcPort() );
-                                            break;
-                                        default:
-                                            break;
+                                        gssApiRequest.setUsername( bindPrincipal );
+                                        gssApiRequest.setCredentials( bindPassword );
+                                        gssApiRequest.setQualityOfProtection( connection
+                                            .getConnectionParameter().getSaslQop() );
+                                        gssApiRequest.setSecurityStrength( connection
+                                            .getConnectionParameter()
+                                            .getSaslSecurityStrength() );
+                                        gssApiRequest.setMutualAuthentication( connection
+                                            .getConnectionParameter()
+                                            .isSaslMutualAuthentication() );
+                                        gssApiRequest
+                                            .setLoginModuleConfiguration( new InnerConfiguration(
+                                                krb5LoginModule ) );
+
+                                        switch ( connection.getConnectionParameter().getKrb5Configuration() )
+                                        {
+                                            case FILE:
+                                                gssApiRequest.setKrb5ConfFilePath( connection.getConnectionParameter()
+                                                    .getKrb5ConfigurationFile() );
+                                                break;
+                                            case MANUAL:
+                                                gssApiRequest.setRealmName( connection.getConnectionParameter()
+                                                    .getKrb5Realm() );
+                                                gssApiRequest.setKdcHost( connection.getConnectionParameter()
+                                                    .getKrb5KdcHost() );
+                                                gssApiRequest.setKdcPort( connection.getConnectionParameter()
+                                                    .getKrb5KdcPort() );
+                                                break;
+                                            default:
+                                                break;
+                                        }
                                     }
-                                }
 
-                                bindResponse = ldapConnection.bind( gssApiRequest );
+                                    bindResponse = ldapConnection.bind( gssApiRequest );
+                                    break;
                             }
                         }
 
@@ -497,7 +548,7 @@ public class DirectoryApiConnectionWrapp
         if ( binaryAttributeDetector != null )
         {
             // Clear the initial list
-            binaryAttributeDetector.setBinaryAttributes( new String[0] );
+            binaryAttributeDetector.setBinaryAttributes();
 
             // Add each binary attribute
             for ( String binaryAttribute : binaryAttributes )
@@ -516,7 +567,7 @@ public class DirectoryApiConnectionWrapp
         final ReferralHandlingMethod referralsHandlingMethod, final Control[] controls,
         final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
     {
-        final long requestNum = SEARCH_RESQUEST_NUM++;
+        final long requestNum = searchRequestNum++;
 
         InnerRunnable runnable = new InnerRunnable()
         {
@@ -723,10 +774,10 @@ public class DirectoryApiConnectionWrapp
                     ModifyResponse modifyResponse = ldapConnection.modify( request );
 
                     // Handle referral
-                    Consumer<ReferralHandlingData> consumer = referralHandlingData -> {
+                    Consumer<ReferralHandlingData> consumer = referralHandlingData -> 
                         referralHandlingData.connectionWrapper.modifyEntry( referralHandlingData.referralDn,
                             modificationItems, controls, monitor, referralHandlingData.newReferralsInfo );
-                    };
+                    
                     if ( checkAndHandleReferral( modifyResponse, monitor, referralsInfo, consumer ) )
                     {
                         return;
@@ -787,7 +838,7 @@ public class DirectoryApiConnectionWrapp
     {
         if ( modificationItems != null )
         {
-            List<Modification> modifications = new ArrayList<Modification>();
+            List<Modification> modifications = new ArrayList<>();
 
             for ( ModificationItem modificationItem : modificationItems )
             {
@@ -866,10 +917,10 @@ public class DirectoryApiConnectionWrapp
                     ModifyDnResponse modifyDnResponse = ldapConnection.modifyDn( request );
 
                     // Handle referral
-                    Consumer<ReferralHandlingData> consumer = referralHandlingData -> {
+                    Consumer<ReferralHandlingData> consumer = referralHandlingData ->
                         referralHandlingData.connectionWrapper.renameEntry( oldDn, newDn, deleteOldRdn, controls,
                             monitor, referralHandlingData.newReferralsInfo );
-                    };
+                    
                     if ( checkAndHandleReferral( modifyDnResponse, monitor, referralsInfo, consumer ) )
                     {
                         return;
@@ -945,10 +996,10 @@ public class DirectoryApiConnectionWrapp
                     AddResponse addResponse = ldapConnection.add( request );
 
                     // Handle referral
-                    Consumer<ReferralHandlingData> consumer = referralHandlingData -> {
+                    Consumer<ReferralHandlingData> consumer = referralHandlingData ->
                         referralHandlingData.connectionWrapper.createEntry( referralHandlingData.referralDn, attributes,
                             controls, monitor, referralHandlingData.newReferralsInfo );
-                    };
+                        
                     if ( checkAndHandleReferral( addResponse, monitor, referralsInfo, consumer ) )
                     {
                         return;
@@ -1023,10 +1074,10 @@ public class DirectoryApiConnectionWrapp
                     DeleteResponse deleteResponse = ldapConnection.delete( request );
 
                     // Handle referral
-                    Consumer<ReferralHandlingData> consumer = referralHandlingData -> {
+                    Consumer<ReferralHandlingData> consumer = referralHandlingData -> 
                         referralHandlingData.connectionWrapper.deleteEntry( referralHandlingData.referralDn, controls,
                             monitor, referralHandlingData.newReferralsInfo );
-                    };
+                    
                     if ( checkAndHandleReferral( deleteResponse, monitor, referralsInfo, consumer ) )
                     {
                         return;
@@ -1159,7 +1210,7 @@ public class DirectoryApiConnectionWrapp
             return true;
         }
 
-        List<String> urls = new ArrayList<String>( referral.getLdapUrls() );
+        List<String> urls = new ArrayList<>( referral.getLdapUrls() );
         String referralDn = new LdapUrl( urls.get( 0 ) ).getDn().getName();
         ReferralHandlingData referralHandlingData = new ReferralHandlingData( referralConnection.getConnectionWrapper(),
             referralDn, referralsInfo );
@@ -1205,7 +1256,7 @@ public class DirectoryApiConnectionWrapp
             runAndMonitor( runnable, monitor );
 
             // check reconnection
-            if ( ( i == 0 ) && ( ( runnable.getException() instanceof InvalidConnectionException ) ) )
+            if ( ( i == 0 ) && ( runnable.getException() instanceof InvalidConnectionException ) )
             {
                 doConnect( monitor );
                 doBind( monitor );
@@ -1225,9 +1276,7 @@ public class DirectoryApiConnectionWrapp
         if ( !monitor.isCanceled() )
         {
             // monitor
-            StudioProgressMonitor.CancelListener listener = new StudioProgressMonitor.CancelListener()
-            {
-                public void cancelRequested( StudioProgressMonitor.CancelEvent event )
+            StudioProgressMonitor.CancelListener listener = event ->
                 {
                     if ( monitor.isCanceled() )
                     {
@@ -1235,6 +1284,7 @@ public class DirectoryApiConnectionWrapp
                         {
                             jobThread.interrupt();
                         }
+                        
                         if ( ldapConnection != null )
                         {
                             try
@@ -1244,28 +1294,21 @@ public class DirectoryApiConnectionWrapp
                             catch ( Exception e )
                             {
                             }
+                            
                             isConnected = false;
                             ldapConnection = null;
                         }
+                        
                         isConnected = false;
                     }
-                }
-            };
+                };
+
             monitor.addCancelListener( listener );
             jobThread = Thread.currentThread();
 
             // run
             try
             {
-                // try {
-                // Thread.sleep(5000);
-                // } catch (InterruptedException e) {
-                // System.out.println(System.currentTimeMillis() + ": sleep
-                // interrupted!");
-                // }
-                // System.out.println(System.currentTimeMillis() + ": " +
-                // runnable);
-
                 runnable.run();
             }
             finally
@@ -1297,7 +1340,7 @@ public class DirectoryApiConnectionWrapp
         {
             if ( configList == null )
             {
-                HashMap<String, Object> options = new HashMap<String, Object>();
+                HashMap<String, Object> options = new HashMap<>();
 
                 // TODO: this only works for Sun JVM
                 options.put( "refreshKrb5Config", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
@@ -1319,6 +1362,7 @@ public class DirectoryApiConnectionWrapp
         }
 
 
+        @Override
         public void refresh()
         {
         }
@@ -1372,7 +1416,7 @@ public class DirectoryApiConnectionWrapp
                     }
 
                     throw new Exception( NLS.bind( "[LDAP: error code {0} - {1}]", new String[] //$NON-NLS-1$
-                        { code + "", message } ) ); //$NON-NLS-1$
+                        { Integer.toString( code ), message } ) ); //$NON-NLS-1$
                 }
             }
         }

Modified: directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java?rev=1805170&r1=1805169&r2=1805170&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java (original)
+++ directory/studio/branches/studio-value/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java Wed Aug 16 10:44:25 2017
@@ -50,8 +50,6 @@ import javax.naming.ldap.LdapContext;
 import javax.naming.ldap.LdapName;
 import javax.naming.ldap.StartTlsRequest;
 import javax.naming.ldap.StartTlsResponse;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLSession;
 import javax.security.auth.Subject;
 import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
@@ -136,7 +134,7 @@ public class JNDIConnectionWrapper imple
 
     private static final String JAVA_NAMING_LDAP_ATTRIBUTES_BINARY = "java.naming.ldap.attributes.binary"; //$NON-NLS-1$
 
-    private static int SEARCH_RESQUEST_NUM = 0;
+    private static int searchRequestNum = 0;
 
     private Connection connection;
 
@@ -286,12 +284,15 @@ public class JNDIConnectionWrapper imple
     public void setBinaryAttributes( Collection<String> binaryAttributes )
     {
         this.binaryAttributes = binaryAttributes;
-        String binaryAttributesString = StringUtils.EMPTY;
+        StringBuilder sb = new StringBuilder();
+        
         for ( String string : binaryAttributes )
         {
-            binaryAttributesString += string + ' ';
+        		sb.append( string ).append( ' ' );
         }
 
+        String binaryAttributesString = sb.toString();
+
         if ( environment != null )
         {
             environment.put( JAVA_NAMING_LDAP_ATTRIBUTES_BINARY, binaryAttributesString );
@@ -331,7 +332,7 @@ public class JNDIConnectionWrapper imple
         final ReferralHandlingMethod referralsHandlingMethod, final Control[] controls,
         final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
     {
-        final long requestNum = SEARCH_RESQUEST_NUM++;
+        final long requestNum = searchRequestNum++;
 
         // start
         InnerRunnable runnable = new InnerRunnable()
@@ -358,13 +359,7 @@ public class JNDIConnectionWrapper imple
                         searchBase, filter, searchControls, aliasesDereferencingMethod, referralsHandlingMethod,
                         controls, requestNum, monitor, referralsInfo );
                 }
-                catch ( PartialResultException e )
-                {
-                    namingEnumeration = new JndiStudioNamingEnumeration( connection, searchCtx, null, e, searchBase,
-                        filter, searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls,
-                        requestNum, monitor, referralsInfo );
-                }
-                catch ( ReferralException e )
+                catch ( PartialResultException | ReferralException e )
                 {
                     namingEnumeration = new JndiStudioNamingEnumeration( connection, searchCtx, null, e, searchBase,
                         filter, searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls,
@@ -441,7 +436,6 @@ public class JNDIConnectionWrapper imple
         {
             public void run()
             {
-                boolean logModification = true;
                 try
                 {
                     // create modify context
@@ -455,18 +449,18 @@ public class JNDIConnectionWrapper imple
                 }
                 catch ( ReferralException re )
                 {
-                    logModification = false;
                     try
                     {
                         ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
                         Referral referral = newReferralsInfo.getNextReferral();
+                        
                         if ( referral != null )
                         {
                             Connection referralConnection = ConnectionWrapperUtils.getReferralConnection( referral,
                                 monitor, this );
                             if ( referralConnection != null )
                             {
-                                List<String> urls = new ArrayList<String>( referral.getLdapUrls() );
+                                List<String> urls = new ArrayList<>( referral.getLdapUrls() );
 
                                 String referralDn = new LdapUrl( urls.get( 0 ) ).getDn().getName();
                                 referralConnection.getConnectionWrapper().modifyEntry( referralDn,
@@ -494,12 +488,9 @@ public class JNDIConnectionWrapper imple
                     namingException = ne;
                 }
 
-                if ( logModification )
+                for ( IJndiLogger logger : getJndiLoggers() )
                 {
-                    for ( IJndiLogger logger : getJndiLoggers() )
-                    {
-                        logger.logChangetypeModify( connection, dn, modificationItems, controls, namingException );
-                    }
+                    logger.logChangetypeModify( connection, dn, modificationItems, controls, namingException );
                 }
             }
         };
@@ -548,7 +539,6 @@ public class JNDIConnectionWrapper imple
         {
             public void run()
             {
-                boolean logModification = true;
                 try
                 {
                     // create modify context
@@ -572,7 +562,6 @@ public class JNDIConnectionWrapper imple
                 }
                 catch ( ReferralException re )
                 {
-                    logModification = false;
                     try
                     {
                         ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
@@ -602,12 +591,9 @@ public class JNDIConnectionWrapper imple
                     namingException = ne;
                 }
 
-                if ( logModification )
+                for ( IJndiLogger logger : getJndiLoggers() )
                 {
-                    for ( IJndiLogger logger : getJndiLoggers() )
-                    {
-                        logger.logChangetypeModDn( connection, oldDn, newDn, deleteOldRdn, controls, namingException );
-                    }
+                    logger.logChangetypeModDn( connection, oldDn, newDn, deleteOldRdn, controls, namingException );
                 }
             }
         };
@@ -655,7 +641,6 @@ public class JNDIConnectionWrapper imple
         {
             public void run()
             {
-                boolean logModification = true;
                 try
                 {
                     // create modify context
@@ -669,18 +654,19 @@ public class JNDIConnectionWrapper imple
                 }
                 catch ( ReferralException re )
                 {
-                    logModification = false;
                     try
                     {
                         ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
                         Referral referral = newReferralsInfo.getNextReferral();
+                        
                         if ( referral != null )
                         {
                             Connection referralConnection = ConnectionWrapperUtils.getReferralConnection( referral,
                                 monitor, this );
+                            
                             if ( referralConnection != null )
                             {
-                                List<String> urls = new ArrayList<String>( referral.getLdapUrls() );
+                                List<String> urls = new ArrayList<>( referral.getLdapUrls() );
 
                                 String referralDn = new LdapUrl( urls.get( 0 ) ).getDn().getName();
                                 referralConnection.getConnectionWrapper().createEntry( referralDn, attributes,
@@ -706,12 +692,9 @@ public class JNDIConnectionWrapper imple
                     namingException = ne;
                 }
 
-                if ( logModification )
+                for ( IJndiLogger logger : getJndiLoggers() )
                 {
-                    for ( IJndiLogger logger : getJndiLoggers() )
-                    {
-                        logger.logChangetypeAdd( connection, dn, attributes, controls, namingException );
-                    }
+                    logger.logChangetypeAdd( connection, dn, attributes, controls, namingException );
                 }
             }
         };
@@ -758,7 +741,6 @@ public class JNDIConnectionWrapper imple
         {
             public void run()
             {
-                boolean logModification = true;
                 try
                 {
                     // create modify context
@@ -772,7 +754,6 @@ public class JNDIConnectionWrapper imple
                 }
                 catch ( ReferralException re )
                 {
-                    logModification = false;
                     try
                     {
                         ReferralsInfo newReferralsInfo = handleReferralException( re, referralsInfo );
@@ -783,7 +764,7 @@ public class JNDIConnectionWrapper imple
                                 monitor, this );
                             if ( referralConnection != null )
                             {
-                                List<String> urls = new ArrayList<String>( referral.getLdapUrls() );
+                                List<String> urls = new ArrayList<>( referral.getLdapUrls() );
 
                                 String referralDn = new LdapUrl( urls.get( 0 ) ).getDn().getName();
                                 referralConnection.getConnectionWrapper().deleteEntry( referralDn, controls,
@@ -809,12 +790,9 @@ public class JNDIConnectionWrapper imple
                     namingException = ne;
                 }
 
-                if ( logModification )
+                for ( IJndiLogger logger : getJndiLoggers() )
                 {
-                    for ( IJndiLogger logger : getJndiLoggers() )
-                    {
-                        logger.logChangetypeDelete( connection, dn, controls, namingException );
-                    }
+                    logger.logChangetypeDelete( connection, dn, controls, namingException );
                 }
             }
         };
@@ -847,11 +825,12 @@ public class JNDIConnectionWrapper imple
         // setup connection parameters
         String host = connection.getConnectionParameter().getHost();
         int port = connection.getConnectionParameter().getPort();
+        long timeout = connection.getConnectionParameter().getTimeout();
 
         useLdaps = connection.getConnectionParameter().getEncryptionMethod() == ConnectionParameter.EncryptionMethod.LDAPS;
         useStartTLS = connection.getConnectionParameter().getEncryptionMethod() == ConnectionParameter.EncryptionMethod.START_TLS;
 
-        environment = new Hashtable<String, String>();
+        environment = new Hashtable<>();
         Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences();
         final boolean validateCertificates = preferences
             .getBoolean( ConnectionCoreConstants.PREFERENCE_VALIDATE_CERTIFICATES );
@@ -866,6 +845,16 @@ public class JNDIConnectionWrapper imple
         {
             environment.put( COM_SUN_JNDI_LDAP_CONNECT_TIMEOUT, "10000" ); //$NON-NLS-1$
         }
+        else
+        {
+        		if ( timeout < 0 )
+        		{
+        			timeout = 0;
+        		}
+        		
+            environment.put( COM_SUN_JNDI_LDAP_CONNECT_TIMEOUT, Long.toString( timeout ) ); //$NON-NLS-1$
+        }
+        
         environment.put( COM_SUN_JNDI_DNS_TIMEOUT_INITIAL, "2000" ); //$NON-NLS-1$
         environment.put( COM_SUN_JNDI_DNS_TIMEOUT_RETRIES, "3" ); //$NON-NLS-1$
 
@@ -904,13 +893,8 @@ public class JNDIConnectionWrapper imple
                                 .extendedOperation( new StartTlsRequest() );
                             // deactivate host name verification at this level,
                             // host name verification is done in StudioTrustManager
-                            tls.setHostnameVerifier( new HostnameVerifier()
-                            {
-                                public boolean verify( String hostname, SSLSession session )
-                                {
-                                    return true;
-                                }
-                            } );
+                            tls.setHostnameVerifier( ( hostname, session ) -> true );
+                            
                             if ( validateCertificates )
                             {
                                 tls.negotiate( StudioSSLSocketFactory.getDefault() );
@@ -1189,9 +1173,7 @@ public class JNDIConnectionWrapper imple
             }
 
             // Login to LDAP server, obtains a service ticket from KDC
-            Subject.doAs( lc.getSubject(), new PrivilegedAction<Object>()
-            {
-                public Object run()
+            Subject.doAs( lc.getSubject(), (PrivilegedAction<Object>)() -> 
                 {
                     try
                     {
@@ -1203,7 +1185,7 @@ public class JNDIConnectionWrapper imple
                     }
                     return null;
                 }
-            } );
+            );
         }
         finally
         {
@@ -1259,9 +1241,7 @@ public class JNDIConnectionWrapper imple
         if ( !monitor.isCanceled() )
         {
             // monitor
-            StudioProgressMonitor.CancelListener listener = new StudioProgressMonitor.CancelListener()
-            {
-                public void cancelRequested( StudioProgressMonitor.CancelEvent event )
+            StudioProgressMonitor.CancelListener listener = event -> 
                 {
                     if ( monitor.isCanceled() )
                     {
@@ -1269,6 +1249,7 @@ public class JNDIConnectionWrapper imple
                         {
                             jobThread.interrupt();
                         }
+                        
                         if ( context != null )
                         {
                             try
@@ -1278,28 +1259,21 @@ public class JNDIConnectionWrapper imple
                             catch ( NamingException ne )
                             {
                             }
+                            
                             isConnected = false;
                             context = null;
                         }
+                        
                         isConnected = false;
                     }
-                }
-            };
+                };
+            
             monitor.addCancelListener( listener );
             jobThread = Thread.currentThread();
 
             // run
             try
             {
-                // try {
-                // Thread.sleep(5000);
-                // } catch (InterruptedException e) {
-                // System.out.println(System.currentTimeMillis() + ": sleep
-                // interrupted!");
-                // }
-                // System.out.println(System.currentTimeMillis() + ": " +
-                // runnable);
-
                 runnable.run();
             }
             finally
@@ -1331,16 +1305,18 @@ public class JNDIConnectionWrapper imple
         {
             if ( configList == null )
             {
-                HashMap<String, Object> options = new HashMap<String, Object>();
+                HashMap<String, Object> options = new HashMap<>();
 
                 // TODO: this only works for Sun JVM
                 options.put( "refreshKrb5Config", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
+                
                 switch ( connection.getConnectionParameter().getKrb5CredentialConfiguration() )
                 {
                     case USE_NATIVE:
                         options.put( "useTicketCache", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
                         options.put( "doNotPrompt", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
                         break;
+                        
                     case OBTAIN_TGT:
                         options.put( "doNotPrompt", "false" ); //$NON-NLS-1$ //$NON-NLS-2$
                         break;
@@ -1352,7 +1328,8 @@ public class JNDIConnectionWrapper imple
             return configList;
         }
 
-
+        
+        @Override
         public void refresh()
         {
         }
@@ -1562,6 +1539,7 @@ public class JNDIConnectionWrapper imple
                         // in the latter case we null out the reference, a new one will be created by handleReferral()
                         referral = null;
                     }
+                    
                     referralException = ( ReferralException ) ne;
 
                     referral = handleReferralException( referralException, initialReferralsInfo, referral );
@@ -1578,7 +1556,7 @@ public class JNDIConnectionWrapper imple
 
 
     private static Referral handleReferralException( ReferralException referralException,
-        ReferralsInfo initialReferralsInfo, Referral referral ) throws NamingException
+        ReferralsInfo initialReferralsInfo, Referral referral )
     {
         String info = ( String ) referralException.getReferralInfo();
 



Mime
View raw message