protected void checkCurrentPassword(MasterPasswordChangeRequest request) throws MasterPasswordChangeException { if (isNotEmpty(request.getCurrentPassword()) == false) { throw createSecurityException(MasterPasswordChangeException.CURRENT_PASSWORD_REQUIRED); } try { if (!manager.getKeyStoreProvider().isKeyStorePassword(request.getCurrentPassword())) { throw createSecurityException(MasterPasswordChangeException.CURRENT_PASSWORD_ERROR); } } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Checks the {@link MasterPasswordChangeRequest} object * * @param request * @throws MasterPasswordChangeException * @throws PasswordPolicyException */ public void validateChangeRequest(MasterPasswordChangeRequest request) throws MasterPasswordChangeException, PasswordPolicyException { checkCurrentPassword(request); checkConfirmationPassword(request); checkNewPassword(request); checkNewEqualsConfirmation(request.getNewPassword(), request.getConfirmPassword()); validatePasswordAgainstPolicy(request.getNewPassword()); checkNewEqualsCurrent(request.getNewPassword(), request.getCurrentPassword()); }
@Test public void testValidator() throws Exception { // test spring MasterPasswordChangeRequest r = new MasterPasswordChangeRequest(); checkCurrentPassword(r); r.setCurrentPassword("geoserver".toCharArray()); // r.setCurrentPassword(getMasterPassword().toCharArray()); checkConfirmationPassword(r); r.setConfirmPassword("abc".toCharArray()); checkNewPassword(r); r.setNewPassword("def".toCharArray()); checkConfirmationEqualsNewPassword(r); r.setNewPassword("abc".toCharArray()); validateAgainstPolicy(r); r.setConfirmPassword(r.getCurrentPassword()); r.setNewPassword(r.getCurrentPassword()); checkCurrentEqualsNewPassword(r); r.setConfirmPassword((new String(r.getCurrentPassword()) + "1").toCharArray()); r.setNewPassword((new String(r.getCurrentPassword()) + "1").toCharArray()); validator.validateChangeRequest(r); }