be.fedict.hsm.admin.webapp.CertificateView.java Source code

Java tutorial

Introduction

Here is the source code for be.fedict.hsm.admin.webapp.CertificateView.java

Source

/*
 * HSM Proxy Project.
 * Copyright (C) 2013 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see 
 * http://www.gnu.org/licenses/.
 */

package be.fedict.hsm.admin.webapp;

import java.security.cert.X509Certificate;
import java.util.Date;

import org.joda.time.DateMidnight;
import org.joda.time.DateTime;
import org.joda.time.Days;

public class CertificateView {

    private final X509Certificate certificate;

    public CertificateView(X509Certificate certificate) {
        this.certificate = certificate;
    }

    public String getSubject() {
        return this.certificate.getSubjectX500Principal().toString();
    }

    public String getIssuer() {
        return this.certificate.getIssuerX500Principal().toString();
    }

    public String getSerialNumber() {
        return this.certificate.getSerialNumber().toString();
    }

    public Date getNotBefore() {
        return this.certificate.getNotBefore();
    }

    public Date getNotAfter() {
        return this.certificate.getNotAfter();
    }

    public int getDaysLeft() {
        DateTime notAfter = new DateTime(this.certificate.getNotAfter());
        DateTime now = new DateTime();
        Days days = Days.daysBetween(new DateMidnight(now), new DateMidnight(notAfter));
        return days.getDays();
    }
}