All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jscep.client.verification.CachingCertificateVerifier Maven / Gradle / Ivy

There is a newer version: 2.5.6
Show newest version
package org.jscep.client.verification;

import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;

/**
 * This CertificateVerifier delegates verification to the provided
 * CertificateVerifier and caches the answer.
 */
public final class CachingCertificateVerifier implements CertificateVerifier {
    /**
     * Previously received verification answers.
     */
    private final Map verificationAnswers;
    /**
     * The verifier to delegate to.
     */
    private final CertificateVerifier delegate;

    /**
     * Constructs a CachingCertificateVerifier which delegates to the
     * specified CertificateVerifier.
     * 
     * @param delegate
     *            the CertificateVerifier to delegate to.
     */
    public CachingCertificateVerifier(final CertificateVerifier delegate) {
        this.delegate = delegate;
        this.verificationAnswers = new HashMap();
    }

    /**
     * This implementation will forward the given certificate to the delegate
     * provided in the constructor, and cache the delegate's response.
     * 

* On every subsequent invocation with the same certificate, the initial * response from the delegate will be returned. * * @param cert * the certificate to verify. * @return the result of calling verify on the delegate * CertificateVerifier. */ @Override public synchronized boolean verify(final X509Certificate cert) { if (verificationAnswers.containsKey(cert)) { return verificationAnswers.get(cert); } else { boolean answer = delegate.verify(cert); verificationAnswers.put(cert, answer); return answer; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy