SubjectDnCredentials extends AbstractDeviceCredentials { public static SubjectDnCredentials create(final String tenantId, final String subjectDn) { Objects.requireNonNull(tenantId); Objects.requireNonNull(subjectDn); return create(tenantId, subjectDn, new JsonObject()); } private  SubjectDnCredentials(final String tenantId, final String authId, final JsonObject clientContext); static SubjectDnCredentials create(final String tenantId, final String subjectDn); static SubjectDnCredentials create(final String tenantId, final String subjectDn,
            final JsonObject clientContext); static SubjectDnCredentials create(final String tenantId, final X500Principal subjectDn); static SubjectDnCredentials create(final String tenantId, final X500Principal subjectDn,
            final JsonObject clientContext); @Override String getType();  }
@Test public void testAuthIdIsRFC2253Compliant() { final String subjectDn = "emailAddress=hoge@acme.com, CN=devices, OU=ACME Department, O=ACME Corporation, L=Chiyoda, ST=Tokyo, C=JP"; final SubjectDnCredentials credentials = SubjectDnCredentials.create("tenant", subjectDn); assertThat(credentials.getAuthId()) .isEqualTo("1.2.840.113549.1.9.1=#160d686f67654061636d652e636f6d,CN=devices,OU=ACME Department,O=ACME Corporation,L=Chiyoda,ST=Tokyo,C=JP"); }
@Test public void testClientContextCreatedIsNotNull() { final SubjectDnCredentials credentials1 = SubjectDnCredentials.create("tenant", "CN=eclipse.org"); assertThat(credentials1.getClientContext()).isNotNull(); final SubjectDnCredentials credentials2 = SubjectDnCredentials.create("tenant", new X500Principal("CN=eclipse.org")); assertThat(credentials2.getClientContext()).isNotNull(); }
@Test public void testCreateDoesNotAllowNullClientContext() { assertThatThrownBy(() -> SubjectDnCredentials.create("tenant", "CN=eclipse.org", null)) .isInstanceOf(NullPointerException.class); }
@Test public void testCreateDoesNotAllowNullClientContextWithPrincipal() { assertThatThrownBy(() -> SubjectDnCredentials.create("tenant", new X500Principal("CN=eclipse.org"), null)) .isInstanceOf(NullPointerException.class); }