@@ -327,41 +327,68 @@ public static void reorderConfigurations(User user, String name, int[] rowIds)
327327 }
328328 }
329329
330- static final EncryptionMigrationHandler ENCRYPTION_MIGRATION_HANDLER = (oldPassPhrase , keySource , oldConfig ) -> {
331- Algorithm decryptAes = Encryption .getAES128 (oldPassPhrase , keySource , oldConfig );
332- _log .info (" Attempting to migrate encrypted properties in authentication configurations" );
333- TableInfo tinfo = CoreSchema .getInstance ().getTableInfoAuthenticationConfigurations ();
334- Map <Integer , String > map = new TableSelector (tinfo , PageFlowUtil .set ("RowId" , "EncryptedProperties" ),
330+ static final EncryptionMigrationHandler ENCRYPTION_MIGRATION_HANDLER = new EncryptionMigrationHandler ()
331+ {
332+ @ Override
333+ public String getDescription ()
334+ {
335+ return "Encrypted Authentication Properties" ;
336+ }
337+
338+ @ Override
339+ public void migrateEncryptedContent (String oldPassPhrase , String keySource , Encryption .AESConfig oldConfig )
340+ {
341+ Algorithm decryptAes = Encryption .getAES128 (oldPassPhrase , keySource , oldConfig );
342+ _log .info (" Attempting to migrate encrypted properties in authentication configurations" );
343+ TableInfo tinfo = CoreSchema .getInstance ().getTableInfoAuthenticationConfigurations ();
344+ Map <Integer , String > map = new TableSelector (tinfo , PageFlowUtil .set ("RowId" , "EncryptedProperties" ),
335345 new SimpleFilter (FieldKey .fromParts ("EncryptedProperties" ), null , CompareType .NONBLANK ), null ).getValueMap (Integer .class );
336- Map <String , String > saveMap = new HashMap <>();
346+ Map <String , String > saveMap = new HashMap <>();
337347
338- map .forEach ((key , value ) -> {
339- try
340- {
341- _log .info (" Migrating encrypted properties for configuration " + key );
348+ map .forEach ((key , value ) -> {
342349 try
343350 {
344- String decryptedValue = decryptAes .decrypt (Base64 .decodeBase64 (value ));
345- String newEncryptedValue = Base64 .encodeBase64String (AES .get ().encrypt (decryptedValue ));
346- assert decryptedValue .equals (AES .get ().decrypt (Base64 .decodeBase64 (newEncryptedValue )));
351+ _log .info (" Migrating encrypted properties for configuration {}" , key );
352+ try
353+ {
354+ String decryptedValue = decryptAes .decrypt (Base64 .decodeBase64 (value ));
355+ String newEncryptedValue = Base64 .encodeBase64String (AES .get ().encrypt (decryptedValue ));
356+ assert decryptedValue .equals (AES .get ().decrypt (Base64 .decodeBase64 (newEncryptedValue )));
347357
348- if (newEncryptedValue != null )
358+ if (newEncryptedValue != null )
359+ {
360+ saveMap .put ("EncryptedProperties" , newEncryptedValue );
361+ Table .update (null , tinfo , saveMap , key );
362+ }
363+ }
364+ catch (DecryptionException e )
349365 {
350- saveMap .put ("EncryptedProperties" , newEncryptedValue );
351- Table .update (null , tinfo , saveMap , key );
366+ _log .info (" Failed to decrypt encrypted properties for configuration {}. It will be skipped." , key );
352367 }
353368 }
354- catch (DecryptionException e )
369+ catch (Exception e )
355370 {
356- _log .info ( " Failed to decrypt encrypted properties for configuration " + key + ". It will be skipped." );
371+ _log .error ( "Exception while migrating configuration {}" , key , e );
357372 }
358- }
359- catch (Exception e )
360- {
361- _log .error ("Exception while migrating configuration " + key , e );
362- }
363- });
364- _log .info (" Migration of encrypted properties in authentication configurations is complete" );
373+ });
374+ _log .info (" Migration of encrypted properties in authentication configurations is complete" );
375+ }
376+
377+ @ Override
378+ public void deleteEncryptedContent ()
379+ {
380+ _log .info ("Clearing the core.AuthenticationConfigurations.EncryptedProperties column" );
381+ TableInfo tinfo = CoreSchema .getInstance ().getTableInfoAuthenticationConfigurations ();
382+ new TableSelector (
383+ tinfo ,
384+ PageFlowUtil .set ("RowId" ),
385+ new SimpleFilter (FieldKey .fromParts ("EncryptedProperties" ), null , CompareType .NONBLANK ),
386+ null
387+ ).forEach (
388+ Integer .class ,
389+ rowId -> Table .update (null , tinfo , PageFlowUtil .map ("EncryptedProperties" , null ), rowId )
390+ );
391+ }
365392 };
366393
367394 // Register a handler so encrypted properties are migrated whenever the encryption key changes
0 commit comments