Ver Fonte

xodus/wordlist updates

jrivard@gmail.com há 6 anos atrás
pai
commit
e906462a63

+ 15 - 4
server/src/main/java/password/pwm/svc/wordlist/WordlistBucket.java

@@ -70,7 +70,7 @@ class WordlistBucket
         seedlistTopKey.set(
         seedlistTopKey.set(
                 StringUtil.isEmpty( valueOfLastKey )
                 StringUtil.isEmpty( valueOfLastKey )
                         ? 0
                         ? 0
-                        : Long.parseLong( valueOfLastKey )
+                        : seedlistKeyToLong( valueOfLastKey )
         );
         );
     }
     }
 
 
@@ -126,7 +126,7 @@ class WordlistBucket
             if ( seedCount > 1000 )
             if ( seedCount > 1000 )
             {
             {
                 final long randomKey = pwmApplication.getSecureService().pwmRandom().nextLong( seedCount );
                 final long randomKey = pwmApplication.getSecureService().pwmRandom().nextLong( seedCount );
-                return pwmApplication.getLocalDB().get( db, String.valueOf( randomKey ) );
+                return pwmApplication.getLocalDB().get( db, seedlistLongToKey( randomKey ) );
             }
             }
         }
         }
         catch ( Exception e )
         catch ( Exception e )
@@ -166,8 +166,10 @@ class WordlistBucket
                     final String normalizedWord = normalizeWord( word );
                     final String normalizedWord = normalizeWord( word );
                     if ( !StringUtil.isEmpty( normalizedWord ) )
                     if ( !StringUtil.isEmpty( normalizedWord ) )
                     {
                     {
-                        returnSet.put( String.valueOf( seedlistTopKey.incrementAndGet() ), normalizedWord );
-                        returnSet.put( KEY_LAST_ISSUED_KEY, String.valueOf( seedlistTopKey.get() ) );
+                        final long nextLong = seedlistTopKey.incrementAndGet();
+                        final String nextKey = seedlistLongToKey( nextLong );
+                        returnSet.put( nextKey, normalizedWord );
+                        returnSet.put( KEY_LAST_ISSUED_KEY, nextKey );
                     }
                     }
                 }
                 }
                 return Collections.unmodifiableMap( returnSet );
                 return Collections.unmodifiableMap( returnSet );
@@ -248,4 +250,13 @@ class WordlistBucket
         return testWords;
         return testWords;
     }
     }
 
 
+    private static long seedlistKeyToLong( final String key )
+    {
+        return Long.parseLong( key, 36 );
+    }
+
+    private static String seedlistLongToKey( final long longValue )
+    {
+        return Long.toString( longValue, 36 );
+    }
 }
 }

+ 1 - 1
server/src/main/java/password/pwm/svc/wordlist/WordlistStatus.java

