class SpringCertificateValidationCallbackHandler extends AbstractCallbackHandler implements InitializingBean {

	@Override
	protected void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
		if (callback instanceof CertificateValidationCallback) {
			((CertificateValidationCallback) callback).setValidator(new SpringSecurityCertificateValidator());
		} else if (callback instanceof CleanupCallback) {
			SecurityContextHolder.clearContext();
		} else {
			throw new UnsupportedCallbackException(callback);
		}
	}

}