45
45
import password .pwm .config .profile .PwmPasswordRule ;
46
46
import password .pwm .config .profile .SetupOtpProfile ;
47
47
import password .pwm .config .profile .UpdateProfileProfile ;
48
- import password .pwm .config .stored .ConfigurationProperty ;
49
- import password .pwm .config .stored .StoredConfigurationImpl ;
48
+ import password .pwm .config .stored .ComparingChangeLog ;
49
+ import password .pwm .config .stored .StoredConfigItemKey ;
50
+ import password .pwm .config .stored .StoredConfiguration ;
51
+ import password .pwm .config .stored .StoredConfigurationFactory ;
50
52
import password .pwm .config .stored .StoredConfigurationUtil ;
51
53
import password .pwm .config .value .BooleanValue ;
52
54
import password .pwm .config .value .CustomLinkValue ;
70
72
import password .pwm .error .ErrorInformation ;
71
73
import password .pwm .error .PwmError ;
72
74
import password .pwm .error .PwmUnrecoverableException ;
75
+ import password .pwm .i18n .PwmLocaleBundle ;
73
76
import password .pwm .util .PasswordData ;
74
77
import password .pwm .util .i18n .LocaleHelper ;
75
78
import password .pwm .util .java .StringUtil ;
78
81
import password .pwm .util .secure .PwmRandom ;
79
82
import password .pwm .util .secure .PwmSecurityKey ;
80
83
81
- import java .io .Serializable ;
82
84
import java .lang .reflect .InvocationTargetException ;
83
85
import java .security .cert .X509Certificate ;
84
86
import java .util .ArrayList ;
@@ -104,13 +106,13 @@ public class Configuration implements SettingReader
104
106
{
105
107
private static final PwmLogger LOGGER = PwmLogger .forClass ( Configuration .class );
106
108
107
- private final StoredConfigurationImpl storedConfiguration ;
109
+ private final StoredConfiguration storedConfiguration ;
108
110
109
111
private DataCache dataCache = new DataCache ();
110
112
111
113
private String cashedConfigurationHash ;
112
114
113
- public Configuration ( final StoredConfigurationImpl storedConfiguration )
115
+ public Configuration ( final StoredConfiguration storedConfiguration )
114
116
{
115
117
this .storedConfiguration = storedConfiguration ;
116
118
}
@@ -126,13 +128,15 @@ public static void deprecatedSettingException( final PwmSetting pwmSetting, fina
126
128
}
127
129
128
130
public void outputToLog ( )
131
+ throws PwmUnrecoverableException
129
132
{
130
133
if ( !LOGGER .isEnabled ( PwmLogLevel .TRACE ) )
131
134
{
132
135
return ;
133
136
}
134
137
135
- final Map <String , String > debugStrings = storedConfiguration .getModifiedSettingDebugValues ( PwmConstants .DEFAULT_LOCALE , true );
138
+ final ComparingChangeLog changeLog = new ComparingChangeLog ( StoredConfigurationFactory .newStoredConfiguration (), storedConfiguration );
139
+ final Map <String , String > debugStrings = StoredConfigurationUtil .asDebugMap ( storedConfiguration , changeLog .changedValues (), PwmConstants .DEFAULT_LOCALE );
136
140
final List <Supplier <CharSequence >> outputStrings = new ArrayList <>();
137
141
138
142
for ( final Map .Entry <String , String > entry : debugStrings .entrySet () )
@@ -516,7 +520,7 @@ public static <E extends Enum<E>> Set<E> valueToOptionList( final PwmSetting set
516
520
}
517
521
}
518
522
519
- public Map <Locale , String > readLocalizedBundle ( final String className , final String keyName )
523
+ public Map <Locale , String > readLocalizedBundle ( final PwmLocaleBundle className , final String keyName )
520
524
{
521
525
final String key = className + "-" + keyName ;
522
526
if ( dataCache .customText .containsKey ( key ) )
@@ -705,11 +709,6 @@ public Collection<Locale> localesForSetting( final PwmSetting setting )
705
709
return returnCollection ;
706
710
}
707
711
708
- public String readProperty ( final ConfigurationProperty key )
709
- {
710
- return storedConfiguration .readConfigProperty ( key );
711
- }
712
-
713
712
public boolean readSettingAsBoolean ( final PwmSetting setting )
714
713
{
715
714
return JavaTypeConverter .valueToBoolean ( readStoredValue ( setting ) );
@@ -748,48 +747,50 @@ public PrivateKeyCertificate readSettingAsPrivateKey( final PwmSetting setting )
748
747
return ( PrivateKeyCertificate ) readStoredValue ( setting ).toNativeObject ();
749
748
}
750
749
751
- public String getNotes ( )
752
- {
753
- return storedConfiguration .readConfigProperty ( ConfigurationProperty .NOTES );
754
- }
755
-
756
750
private PwmSecurityKey tempInstanceKey = null ;
757
751
758
752
public PwmSecurityKey getSecurityKey ( ) throws PwmUnrecoverableException
759
753
{
760
- final PasswordData configValue = readSettingAsPassword ( PwmSetting .PWM_SECURITY_KEY );
761
-
762
- if ( configValue == null || configValue .getStringValue ().isEmpty () )
754
+ if ( dataCache .pwmSecurityKey == null )
763
755
{
764
- final String errorMsg = "Security Key value is not configured,will generate temp value for use by runtime instance" ;
765
- final ErrorInformation errorInfo = new ErrorInformation ( PwmError .ERROR_INVALID_SECURITY_KEY , errorMsg );
766
- LOGGER .warn ( errorInfo .toDebugStr () );
767
- if ( tempInstanceKey == null )
756
+ final PasswordData configValue = readSettingAsPassword ( PwmSetting .PWM_SECURITY_KEY );
757
+
758
+ if ( configValue == null || configValue .getStringValue ().isEmpty () )
768
759
{
769
- tempInstanceKey = new PwmSecurityKey ( PwmRandom .getInstance ().alphaNumericString ( 256 ) );
760
+ final String errorMsg = "Security Key value is not configured, will generate temp value for use by runtime instance" ;
761
+ final ErrorInformation errorInfo = new ErrorInformation ( PwmError .ERROR_INVALID_SECURITY_KEY , errorMsg );
762
+ LOGGER .warn ( errorInfo .toDebugStr () );
763
+ if ( tempInstanceKey == null )
764
+ {
765
+ tempInstanceKey = new PwmSecurityKey ( PwmRandom .getInstance ().alphaNumericString ( 1024 ) );
766
+ }
767
+ dataCache .pwmSecurityKey = tempInstanceKey ;
770
768
}
771
- return tempInstanceKey ;
772
- }
769
+ else
770
+ {
771
+ final int minSecurityKeyLength = Integer .parseInt ( readAppProperty ( AppProperty .SECURITY_CONFIG_MIN_SECURITY_KEY_LENGTH ) );
772
+ if ( configValue .getStringValue ().length () < minSecurityKeyLength )
773
+ {
774
+ final String errorMsg = "Security Key must be greater than 32 characters in length" ;
775
+ final ErrorInformation errorInfo = new ErrorInformation ( PwmError .ERROR_INVALID_SECURITY_KEY , errorMsg );
776
+ throw new PwmUnrecoverableException ( errorInfo );
777
+ }
773
778
774
- final int minSecurityKeyLength = Integer .parseInt ( readAppProperty ( AppProperty .SECURITY_CONFIG_MIN_SECURITY_KEY_LENGTH ) );
775
- if ( configValue .getStringValue ().length () < minSecurityKeyLength )
776
- {
777
- final String errorMsg = "Security Key must be greater than 32 characters in length" ;
778
- final ErrorInformation errorInfo = new ErrorInformation ( PwmError .ERROR_INVALID_SECURITY_KEY , errorMsg );
779
- throw new PwmUnrecoverableException ( errorInfo );
779
+ try
780
+ {
781
+ dataCache .pwmSecurityKey = new PwmSecurityKey ( configValue .getStringValue () );
782
+ }
783
+ catch ( Exception e )
784
+ {
785
+ final String errorMsg = "unexpected error generating Security Key crypto: " + e .getMessage ();
786
+ final ErrorInformation errorInfo = new ErrorInformation ( PwmError .ERROR_INVALID_SECURITY_KEY , errorMsg );
787
+ LOGGER .error ( errorInfo .toDebugStr (), e );
788
+ throw new PwmUnrecoverableException ( errorInfo );
789
+ }
790
+ }
780
791
}
781
792
782
- try
783
- {
784
- return new PwmSecurityKey ( configValue .getStringValue () );
785
- }
786
- catch ( Exception e )
787
- {
788
- final String errorMsg = "unexpected error generating Security Key crypto: " + e .getMessage ();
789
- final ErrorInformation errorInfo = new ErrorInformation ( PwmError .ERROR_INVALID_SECURITY_KEY , errorMsg );
790
- LOGGER .error ( errorInfo .toDebugStr (), e );
791
- throw new PwmUnrecoverableException ( errorInfo );
792
- }
793
+ return dataCache .pwmSecurityKey ;
793
794
}
794
795
795
796
public List <DataStorageMethod > getResponseStorageLocations ( final PwmSetting setting )
@@ -1017,14 +1018,15 @@ private StoredValue readStoredValue( final PwmSetting setting )
1017
1018
return readValue ;
1018
1019
}
1019
1020
1020
- private static class DataCache implements Serializable
1021
+ private static class DataCache
1021
1022
{
1022
1023
private final Map <String , Map <Locale , PwmPasswordPolicy >> cachedPasswordPolicy = new LinkedHashMap <>();
1023
1024
private Map <Locale , String > localeFlagMap = null ;
1024
1025
private final Map <PwmSetting , StoredValue > settings = new EnumMap <>( PwmSetting .class );
1025
1026
private final Map <String , Map <Locale , String >> customText = new LinkedHashMap <>();
1026
1027
private final Map <ProfileDefinition , Map > profileCache = new LinkedHashMap <>();
1027
1028
private Map <String , String > appPropertyOverrides = null ;
1029
+ private PwmSecurityKey pwmSecurityKey ;
1028
1030
}
1029
1031
1030
1032
public Map <AppProperty , String > readAllNonDefaultAppProperties ( )
@@ -1125,9 +1127,9 @@ private Profile newProfileForID( final ProfileDefinition profileDefinition, fina
1125
1127
return profileFactory .makeFromStoredConfiguration ( storedConfiguration , profileID );
1126
1128
}
1127
1129
1128
- public StoredConfigurationImpl getStoredConfiguration ( ) throws PwmUnrecoverableException
1130
+ public StoredConfiguration getStoredConfiguration ( ) throws PwmUnrecoverableException
1129
1131
{
1130
- final StoredConfigurationImpl copiedStoredConfiguration = StoredConfigurationImpl . copy ( storedConfiguration );
1132
+ final StoredConfiguration copiedStoredConfiguration = this . storedConfiguration . copy ();
1131
1133
copiedStoredConfiguration .lock ();
1132
1134
return copiedStoredConfiguration ;
1133
1135
}
@@ -1149,10 +1151,13 @@ public String configurationHash( )
1149
1151
1150
1152
public Set <PwmSetting > nonDefaultSettings ( )
1151
1153
{
1152
- final Set returnSet = new LinkedHashSet ();
1153
- for ( final StoredConfigurationImpl . SettingValueRecord valueRecord : this .storedConfiguration .modifiedSettings () )
1154
+ final Set < PwmSetting > returnSet = new LinkedHashSet <> ();
1155
+ for ( final StoredConfigItemKey key : this .storedConfiguration .modifiedSettings () )
1154
1156
{
1155
- returnSet .add ( valueRecord .getSetting () );
1157
+ if ( key .getRecordType () == StoredConfigItemKey .RecordType .SETTING )
1158
+ {
1159
+ returnSet .add ( key .toPwmSetting () );
1160
+ }
1156
1161
}
1157
1162
return returnSet ;
1158
1163
}
0 commit comments