|
@@ -24,6 +24,7 @@ package password.pwm.config.value;
|
|
|
|
|
|
import org.jdom2.Element;
|
|
|
import password.pwm.config.PwmSetting;
|
|
|
+import password.pwm.config.PwmSettingProperty;
|
|
|
import password.pwm.config.StoredValue;
|
|
|
import password.pwm.util.java.JsonUtil;
|
|
|
import password.pwm.util.secure.PwmSecurityKey;
|
|
@@ -49,15 +50,33 @@ public class NumericValue extends AbstractValue implements StoredValue
|
|
|
return new NumericValue( JsonUtil.deserialize( value, Long.class ) );
|
|
|
}
|
|
|
|
|
|
- public NumericValue fromXmlElement( final Element settingElement, final PwmSecurityKey input )
|
|
|
+ public NumericValue fromXmlElement( final PwmSetting pwmSetting, final Element settingElement, final PwmSecurityKey input )
|
|
|
{
|
|
|
final Element valueElement = settingElement.getChild( "value" );
|
|
|
final String value = valueElement.getText();
|
|
|
- return new NumericValue( Long.parseLong( value ) );
|
|
|
+ return new NumericValue( normalizeValue( pwmSetting, Long.parseLong( value ) ) );
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ private static long normalizeValue( final PwmSetting pwmSetting, final long value )
|
|
|
+ {
|
|
|
+ final long minValue = Long.parseLong( pwmSetting.getProperties().getOrDefault( PwmSettingProperty.Minimum, "0" ) );
|
|
|
+ final long maxValue = Long.parseLong( pwmSetting.getProperties().getOrDefault( PwmSettingProperty.Maximum, "0" ) );
|
|
|
+
|
|
|
+ if ( minValue > 0 && value < minValue )
|
|
|
+ {
|
|
|
+ return minValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( maxValue > 0 && value > maxValue )
|
|
|
+ {
|
|
|
+ return maxValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<Element> toXmlValues( final String valueElementName, final PwmSecurityKey pwmSecurityKey )
|
|
|
{
|