Example usage for javax.security.cert X509Certificate getInstance

List of usage examples for javax.security.cert X509Certificate getInstance

Introduction

In this page you can find the example usage for javax.security.cert X509Certificate getInstance.

Prototype

public static final X509Certificate getInstance(byte[] certData) throws CertificateException 

Source Link

Document

Instantiates an X509Certificate object, and initializes it with the specified byte array.

Usage

From source file:pl.psnc.synat.wrdz.zu.certificate.CertificateChecker.java

/**
 * Checks whether any active users' certificates are beyond the expiration threshold.
 *//*from w  w  w  .  j a v  a  2 s . c  o m*/
@TransactionAttribute
public void checkCertificates() {

    List<UserAuthentication> auths = userAuthDao.findAll();

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, configuration.getCertificateCheckThreshold());
    Date cutoff = cal.getTime();

    for (UserAuthentication auth : auths) {
        if (auth.getActive() && auth.getCertificate() != null) {
            try {
                X509Certificate certificate = X509Certificate
                        .getInstance(Base64.decodeBase64(auth.getCertificate()));
                if (cutoff.after(certificate.getNotAfter())) {
                    notifyExpirationCheckFail(auth.getUser().getUsername());
                }
            } catch (CertificateException e) {
                logger.warn("Certificate could not be read", e);
            }
        }
    }
}