|
@@ -20,522 +20,34 @@
|
|
|
|
|
|
package password.pwm.http.tag;
|
|
|
|
|
|
-import lombok.Value;
|
|
|
import password.pwm.PwmDomain;
|
|
|
import password.pwm.config.DomainConfig;
|
|
|
-import password.pwm.config.option.ADPolicyComplexity;
|
|
|
import password.pwm.config.profile.NewUserProfile;
|
|
|
import password.pwm.config.profile.PwmPasswordPolicy;
|
|
|
-import password.pwm.config.profile.PwmPasswordRule;
|
|
|
import password.pwm.error.PwmError;
|
|
|
-import password.pwm.error.PwmException;
|
|
|
import password.pwm.error.PwmUnrecoverableException;
|
|
|
import password.pwm.http.PwmRequest;
|
|
|
import password.pwm.http.PwmSession;
|
|
|
import password.pwm.http.servlet.PwmServletDefinition;
|
|
|
import password.pwm.http.servlet.newuser.NewUserServlet;
|
|
|
-import password.pwm.i18n.Display;
|
|
|
-import password.pwm.i18n.Message;
|
|
|
-import password.pwm.util.i18n.LocaleHelper;
|
|
|
-import password.pwm.util.java.StringUtil;
|
|
|
import password.pwm.util.logging.PwmLogger;
|
|
|
import password.pwm.util.macro.MacroRequest;
|
|
|
-import password.pwm.util.password.PasswordRuleReaderHelper;
|
|
|
+import password.pwm.util.password.PasswordRequirementViewableRuleGenerator;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import javax.servlet.jsp.JspTagException;
|
|
|
-import javax.servlet.jsp.tagext.TagSupport;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
-import java.util.MissingResourceException;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @author Jason D. Rivard
|
|
|
*/
|
|
|
-public class PasswordRequirementsTag extends TagSupport
|
|
|
+public class PasswordRequirementsTag extends PwmAbstractTag
|
|
|
{
|
|
|
private static final PwmLogger LOGGER = PwmLogger.forClass( PasswordRequirementsTag.class );
|
|
|
private String separator;
|
|
|
private String prepend;
|
|
|
private String form;
|
|
|
|
|
|
- public static List<String> getPasswordRequirementsStrings(
|
|
|
- final PwmPasswordPolicy passwordPolicy,
|
|
|
- final DomainConfig config,
|
|
|
- final Locale locale,
|
|
|
- final MacroRequest macroRequest
|
|
|
- )
|
|
|
- {
|
|
|
- final List<String> ruleTexts = new ArrayList<>( );
|
|
|
- final PolicyValues policyValues = new PolicyValues( passwordPolicy, passwordPolicy.getRuleHelper(), locale, config, macroRequest );
|
|
|
- for ( final RuleTextGenerator ruleTextGenerator : RULE_TEXT_GENERATORS )
|
|
|
- {
|
|
|
- ruleTexts.addAll( ruleTextGenerator.generate( policyValues ) );
|
|
|
- }
|
|
|
-
|
|
|
- return Collections.unmodifiableList( ruleTexts );
|
|
|
- }
|
|
|
-
|
|
|
- private static final List<RuleTextGenerator> RULE_TEXT_GENERATORS = List.of(
|
|
|
- new CaseSensitiveRuleTextGenerator(),
|
|
|
- new MinLengthRuleTextGenerator(),
|
|
|
- new MaxLengthRuleTextGenerator(),
|
|
|
- new MinAlphaRuleTextGenerator(),
|
|
|
- new MaxAlphaRuleTextGenerator(),
|
|
|
- new NumericCharsRuleTextGenerator(),
|
|
|
- new SpecialCharsRuleTextGenerator(),
|
|
|
- new MaximumRepeatRuleTextGenerator(),
|
|
|
- new MaximumSequentialRepeatRuleTextGenerator(),
|
|
|
- new MinimumLowerRuleTextGenerator(),
|
|
|
- new MaximumLowerRuleTextGenerator(),
|
|
|
- new MinimumUpperRuleTextGenerator(),
|
|
|
- new MaximumUpperRuleTextGenerator(),
|
|
|
- new MinimumUniqueRuleTextGenerator(),
|
|
|
- new DisallowedValuesRuleTextGenerator(),
|
|
|
- new WordlistRuleTextGenerator(),
|
|
|
- new DisallowedAttributesRuleTextGenerator(),
|
|
|
- new MaximumOldCharsRuleTextGenerator(),
|
|
|
- new MinimumLifetimeRuleTextGenerator(),
|
|
|
- new ADRuleTextGenerator(),
|
|
|
- new UniqueRequiredRuleTextGenerator() );
|
|
|
-
|
|
|
- private interface RuleTextGenerator
|
|
|
- {
|
|
|
- List<String> generate( PolicyValues policyValues );
|
|
|
- }
|
|
|
-
|
|
|
- @Value
|
|
|
- private static class PolicyValues
|
|
|
- {
|
|
|
- private PwmPasswordPolicy passwordPolicy;
|
|
|
- private PasswordRuleReaderHelper ruleHelper;
|
|
|
- private Locale locale;
|
|
|
- private DomainConfig config;
|
|
|
- private MacroRequest macroRequest;
|
|
|
- }
|
|
|
-
|
|
|
- private static class CaseSensitiveRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- if ( policyValues.getRuleHelper().readBooleanValue( PwmPasswordRule.CaseSensitive ) )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_CaseSensitive, null, policyValues ) );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_NotCaseSensitive, null, policyValues ) );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MinLengthRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MinimumLength );
|
|
|
- final ADPolicyComplexity adPolicyLevel = policyValues.getRuleHelper().getADComplexityLevel();
|
|
|
-
|
|
|
- if ( adPolicyLevel == ADPolicyComplexity.AD2003 || adPolicyLevel == ADPolicyComplexity.AD2008 )
|
|
|
- {
|
|
|
- if ( value < 6 )
|
|
|
- {
|
|
|
- value = 6;
|
|
|
- }
|
|
|
- }
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MinLength, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MaxLengthRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MaximumLength );
|
|
|
- if ( value > 0 && value < 64 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MaxLength, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MinAlphaRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MinimumAlpha );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MinAlpha, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MaxAlphaRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MaximumAlpha );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MaxAlpha, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class NumericCharsRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final PasswordRuleReaderHelper ruleHelper = policyValues.getRuleHelper();
|
|
|
- if ( !ruleHelper.readBooleanValue( PwmPasswordRule.AllowNumeric ) )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_AllowNumeric, null, policyValues ) );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- final List<String> returnValues = new ArrayList<>( );
|
|
|
- final int minValue = ruleHelper.readIntValue( PwmPasswordRule.MinimumNumeric );
|
|
|
- if ( minValue > 0 )
|
|
|
- {
|
|
|
- returnValues.add( getLocalString( Message.Requirement_MinNumeric, minValue, policyValues ) );
|
|
|
- }
|
|
|
-
|
|
|
- final int maxValue = ruleHelper.readIntValue( PwmPasswordRule.MaximumNumeric );
|
|
|
- if ( maxValue > 0 )
|
|
|
- {
|
|
|
- returnValues.add( getLocalString( Message.Requirement_MaxNumeric, maxValue, policyValues ) );
|
|
|
- }
|
|
|
-
|
|
|
- if ( !ruleHelper.readBooleanValue( PwmPasswordRule.AllowFirstCharNumeric ) )
|
|
|
- {
|
|
|
- returnValues.add( getLocalString( Message.Requirement_FirstNumeric, maxValue, policyValues ) );
|
|
|
- }
|
|
|
-
|
|
|
- if ( !ruleHelper.readBooleanValue( PwmPasswordRule.AllowLastCharNumeric ) )
|
|
|
- {
|
|
|
- returnValues.add( getLocalString( Message.Requirement_LastNumeric, maxValue, policyValues ) );
|
|
|
- }
|
|
|
- return returnValues;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class SpecialCharsRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final PasswordRuleReaderHelper ruleHelper = policyValues.getRuleHelper();
|
|
|
- if ( !ruleHelper.readBooleanValue( PwmPasswordRule.AllowSpecial ) )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_AllowSpecial, null, policyValues ) );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- final List<String> returnValues = new ArrayList<>( );
|
|
|
- final int minValue = ruleHelper.readIntValue( PwmPasswordRule.MinimumSpecial );
|
|
|
- if ( minValue > 0 )
|
|
|
- {
|
|
|
- returnValues.add( getLocalString( Message.Requirement_MinSpecial, minValue, policyValues ) );
|
|
|
- }
|
|
|
-
|
|
|
- final int maxValue = ruleHelper.readIntValue( PwmPasswordRule.MaximumSpecial );
|
|
|
- if ( maxValue > 0 )
|
|
|
- {
|
|
|
- returnValues.add( getLocalString( Message.Requirement_MaxSpecial, maxValue, policyValues ) );
|
|
|
- }
|
|
|
-
|
|
|
- if ( !ruleHelper.readBooleanValue( PwmPasswordRule.AllowFirstCharSpecial ) )
|
|
|
- {
|
|
|
- returnValues.add( getLocalString( Message.Requirement_FirstSpecial, maxValue, policyValues ) );
|
|
|
- }
|
|
|
-
|
|
|
- if ( !ruleHelper.readBooleanValue( PwmPasswordRule.AllowLastCharSpecial ) )
|
|
|
- {
|
|
|
- returnValues.add( getLocalString( Message.Requirement_LastSpecial, maxValue, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.unmodifiableList( returnValues );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MaximumRepeatRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MaximumRepeat );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MaxRepeat, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MaximumSequentialRepeatRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MaximumSequentialRepeat );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MaxSeqRepeat, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MinimumLowerRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MinimumLowerCase );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MinLower, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MaximumLowerRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MaximumLowerCase );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MaxLower, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MinimumUpperRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MinimumUpperCase );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MinUpper, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MaximumUpperRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MaximumUpperCase );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MaxUpper, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MinimumUniqueRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MinimumUnique );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_MinUnique, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class DisallowedValuesRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final List<String> setValue = policyValues.getRuleHelper().getDisallowedValues();
|
|
|
- if ( !setValue.isEmpty() )
|
|
|
- {
|
|
|
- final StringBuilder fieldValue = new StringBuilder();
|
|
|
- for ( final String loopValue : setValue )
|
|
|
- {
|
|
|
- fieldValue.append( ' ' );
|
|
|
-
|
|
|
- final String expandedValue = policyValues.getMacroRequest().expandMacros( loopValue );
|
|
|
- fieldValue.append( StringUtil.escapeHtml( expandedValue ) );
|
|
|
- }
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_DisAllowedValues, fieldValue.toString(), policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class WordlistRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- if ( policyValues.getRuleHelper().readBooleanValue( PwmPasswordRule.EnableWordlist ) )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_WordList, "", policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class DisallowedAttributesRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final List<String> setValue = policyValues.getRuleHelper().getDisallowedAttributes();
|
|
|
- final ADPolicyComplexity adPolicyLevel = policyValues.getRuleHelper().getADComplexityLevel();
|
|
|
- if ( !setValue.isEmpty() || adPolicyLevel == ADPolicyComplexity.AD2003 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_DisAllowedAttributes, "", policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MaximumOldCharsRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MaximumOldChars );
|
|
|
- if ( value > 0 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_OldChar, value, policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class MinimumLifetimeRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final int value = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.MinimumLifetime );
|
|
|
-
|
|
|
- if ( value <= 0 )
|
|
|
- {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- final int secondsPerDay = 60 * 60 * 24;
|
|
|
-
|
|
|
- final String durationStr;
|
|
|
- if ( value % secondsPerDay == 0 )
|
|
|
- {
|
|
|
- final int valueAsDays = value / ( 60 * 60 * 24 );
|
|
|
- final Display key = valueAsDays <= 1 ? Display.Display_Day : Display.Display_Days;
|
|
|
- durationStr = valueAsDays + " " + LocaleHelper.getLocalizedMessage( policyValues.getLocale(), key, policyValues.getConfig() );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- final int valueAsHours = value / ( 60 * 60 );
|
|
|
- final Display key = valueAsHours <= 1 ? Display.Display_Hour : Display.Display_Hours;
|
|
|
- durationStr = valueAsHours + " " + LocaleHelper.getLocalizedMessage( policyValues.getLocale(), key, policyValues.getConfig() );
|
|
|
- }
|
|
|
-
|
|
|
- final String userMsg = Message.getLocalizedMessage( policyValues.getLocale(), Message.Requirement_MinimumFrequency, policyValues.getConfig(), durationStr );
|
|
|
- return Collections.singletonList( userMsg );
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class ADRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final ADPolicyComplexity adPolicyLevel = policyValues.getRuleHelper().getADComplexityLevel();
|
|
|
- if ( adPolicyLevel == ADPolicyComplexity.AD2003 )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_ADComplexity, "", policyValues ) );
|
|
|
- }
|
|
|
- else if ( adPolicyLevel == ADPolicyComplexity.AD2008 )
|
|
|
- {
|
|
|
- final int maxViolations = policyValues.getRuleHelper().readIntValue( PwmPasswordRule.ADComplexityMaxViolations );
|
|
|
- final int minGroups = 5 - maxViolations;
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_ADComplexity2008, String.valueOf( minGroups ), policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static class UniqueRequiredRuleTextGenerator implements RuleTextGenerator
|
|
|
- {
|
|
|
- @Override
|
|
|
- public List<String> generate( final PolicyValues policyValues )
|
|
|
- {
|
|
|
- if ( policyValues.getRuleHelper().readBooleanValue( PwmPasswordRule.UniqueRequired ) )
|
|
|
- {
|
|
|
- return Collections.singletonList( getLocalString( Message.Requirement_UniqueRequired, "", policyValues ) );
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static String getLocalString( final Message message, final int size, final PolicyValues policyValues )
|
|
|
- {
|
|
|
- final Message effectiveMessage = size > 1 && message.getPluralMessage() != null
|
|
|
- ? message.getPluralMessage()
|
|
|
- : message;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- return Message.getLocalizedMessage( policyValues.getLocale(), effectiveMessage, policyValues.getConfig(), String.valueOf( size ) );
|
|
|
- }
|
|
|
- catch ( final MissingResourceException e )
|
|
|
- {
|
|
|
- LOGGER.error( () -> "unable to display requirement tag for message '" + message.toString() + "': " + e.getMessage() );
|
|
|
- }
|
|
|
- return "UNKNOWN MESSAGE STRING";
|
|
|
- }
|
|
|
-
|
|
|
- private static String getLocalString( final Message message, final String field, final PolicyValues policyValues )
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- return Message.getLocalizedMessage( policyValues.getLocale(), message, policyValues.getConfig(), field );
|
|
|
- }
|
|
|
- catch ( final MissingResourceException e )
|
|
|
- {
|
|
|
- LOGGER.error( () -> "unable to display requirement tag for message '" + message.toString() + "': " + e.getMessage() );
|
|
|
- }
|
|
|
- return "UNKNOWN MESSAGE STRING";
|
|
|
- }
|
|
|
-
|
|
|
public String getSeparator( )
|
|
|
{
|
|
|
return separator;
|
|
@@ -567,51 +79,48 @@ public class PasswordRequirementsTag extends TagSupport
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int doEndTag( )
|
|
|
- throws javax.servlet.jsp.JspTagException
|
|
|
+ protected PwmLogger getLogger()
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- final PwmRequest pwmRequest = PwmRequest.forRequest( ( HttpServletRequest ) pageContext.getRequest(), ( HttpServletResponse ) pageContext.getResponse() );
|
|
|
- final PwmSession pwmSession = pwmRequest.getPwmSession();
|
|
|
- final PwmDomain pwmDomain = pwmRequest.getPwmDomain();
|
|
|
- final DomainConfig config = pwmDomain.getConfig();
|
|
|
- final Locale locale = pwmSession.getSessionStateBean().getLocale();
|
|
|
+ return LOGGER;
|
|
|
+ }
|
|
|
|
|
|
- pwmRequest.getMacroMachine( );
|
|
|
+ @Override
|
|
|
+ protected String generateTagBodyContents( final PwmRequest pwmRequest )
|
|
|
+ throws PwmUnrecoverableException
|
|
|
+ {
|
|
|
+ final PwmSession pwmSession = pwmRequest.getPwmSession();
|
|
|
+ final PwmDomain pwmDomain = pwmRequest.getPwmDomain();
|
|
|
+ final DomainConfig config = pwmDomain.getConfig();
|
|
|
+ final Locale locale = pwmSession.getSessionStateBean().getLocale();
|
|
|
|
|
|
- final PwmPasswordPolicy passwordPolicy = readPasswordPolicy( pwmRequest );
|
|
|
+ pwmRequest.getMacroMachine( );
|
|
|
|
|
|
- final Optional<String> configuredRuleText = passwordPolicy.getRuleText( pwmRequest.getLocale() );
|
|
|
- if ( configuredRuleText.isPresent() )
|
|
|
- {
|
|
|
- pageContext.getOut().write( configuredRuleText.get() );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- final MacroRequest macroRequest = pwmRequest.getMacroMachine( );
|
|
|
+ final PwmPasswordPolicy passwordPolicy = readPasswordPolicy( pwmRequest );
|
|
|
|
|
|
- final String pre = prepend != null && prepend.length() > 0 ? prepend : "";
|
|
|
- final String sep = separator != null && separator.length() > 0 ? separator : "<br/>";
|
|
|
- final List<String> requirementsList = getPasswordRequirementsStrings( passwordPolicy, config, locale, macroRequest );
|
|
|
+ final Optional<String> configuredRuleText = passwordPolicy.getRuleText( pwmRequest.getLocale() );
|
|
|
+ if ( configuredRuleText.isPresent() )
|
|
|
+ {
|
|
|
+ return configuredRuleText.get();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ final MacroRequest macroRequest = pwmRequest.getMacroMachine( );
|
|
|
|
|
|
- final StringBuilder requirementsText = new StringBuilder();
|
|
|
- for ( final String requirementStatement : requirementsList )
|
|
|
- {
|
|
|
- requirementsText.append( pre );
|
|
|
- requirementsText.append( requirementStatement );
|
|
|
- requirementsText.append( sep );
|
|
|
- }
|
|
|
+ final String pre = prepend != null && prepend.length() > 0 ? prepend : "";
|
|
|
+ final String sep = separator != null && separator.length() > 0 ? separator : "<br/>";
|
|
|
+ final List<String> requirementsList = PasswordRequirementViewableRuleGenerator
|
|
|
+ .generate( passwordPolicy, config, locale, macroRequest );
|
|
|
|
|
|
- pageContext.getOut().write( requirementsText.toString() );
|
|
|
+ final StringBuilder requirementsText = new StringBuilder();
|
|
|
+ for ( final String requirementStatement : requirementsList )
|
|
|
+ {
|
|
|
+ requirementsText.append( pre );
|
|
|
+ requirementsText.append( requirementStatement );
|
|
|
+ requirementsText.append( sep );
|
|
|
}
|
|
|
+
|
|
|
+ return requirementsText.toString();
|
|
|
}
|
|
|
- catch ( final IOException | PwmException e )
|
|
|
- {
|
|
|
- LOGGER.error( () -> "unexpected error during password requirements generation: " + e.getMessage(), e );
|
|
|
- throw new JspTagException( e.getMessage() );
|
|
|
- }
|
|
|
- return EVAL_PAGE;
|
|
|
}
|
|
|
|
|
|
static PwmPasswordPolicy readPasswordPolicy( final PwmRequest pwmRequest )
|