class SpringPlainTextPasswordValidationCallbackHandler extends AbstractCallbackHandler implements InitializingBean {

	@Override
	protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
		if (callback instanceof PasswordValidationCallback) {
			PasswordValidationCallback validationCallback = (PasswordValidationCallback) callback;
			if (validationCallback.getRequest() instanceof PasswordValidationCallback.PlainTextPasswordRequest) {
				validationCallback.setValidator(new SpringSecurityPlainTextPasswordValidator());
				return;
			}
		} else if (callback instanceof CleanupCallback) {
			SecurityContextHolder.clearContext();
			return;
		}
		throw new UnsupportedCallbackException(callback);
	}

}