TenantObject extends JsonBackedValueObject { @JsonIgnore public TenantObject addTrustAnchor(final PublicKey publicKey, final X500Principal subjectDn, final Boolean autoProvisioningEnabled) { Objects.requireNonNull(publicKey); Objects.requireNonNull(subjectDn); return addTrustAnchor(publicKey.getEncoded(), publicKey.getAlgorithm(), subjectDn, autoProvisioningEnabled); }  @JsonAnySetter TenantObject setProperty(final String name, final Object value); @JsonIgnore String getTenantId(); @JsonIgnore TenantObject setTenantId(final String tenantId); @JsonIgnore boolean isEnabled(); @JsonIgnore TenantObject setEnabled(final boolean flag); @JsonIgnore TenantObject setTrustAnchor(final PublicKey publicKey, final X500Principal subjectDn); @JsonIgnore TenantObject addTrustAnchor(final PublicKey publicKey, final X500Principal subjectDn,
            final Boolean autoProvisioningEnabled); @JsonIgnore TenantObject addTrustAnchor(final byte[] publicKey,
                                       final String publicKeyAlgorithm,
                                       final X500Principal subjectDn,
                                       final Boolean autoProvisioningEnabled); @JsonIgnore Set<TrustAnchor> getTrustAnchors(); @JsonIgnore boolean isAutoProvisioningEnabled(final String subjectDn); @JsonProperty(TenantConstants.FIELD_ADAPTERS) List<Adapter> getAdapters(); @JsonProperty(TenantConstants.FIELD_ADAPTERS) TenantObject setAdapters(final List<Adapter> adapters); @JsonIgnore Adapter getAdapter(final String type); TenantObject addAdapter(final Adapter adapter); @JsonIgnore boolean isAdapterEnabled(final String typeName); @JsonIgnore int getMaxTimeUntilDisconnect(final String typeName); static TenantObject from(final String tenantId, final Boolean enabled); static TenantObject from(final Boolean enabled); @JsonGetter(TenantConstants.FIELD_RESOURCE_LIMITS) ResourceLimits getResourceLimits(); @JsonIgnore TenantObject setResourceLimits(final JsonObject resourceLimits); @JsonSetter(TenantConstants.FIELD_RESOURCE_LIMITS) TenantObject setResourceLimits(final ResourceLimits resourceLimits); @JsonIgnore int getMinimumMessageSize(); TenantObject setMinimumMessageSize(final int payloadSize); @JsonIgnore JsonObject getDefaults(); @JsonIgnore TenantObject setDefaults(final JsonObject defaultProperties); @JsonProperty(value = TenantConstants.FIELD_TRACING) TenantTracingConfig getTracingConfig(); @JsonProperty(value = TenantConstants.FIELD_TRACING) TenantObject setTracingConfig(final TenantTracingConfig tracing);  }
@Test public void testAddTrustAnchor() throws GeneralSecurityException, IOException { final String caName1 = "eclipse.org"; final String caName2 = "acme.com"; final X509Certificate caCert1 = createCaCertificate(caName1); final X509Certificate caCert2 = createCaCertificate(caName2); final TenantObject obj = TenantObject.from(Constants.DEFAULT_TENANT, Boolean.TRUE) .setTrustAnchor(trustedCaCert.getPublicKey(), trustedCaCert.getSubjectX500Principal()) .addTrustAnchor(caCert1.getPublicKey(), caCert1.getSubjectX500Principal(), true) .addTrustAnchor(caCert2.getPublicKey(), caCert2.getSubjectX500Principal(), false); assertThat(obj.getTrustAnchors()).hasSize(3); obj.getTrustAnchors().forEach(trustAnchor -> { switch (trustAnchor.getCAName()) { case "CN=" + caName1: assertThat(trustAnchor.getCA()).isEqualTo(caCert1.getSubjectX500Principal()); assertThat(trustAnchor.getCAPublicKey()).isEqualTo(caCert1.getPublicKey()); assertThat(obj.isAutoProvisioningEnabled(trustAnchor.getCAName())).isTrue(); break; case "CN=" + caName2: assertThat(trustAnchor.getCA()).isEqualTo(caCert2.getSubjectX500Principal()); assertThat(trustAnchor.getCAPublicKey()).isEqualTo(caCert2.getPublicKey()); assertThat(obj.isAutoProvisioningEnabled(trustAnchor.getCAName())).isFalse(); break; default: assertThat(trustAnchor.getCA()).isEqualTo(trustedCaCert.getSubjectX500Principal()); assertThat(trustAnchor.getCAPublicKey()).isEqualTo(trustedCaCert.getPublicKey()); assertThat(obj.isAutoProvisioningEnabled(trustAnchor.getCAName())).isFalse(); } }); }