home-cert-assistant/src/main/java/de/mlessmann/certassist/models/Certificate.java
Magnus Leßmann (@Mark.TwoFive) 8a843dc300
Some checks failed
Build / build (pull_request) Successful in 1m59s
Check formatting / check-formatting (pull_request) Failing after 19s
wip: Generate and configure OpenAPI spec
- Create two (non-functioning) demo endpoints to check the swagger UI with
- Configure Jackson to only serialize specific attributes
- Configure SpringDoc so that only attributes known to Jackson are shown
- Add some shortcut annotations for Json formatting
2025-06-19 23:07:27 +02:00

112 lines
3.5 KiB
Java

package de.mlessmann.certassist.models;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.mlessmann.certassist.web.JsonIsoOffsetDate;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"fingerprint"})})
@Getter
@Setter
@ToString
@RequiredArgsConstructor
public class Certificate {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
@Setter(AccessLevel.NONE)
private String id;
@NotNull
@Enumerated(EnumType.STRING)
@JsonProperty
private CertificateType type;
@JsonProperty
private String trustingAuthority;
/**
* <ul>
* <li>-1 = no requested key length is known (might happen with imported certificates)</li>
* <li>0 = no key is available for this certificate (might happen with trusted third party certificates)</li>
* <li>> 1 = The key length in bits used for the private key of this certificate</li>
* </ul>
*/
@Min(-1)
private int requestedKeyLength;
@JsonIsoOffsetDate
private OffsetDateTime notBefore;
@JsonIsoOffsetDate
private OffsetDateTime notAfter;
@NotNull
@JsonProperty
private String subjectCommonName;
@JsonProperty
private String subjectEmailAddress;
@JsonProperty
private String subjectOrganization;
@JsonProperty
private String subjectOrganizationalUnit;
@JsonProperty
private String subjectCountry;
@JsonProperty
private String subjectState;
@JsonProperty
private String subjectLocality;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@ToString.Exclude
private List<CertificateExtension> certificateExtension = new ArrayList<>();
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
@Column(nullable = false)
private byte[] cert = new byte[0];
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
@Column
private byte[] privateKey = new byte[0];
//@Lob - Cannot annotate column: https://github.com/xerial/sqlite-jdbc/issues/135
@Column
private byte[] fullchain;
@Column(nullable = false)
@JsonProperty
@Schema(description = "The certificate fingerprint. The algorithm used to derive the fingerprint is determined by OpenSSL")
private String fingerprint;
@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy
? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass()
: o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass()
: this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
Certificate that = (Certificate) o;
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
public final int hashCode() {
return this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode()
: getClass().hashCode();
}
}