TrustedCertificateAuthority { @JsonIgnore public final boolean isValid() { if (cert != null) { return true; } else if (subjectDn == null || publicKey == null || notBefore == null || notAfter == null) { return false; } else { try { final String alg = Optional.ofNullable(keyAlgorithm).orElse("RSA"); KeyFactory.getInstance(alg).generatePublic(new X509EncodedKeySpec(publicKey)); return true; } catch (final GeneralSecurityException | IllegalArgumentException e) { return false; } } }  @JsonIgnore final boolean isValid(); @JsonProperty(value = TenantConstants.FIELD_PAYLOAD_SUBJECT_DN) final TrustedCertificateAuthority setSubjectDn(final String subjectDn); final TrustedCertificateAuthority setSubjectDn(final X500Principal subjectDn); final X500Principal getSubjectDn(); @JsonProperty(value = TenantConstants.FIELD_PAYLOAD_SUBJECT_DN) final String getSubjectDnAsString(); @JsonProperty(TenantConstants.FIELD_PAYLOAD_PUBLIC_KEY) final TrustedCertificateAuthority setPublicKey(final byte[] publicKey); @JsonProperty(TenantConstants.FIELD_PAYLOAD_PUBLIC_KEY) final byte[] getPublicKey(); @JsonProperty(TenantConstants.FIELD_PAYLOAD_CERT) final TrustedCertificateAuthority setCertificate(final byte[] certificate); final TrustedCertificateAuthority setKeyAlgorithm(final String keyAlgorithm); final String getKeyAlgorithm(); final TrustedCertificateAuthority setNotBefore(final Instant notBefore); final Instant getNotBefore(); final TrustedCertificateAuthority setNotAfter(final Instant notAfter); final Instant getNotAfter(); final boolean isAutoProvisioningEnabled(); final TrustedCertificateAuthority setAutoProvisioningEnabled(final boolean enabled);  }
@Test public void testDecodeTrustedCAUsingCert() throws CertificateEncodingException { final JsonObject ca = new JsonObject() .put(RegistryManagementConstants.FIELD_PAYLOAD_CERT, certificate.getEncoded()); final TrustedCertificateAuthority authority = ca.mapTo(TrustedCertificateAuthority.class); assertThat(authority.isValid()).isTrue(); assertAuthority(authority); }