Skip to content

Commit

Permalink
Change REST method to fetch plugin information
Browse files Browse the repository at this point in the history
  • Loading branch information
hmiguim committed Jul 8, 2024
1 parent 6367e8e commit ee7116b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,75 @@
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;
@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 String getIssuerDN() {
return issuerDN;
}

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

public String getSubjectDN() {
return subjectDN;
}
public String getSubjectDN() {
return subjectDN;
}

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

public Date getNotBefore() {
return notBefore;
}
public Date getNotBefore() {
return notBefore;
}

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

public Date getNotAfter() {
return notAfter;
}
public Date getNotAfter() {
return notAfter;
}

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

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

public String getCommonName(String dn) {
return getCertificateInfo(dn, "CN");
}
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";
private String getCertificateInfo(String dn, String field) {
for (String each : dn.split(",\\s")) {
if (each.startsWith(field + "=")) {
return each.substring(field.length() + 1);
}
}
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 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);
}
@Override
public int hashCode() {
return Objects.hash(issuerDN, subjectDN, notBefore, notAfter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
import java.util.HashSet;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
* @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 Set<Certificate> certificates = new HashSet<>();
private boolean notVerified = false;

public CertificateStatus getCertificateStatus() {
return certificateStatus;
Expand All @@ -42,6 +45,7 @@ public void setCertificates(Set<Certificate> certificates) {
this.certificates = certificates;
}

@JsonIgnore
public void addCertificates(String issuer, String subject, Date notBefore, Date notAfter) {
Certificate certificate = new Certificate();
certificate.setIssuerDN(issuer);
Expand All @@ -51,12 +55,8 @@ public void addCertificates(String issuer, String subject, Date notBefore, Date
this.certificates.add(certificate);
}

public boolean isNotVerified(){
@JsonIgnore
public boolean isNotVerified() {
return getCertificateStatus().equals(CertificateStatus.NOT_VERIFIED);
}

public void setNotVerified(boolean notVerified) {
this.notVerified = notVerified;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ public PluginInfoList getPluginsInfo(List<PluginType> pluginTypes) {
PluginInfoList pluginsInfo = new PluginInfoList();

for (PluginType pluginType : pluginTypes) {
pluginsInfo.addObjects(pluginInfoPerType.getOrDefault(pluginType, Collections.emptyList()));
List<PluginInfo> orDefault = pluginInfoPerType.getOrDefault(pluginType, Collections.emptyList());
orDefault.removeIf(p -> p.getCategories().contains(RodaConstants.PLUGIN_CATEGORY_NOT_LISTABLE));
pluginsInfo.addObjects(orDefault);
}

return pluginsInfo;
Expand Down Expand Up @@ -767,7 +769,7 @@ private void addStartupPluginJars(Path jarPath, Attributes mainAttributes, List<
boolean optIn = configurationManager.getProperty(RodaConstants.PLUGINS_CERTIFICATE_OPT_IN_PROPERTY, false);
CertificateInfo certificateInfo = PluginCertificateUtils.loadAndCheckCertificates(jarPath);
if (!certificateInfo.isNotVerified() || optIn) {
LOGGER.info("Adding startup jars from auth plugin " + authPluginClassNamesString);
LOGGER.info("Adding startup jars from auth plugin {}", authPluginClassNamesString);
URLClassLoader classLoader = new URLClassLoader(jarClasspath.toArray(new URL[] {}),
getClass().getClassLoader());
jarStartupPluginsClassloaderCache.put(authPluginClassNamesString, classLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ core.user_registration.disabled = false
# Plugins certificates setting
#
##########################################################################
core.plugins.external.certificates.opt-in = true
# core.plugins.external.certificates.opt-in = false
# core.plugins.external.certificates.custom.truststore.enable = false
# core.plugins.external.certificates.custom.truststore.type = PKCS12
# core.plugins.external.certificates.custom.truststore.name = custom-truststore.p12
Expand Down

0 comments on commit ee7116b

Please sign in to comment.