public void validate(PasswordPolicyConfig config) throws SecurityConfigException { if (config.getMinLength() < 0) throw createSecurityException(INVALID_MIN_LENGTH); if (config.getMaxLength() != -1) { if (config.getMinLength() > config.getMaxLength()) throw createSecurityException(INVALID_MAX_LENGTH); } }
public PasswordPolicyConfig(PasswordPolicyConfig other) { super(other); uppercaseRequired = other.isUppercaseRequired(); lowercaseRequired = other.isLowercaseRequired(); digitRequired = other.isDigitRequired(); minLength = other.getMinLength(); maxLength = other.getMaxLength(); }
@Override public void validatePassword(char[] password) throws PasswordPolicyException { // if (password==null) // throw createSecurityException(PW_IS_NULL); if (password == null) { // treat as "empty" password = new char[] {}; } if (password.length < config.getMinLength()) throw createSecurityException(MIN_LENGTH_$1, config.getMinLength()); if (config.getMaxLength() >= 0 && password.length > config.getMaxLength()) throw createSecurityException(MAX_LENGTH_$1, config.getMaxLength()); if (config.isDigitRequired()) { if (checkUsingMethod("isDigit", password) == false) throw createSecurityException(NO_DIGIT); } if (config.isUppercaseRequired()) { if (checkUsingMethod("isUpperCase", password) == false) throw createSecurityException(NO_UPPERCASE); } if (config.isLowercaseRequired()) { if (checkUsingMethod("isLowerCase", password) == false) throw createSecurityException(NO_LOWERCASE); } String prefix = passwordStartsWithEncoderPrefix(password); if (prefix != null) throw createSecurityException(RESERVED_PREFIX_$1, prefix); }
expect(masterPasswdPolicyConfig.getMaxLength()).andReturn(-1).anyTimes();
public PasswordPolicyPanel(String id, IModel<PasswordPolicyConfig> model) { super(id, model); PasswordPolicyConfig pwPolicy = model.getObject(); //add(new TextField("name").setRequired(true)); add(new CheckBox("digitRequired")); add(new CheckBox("uppercaseRequired")); add(new CheckBox("lowercaseRequired")); add(new TextField<Integer>("minLength")); boolean unlimited = pwPolicy.getMaxLength() == -1; add(new AjaxCheckBox("unlimitedMaxLength", new Model(unlimited)) { @Override protected void onUpdate(AjaxRequestTarget target) { Boolean value = getModelObject(); maxLengthPanel.setVisible(!value); if (value) { maxLengthPanel.setUnlimited(); } target.addComponent(maxLengthPanel.getParent()); } }); add(maxLengthPanel = (MaxLengthPanel) new MaxLengthPanel("maxLength").setVisible(!unlimited)); }
public PasswordPolicyPanel(String id, IModel<PasswordPolicyConfig> model) { super(id, model); PasswordPolicyConfig pwPolicy = model.getObject(); //add(new TextField("name").setRequired(true)); add(new CheckBox("digitRequired")); add(new CheckBox("uppercaseRequired")); add(new CheckBox("lowercaseRequired")); add(new TextField<Integer>("minLength")); boolean unlimited = pwPolicy.getMaxLength() == -1; add(new AjaxCheckBox("unlimitedMaxLength", new Model(unlimited)) { @Override protected void onUpdate(AjaxRequestTarget target) { Boolean value = getModelObject(); maxLengthPanel.setVisible(!value); if (value) { maxLengthPanel.setUnlimited(); } target.addComponent(maxLengthPanel.getParent()); } }); add(maxLengthPanel = (MaxLengthPanel) new MaxLengthPanel("maxLength").setVisible(!unlimited)); }
public PasswordPolicyPanel(String id, IModel<PasswordPolicyConfig> model) { super(id, model); PasswordPolicyConfig pwPolicy = model.getObject(); // add(new TextField("name").setRequired(true)); add(new CheckBox("digitRequired")); add(new CheckBox("uppercaseRequired")); add(new CheckBox("lowercaseRequired")); add(new TextField<Integer>("minLength")); boolean unlimited = pwPolicy.getMaxLength() == -1; add( new AjaxCheckBox("unlimitedMaxLength", new Model(unlimited)) { @Override protected void onUpdate(AjaxRequestTarget target) { Boolean value = getModelObject(); maxLengthPanel.setVisible(!value); if (value) { maxLengthPanel.setUnlimited(); } target.add(maxLengthPanel.getParent()); } }); add( maxLengthPanel = (MaxLengthPanel) new MaxLengthPanel("maxLength").setVisible(!unlimited)); }