@@ -32,7 +32,7 @@ import java.time.Instant;
 @Builder( toBuilder = true )
 @Builder( toBuilder = true )
 public class WordlistStatus implements Serializable
 public class WordlistStatus implements Serializable
 {
 {
-    public static final int CURRENT_VERSION = 3;
+    public static final int CURRENT_VERSION = 4;
 
 
     @Builder.Default
     @Builder.Default
     private int version = CURRENT_VERSION;
     private int version = CURRENT_VERSION;

+ 2 - 39
server/src/main/java/password/pwm/util/localdb/XodusLocalDB.java

@@ -138,20 +138,6 @@ public class XodusLocalDB implements LocalDBProvider
         LOGGER.trace( () -> "preparing to open with configuration " + JsonUtil.serializeMap( environmentConfig.getSettings() ) );
         LOGGER.trace( () -> "preparing to open with configuration " + JsonUtil.serializeMap( environmentConfig.getSettings() ) );
         environment = Environments.newInstance( dbDirectory.getAbsolutePath() + File.separator + FILE_SUB_PATH, environmentConfig );
         environment = Environments.newInstance( dbDirectory.getAbsolutePath() + File.separator + FILE_SUB_PATH, environmentConfig );
 
 
-        try
-        {
-            if ( !getDirtyFile().exists() )
-            {
-                Files.createFile( getDirtyFile().toPath() );
-                LOGGER.trace( () -> "created openLock file" );
-            }
-        }
-        catch ( IOException e )
-        {
-            LOGGER.error( "error creating openLock file: " + e.getMessage() );
-        }
-
-
         LOGGER.trace( () -> "environment open (" + TimeDuration.fromCurrent( startTime ).asCompactString() + ")" );
         LOGGER.trace( () -> "environment open (" + TimeDuration.fromCurrent( startTime ).asCompactString() + ")" );
 
 
         environment.executeInTransaction( txn ->
         environment.executeInTransaction( txn ->
@@ -177,21 +163,13 @@ public class XodusLocalDB implements LocalDBProvider
     @Override
     @Override
     public void close( ) throws LocalDBException
     public void close( ) throws LocalDBException
     {
     {
+        final Instant startTime = Instant.now();
         if ( environment != null && environment.isOpen() )
         if ( environment != null && environment.isOpen() )
         {
         {
             environment.close();
             environment.close();
-            try
-            {
-                Files.deleteIfExists( getDirtyFile().toPath() );
-                LOGGER.trace( () -> "deleted openLock file" );
-            }
-            catch ( IOException e )
-            {
-                LOGGER.error( "error creating openLock file: " + e.getMessage() );
-            }
         }
         }
         status = LocalDB.Status.CLOSED;
         status = LocalDB.Status.CLOSED;
-        LOGGER.debug( () -> "closed" );
+        LOGGER.debug( () -> "closed (" + TimeDuration.compactFromCurrent( startTime ) + ")" );
     }
     }
 
 
     private EnvironmentConfig makeEnvironmentConfig( final Map<String, String> initParameters )
     private EnvironmentConfig makeEnvironmentConfig( final Map<String, String> initParameters )
@@ -201,16 +179,6 @@ public class XodusLocalDB implements LocalDBProvider
         environmentConfig.setMemoryUsage( 50 * 1024 * 1024 );
         environmentConfig.setMemoryUsage( 50 * 1024 * 1024 );
         environmentConfig.setEnvGatherStatistics( true );
         environmentConfig.setEnvGatherStatistics( true );
 
 
-        if ( Files.exists( getDirtyFile().toPath() ) )
-        {
-            environmentConfig.setGcUtilizationFromScratch( true );
-            LOGGER.warn( "environment not closed cleanly, will re-calculate GC" );
-        }
-        else
-        {
-            LOGGER.debug( () -> "environment was closed cleanly" );
-        }
-
         for ( final Map.Entry<String, String> entry : initParameters.entrySet() )
         for ( final Map.Entry<String, String> entry : initParameters.entrySet() )
         {
         {
             final String key = entry.getKey();
             final String key = entry.getKey();
@@ -661,9 +629,4 @@ public class XodusLocalDB implements LocalDBProvider
             LOGGER.error( "error writing LocalDB readme file: " + e.getMessage() );
             LOGGER.error( "error writing LocalDB readme file: " + e.getMessage() );
         }
         }
     }
     }
-
-    private File getDirtyFile()
-    {
-        return new File( this.getFileLocation().getAbsolutePath() + File.separator + FILE_SUB_PATH + File.separator + "xodus.open" );
-    }
 }
 }

+ 1 - 1
webapp/src/main/webapp/WEB-INF/jsp/configmanager-wordlists.jsp

@@ -75,7 +75,7 @@
                     </button>
                     </button>
                 </td>
                 </td>
                 <td class="buttoncell">
                 <td class="buttoncell">
-                    <button class="menubutton" id="MenuItem_ClearSeedlist" disabled="disabled">
+                    <button class="menubutton" id="MenuItem_ClearSeedlist" style="visibility: hidden;">
                         <pwm:if test="<%=PwmIfTest.showIcons%>"><span class="btn-icon pwm-icon pwm-icon-trash"></span></pwm:if>
                         <pwm:if test="<%=PwmIfTest.showIcons%>"><span class="btn-icon pwm-icon pwm-icon-trash"></span></pwm:if>
                         Clear Seed List
                         Clear Seed List
                     </button>
                     </button>