PasswordValidationAction extends AbstractAuthorizableAction { @Override public void onPasswordChange(@NotNull User user, @Nullable String newPassword, @NotNull Root root, @NotNull NamePathMapper namePathMapper) throws RepositoryException { validatePassword(newPassword, true); }  @Override void init(SecurityProvider securityProvider, ConfigurationParameters config); @Override void onCreate(@NotNull User user, @Nullable String password, @NotNull Root root, @NotNull NamePathMapper namePathMapper); @Override void onPasswordChange(@NotNull User user, @Nullable String newPassword, @NotNull Root root, @NotNull NamePathMapper namePathMapper); static final String CONSTRAINT; }
@Test public void testOnPasswordChangeInvalid() throws Exception { List<String> invalid = new ArrayList<>(); invalid.add("pw1"); invalid.add("only6C"); invalid.add("12345678"); invalid.add("WITHOUTLOWERCASE"); invalid.add("withoutuppercase"); for (String pw : invalid) { try { pwAction.onPasswordChange(user, pw, root, namePathMapper); fail("should throw constraint violation"); } catch (ConstraintViolationException e) { } } }
@Test public void testOnPasswordChangeValidPw() throws Exception { List<String> valid = new ArrayList<>(); valid.add("abCDefGH"); valid.add("Abbbbbbbbbbbb"); valid.add("cDDDDDDDDDDDDDDDDD"); valid.add("gH%%%%%%%%%%%%%%%%^^"); valid.add("&)(*&^%23qW"); for (String pw : valid) { pwAction.onPasswordChange(user, pw, root, namePathMapper); } }
@Test(expected = ConstraintViolationException.class) public void testOnPasswordChange() throws Exception { pwAction.init(securityProvider, ConfigurationParameters.of(PasswordValidationAction.CONSTRAINT, "abc")); String hashed = PasswordUtil.buildPasswordHash("abc"); pwAction.onPasswordChange(user, hashed, root, namePathMapper); }