Skip to content

Commit

Permalink
Changes to object Certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard committed Jul 8, 2024
1 parent b74e196 commit 6367e8e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.roda.core.data.v2.jobs;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

public class Certificate implements Serializable {
@Serial
private static final long serialVersionUID = -4981616458177975741L;
private String issuerDN = null;
private String subjectDN = null;
private Date notBefore = null;
private Date notAfter = null;

public String getIssuerDN() {
return issuerDN;
}

public void setIssuerDN(String issuerDN) {
this.issuerDN = issuerDN;
}

public String getSubjectDN() {
return subjectDN;
}

public void setSubjectDN(String subjectDN) {
this.subjectDN = subjectDN;
}

public Date getNotBefore() {
return notBefore;
}

public void setNotBefore(Date notBefore) {
this.notBefore = notBefore;
}

public Date getNotAfter() {
return notAfter;
}

public void setNotAfter(Date notAfter) {
this.notAfter = notAfter;
}

public String getOrganizationName(String dn) {
return getCertificateInfo(dn, "O");
}

public String getCommonName(String dn) {
return getCertificateInfo(dn, "CN");
}

private String getCertificateInfo(String dn, String field) {
for (String each : dn.split(",\\s")) {
if (each.startsWith(field + "=")) {
String result = each.substring(field.length() + 1);
return result;
}
}
return "NOT FOUND";
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Certificate that = (Certificate) o;
return Objects.equals(issuerDN, that.issuerDN) && Objects.equals(subjectDN, that.subjectDN)
&& Objects.equals(notBefore, that.notBefore) && Objects.equals(notAfter, that.notAfter);
}

@Override
public int hashCode() {
return Objects.hash(issuerDN, subjectDN, notBefore, notAfter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
*/
package org.roda.core.data.v2.jobs;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
* @author Gabriel Barros <[email protected]>
*/
public class CertificateInfo implements Serializable {
@Serial
private static final long serialVersionUID = 5755199988566186742L;
public enum CertificateStatus {
INTERNAL, VERIFIED, NOT_VERIFIED
}
private CertificateStatus certificateStatus = CertificateStatus.INTERNAL;
private HashSet<Certificate> certificates = new HashSet<>();
private Set<Certificate> certificates = new HashSet<>();
private boolean notVerified = false;

public CertificateStatus getCertificateStatus() {
return certificateStatus;
Expand All @@ -31,10 +34,14 @@ public void setCertificateStatus(CertificateStatus status) {
certificateStatus = status;
}

public HashSet<Certificate> getCertificates() {
public Set<Certificate> getCertificates() {
return certificates;
}

public void setCertificates(Set<Certificate> certificates) {
this.certificates = certificates;
}

public void addCertificates(String issuer, String subject, Date notBefore, Date notAfter) {
Certificate certificate = new Certificate();
certificate.setIssuerDN(issuer);
Expand All @@ -48,77 +55,8 @@ public boolean isNotVerified(){
return getCertificateStatus().equals(CertificateStatus.NOT_VERIFIED);
}

public static class Certificate implements Serializable {
private static final long serialVersionUID = -4981616458177975741L;
private String issuerDN = null;
private String subjectDN = null;
private Date notBefore = null;
private Date notAfter = null;

public String getIssuerDN() {
return issuerDN;
}

public void setIssuerDN(String issuerDN) {
this.issuerDN = issuerDN;
}

public String getSubjectDN() {
return subjectDN;
}

public void setSubjectDN(String subjectDN) {
this.subjectDN = subjectDN;
}

public Date getNotBefore() {
return notBefore;
}

public void setNotBefore(Date notBefore) {
this.notBefore = notBefore;
}

public Date getNotAfter() {
return notAfter;
}

public void setNotAfter(Date notAfter) {
this.notAfter = notAfter;
}

public String getOrganizationName(String dn) {
return getCertificateInfo(dn, "O");
}

public String getCommonName(String dn) {
return getCertificateInfo(dn, "CN");
}

private String getCertificateInfo(String dn, String field) {
for (String each : dn.split(",\\s")) {
if (each.startsWith(field + "=")) {
String result = each.substring(field.length() + 1);
return result;
}
}
return "NOT FOUND";
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Certificate that = (Certificate) o;
return Objects.equals(issuerDN, that.issuerDN) && Objects.equals(subjectDN, that.subjectDN)
&& Objects.equals(notBefore, that.notBefore) && Objects.equals(notAfter, that.notAfter);
}

@Override
public int hashCode() {
return Objects.hash(issuerDN, subjectDN, notBefore, notAfter);
}
public void setNotVerified(boolean notVerified) {
this.notVerified = notVerified;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.roda.core.data.v2.ip.IndexedFile;
import org.roda.core.data.v2.ip.IndexedRepresentation;
import org.roda.core.data.v2.ip.Representation;
import org.roda.core.data.v2.jobs.Certificate;
import org.roda.core.data.v2.jobs.CertificateInfo;
import org.roda.core.data.v2.jobs.IndexedReport;
import org.roda.core.data.v2.jobs.Job;
Expand Down Expand Up @@ -564,7 +565,7 @@ private void buildPluginStatusPanel() {
} else if (CertificateInfo.CertificateStatus.VERIFIED.equals(certificateStatus)) {
badgePanel.setIcon("fas fa-shield-alt");
badgePanel.addStyleName("badge-panel-success");
CertificateInfo.Certificate certificate = certificateInfo.getCertificates().iterator().next();
Certificate certificate = certificateInfo.getCertificates().iterator().next();
String issuer = certificate.getOrganizationName(certificate.getIssuerDN());
String subject = certificate.getOrganizationName(certificate.getSubjectDN());
statusMessage.setHTML(messages.pluginTrustedMessage(issuer, subject));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.roda.core.data.v2.index.select.SelectedItemsList;
import org.roda.core.data.v2.index.select.SelectedItemsNone;
import org.roda.core.data.v2.ip.TransferredResource;
import org.roda.core.data.v2.jobs.Certificate;
import org.roda.core.data.v2.jobs.CertificateInfo;
import org.roda.core.data.v2.jobs.JobParallelism;
import org.roda.core.data.v2.jobs.JobPriority;
Expand Down Expand Up @@ -544,7 +545,7 @@ private void buildPluginStatusPanel() {
} else if (CertificateInfo.CertificateStatus.VERIFIED.equals(certificateStatus)) {
badgePanel.setIcon("fas fa-shield-alt");
badgePanel.addStyleName("badge-panel-success");
CertificateInfo.Certificate certificate = certificateInfo.getCertificates().iterator().next();
Certificate certificate = certificateInfo.getCertificates().iterator().next();
String issuer = certificate.getOrganizationName(certificate.getIssuerDN());
String subject = certificate.getOrganizationName(certificate.getSubjectDN());
statusMessage.setHTML(messages.pluginTrustedMessage(issuer, subject));
Expand Down

0 comments on commit 6367e8e

Please sign in to comment.