You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2009/10/08 11:49:04 UTC

svn commit: r823103 - in /directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core: ./ model/

Author: seelmann
Date: Thu Oct  8 09:49:03 2009
New Revision: 823103

URL: http://svn.apache.org/viewvc?rev=823103&view=rev
Log:
Fix for DIRSTUDIO-495 (Cannot edit password field):
o Catch exception if password hash is no valid BASE64

Modified:
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreMessages.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages.properties
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_de.properties
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_fr.properties
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreMessages.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreMessages.java?rev=823103&r1=823102&r2=823103&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreMessages.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreMessages.java Thu Oct  8 09:49:03 2009
@@ -168,6 +168,8 @@
 
     public static String model__unsupported_hash;
 
+    public static String model__invalid_hash;
+
     public static String ldif__imported_n_entries_m_errors;
 
     public static String ldif__n_errors_see_logfile;

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages.properties?rev=823103&r1=823102&r2=823103&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages.properties (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages.properties Thu Oct  8 09:49:03 2009
@@ -98,6 +98,7 @@
 dsml__n_errors_see_responsefile={0} errors occurred, see response file for details
 
 model__unsupported_hash=Unsupported hash method
+model__invalid_hash=Invalid hash value
 model__url_no_protocol=No protocol
 model__url_no_attributes=No attributes
 model__url_no_extensions=No extensions

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_de.properties?rev=823103&r1=823102&r2=823103&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_de.properties (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_de.properties Thu Oct  8 09:49:03 2009
@@ -96,6 +96,7 @@
 dsml__n_errors_see_responsefile={0} Fehler sind aufgetreten, siehe Antwort-Datei f\u00FCr Details
 
 model__unsupported_hash=Nicht unterst\u00FCtze Hash Methode
+model__invalid_hash=Ung\u00FCltiger Hash Wert
 model__url_no_protocol=Kein Protokoll
 model__url_no_attributes=Keine Attribute
 model__url_no_extensions=Keine Erweiterungen

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_fr.properties?rev=823103&r1=823102&r2=823103&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_fr.properties (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/browsercoremessages_fr.properties Thu Oct  8 09:49:03 2009
@@ -98,6 +98,7 @@
 dsml__n_errors_see_responsefile={0} erreurs sont survenues, consulter le fichier de r\u00E9ponse pour les d\u00E9tails
 
 model__unsupported_hash=M\u00E9thode de hashage non support\u00E9e
+model__invalid_hash=TODO:Invalid hash value
 model__url_no_protocol=Pas de protocol
 model__url_no_attributes=Pas d'attributs
 model__url_no_extensions=Pas d'extensions

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java?rev=823103&r1=823102&r2=823103&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java Thu Oct  8 09:49:03 2009
@@ -70,6 +70,9 @@
 
     /** The constant used for unsupported hash methods */
     public static final String HASH_METHOD_UNSUPPORTED = BrowserCoreMessages.model__unsupported_hash;
+    
+    /** The constant used for invalid password hashes */
+    public static final String HASH_METHOD_INVALID = BrowserCoreMessages.model__invalid_hash;
 
     /** The hash method. */
     private String hashMethod;
@@ -108,43 +111,48 @@
         }
         else if ( password.indexOf( '{' ) == 0 && password.indexOf( '}' ) > 0 )
         {
-            hashMethod = password.substring( password.indexOf( '{' ) + 1, password.indexOf( '}' ) );
-            String rest = password.substring( hashMethod.length() + 2 );
-
-            if ( HASH_METHOD_SHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_MD5.equalsIgnoreCase( hashMethod ) )
-            {
-                hashedPassword = LdifUtils.base64decodeToByteArray( rest );
-                salt = null;
-            }
-            else if ( HASH_METHOD_SSHA.equalsIgnoreCase( hashMethod ) )
-            {
-                byte[] hashedPasswordWithSalt = LdifUtils.base64decodeToByteArray( rest );
-                hashedPassword = new byte[20];
-                salt = new byte[hashedPasswordWithSalt.length - hashedPassword.length];
-                split( hashedPasswordWithSalt, hashedPassword, salt );
-            }
-            else if ( HASH_METHOD_SMD5.equalsIgnoreCase( hashMethod ) )
+            try
             {
-                byte[] hashedPasswordWithSalt = LdifUtils.base64decodeToByteArray( rest );
-                hashedPassword = new byte[16];
-                salt = new byte[hashedPasswordWithSalt.length - hashedPassword.length];
-                split( hashedPasswordWithSalt, hashedPassword, salt );
-            }
-            else if ( HASH_METHOD_CRYPT.equalsIgnoreCase( hashMethod ) )
-            {
-                byte[] saltWithPassword = LdifUtils.utf8encode( rest );
-                salt = new byte[2];
-                hashedPassword = new byte[saltWithPassword.length - salt.length];
-                split( saltWithPassword, salt, hashedPassword );
+                hashMethod = password.substring( password.indexOf( '{' ) + 1, password.indexOf( '}' ) );
+                String rest = password.substring( hashMethod.length() + 2 );
+
+                if ( HASH_METHOD_SHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_MD5.equalsIgnoreCase( hashMethod ) )
+                {
+                    hashedPassword = LdifUtils.base64decodeToByteArray( rest );
+                    salt = null;
+                }
+                else if ( HASH_METHOD_SSHA.equalsIgnoreCase( hashMethod ) )
+                {
+                    byte[] hashedPasswordWithSalt = LdifUtils.base64decodeToByteArray( rest );
+                    hashedPassword = new byte[20];
+                    salt = new byte[hashedPasswordWithSalt.length - hashedPassword.length];
+                    split( hashedPasswordWithSalt, hashedPassword, salt );
+                }
+                else if ( HASH_METHOD_SMD5.equalsIgnoreCase( hashMethod ) )
+                {
+                    byte[] hashedPasswordWithSalt = LdifUtils.base64decodeToByteArray( rest );
+                    hashedPassword = new byte[16];
+                    salt = new byte[hashedPasswordWithSalt.length - hashedPassword.length];
+                    split( hashedPasswordWithSalt, hashedPassword, salt );
+                }
+                else if ( HASH_METHOD_CRYPT.equalsIgnoreCase( hashMethod ) )
+                {
+                    byte[] saltWithPassword = LdifUtils.utf8encode( rest );
+                    salt = new byte[2];
+                    hashedPassword = new byte[saltWithPassword.length - salt.length];
+                    split( saltWithPassword, salt, hashedPassword );
+                }
+                else
+                {
+                    hashMethod = HASH_METHOD_UNSUPPORTED;
+                    trash = password;
+                }
             }
-            else
+            catch ( RuntimeException e )
             {
-                // throw new IllegalArgumentException("Unsupported hash method
-                // '"+hashMethod+"'");
-                // handle as plain text?
-                hashMethod = HASH_METHOD_UNSUPPORTED;
+                // happens if 'rest' is not valid BASE64
+                hashMethod = HASH_METHOD_INVALID;
                 trash = password;
-                // salt = null;
             }
         }
         else
@@ -168,9 +176,10 @@
      */
     public Password( String hashMethod, String passwordAsPlaintext )
     {
-        if ( !( hashMethod == null || HASH_METHOD_NO.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SHA.equalsIgnoreCase( hashMethod )
-            || HASH_METHOD_SSHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_MD5.equalsIgnoreCase( hashMethod )
-            || HASH_METHOD_SMD5.equalsIgnoreCase( hashMethod ) || HASH_METHOD_CRYPT.equalsIgnoreCase( hashMethod ) ) )
+        if ( !( hashMethod == null || HASH_METHOD_NO.equalsIgnoreCase( hashMethod )
+            || HASH_METHOD_SHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SSHA.equalsIgnoreCase( hashMethod )
+            || HASH_METHOD_MD5.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SMD5.equalsIgnoreCase( hashMethod ) || HASH_METHOD_CRYPT
+            .equalsIgnoreCase( hashMethod ) ) )
         {
             throw new IllegalArgumentException( BrowserCoreMessages.model__unsupported_hash );
         }
@@ -338,7 +347,8 @@
     {
         StringBuffer sb = new StringBuffer();
 
-        if ( HASH_METHOD_UNSUPPORTED.equalsIgnoreCase( hashMethod ) )
+        if ( HASH_METHOD_UNSUPPORTED.equalsIgnoreCase( hashMethod )
+            || HASH_METHOD_INVALID.equalsIgnoreCase( hashMethod ) )
         {
             sb.append( trash );
         }