JaasPlainTextPasswordValidationCallbackHandler extends AbstractJaasValidationCallbackHandler { @Override protected final void handleInternal(Callback callback) throws UnsupportedCallbackException { if (callback instanceof PasswordValidationCallback) { PasswordValidationCallback validationCallback = (PasswordValidationCallback) callback; if (validationCallback.getRequest() instanceof PasswordValidationCallback.PlainTextPasswordRequest) { validationCallback.setValidator(new JaasPlainTextPasswordValidator()); return; } } throw new UnsupportedCallbackException(callback); }    }
@Test public void testAuthenticateUserPlainTextValid() throws Exception { PasswordValidationCallback.PlainTextPasswordRequest request = new PasswordValidationCallback.PlainTextPasswordRequest( "Bert", "Ernie"); PasswordValidationCallback callback = new PasswordValidationCallback(request); callbackHandler.handleInternal(callback); boolean authenticated = callback.getResult(); Assert.assertTrue("Not authenticated", authenticated); }
@Test public void testAuthenticateUserPlainTextInvalid() throws Exception { PasswordValidationCallback.PlainTextPasswordRequest request = new PasswordValidationCallback.PlainTextPasswordRequest( "Bert", "Big bird"); PasswordValidationCallback callback = new PasswordValidationCallback(request); callbackHandler.handleInternal(callback); boolean authenticated = callback.getResult(); Assert.assertFalse("Authenticated", authenticated); }