X509AuthProvider extends CredentialsApiAuthProvider<SubjectDnCredentials> { @Override public SubjectDnCredentials getCredentials(final JsonObject authInfo) { Objects.requireNonNull(authInfo); try { final String tenantId = authInfo.getString(CredentialsConstants.FIELD_PAYLOAD_TENANT_ID); final String subjectDn = authInfo.getString(CredentialsConstants.FIELD_PAYLOAD_SUBJECT_DN); if (tenantId == null || subjectDn == null) { return null; } else { final JsonObject clientContext = authInfo.copy(); clientContext.remove(CredentialsConstants.FIELD_PAYLOAD_TENANT_ID); clientContext.remove(CredentialsConstants.FIELD_PAYLOAD_SUBJECT_DN); return SubjectDnCredentials.create(tenantId, subjectDn, clientContext); } } catch (ClassCastException | IllegalArgumentException e) { log.warn("Reading authInfo failed", e); return null; } } @Autowired  X509AuthProvider(final CredentialsClientFactory credentialsClientFactory, final Tracer tracer); @Override SubjectDnCredentials getCredentials(final JsonObject authInfo);  }
@Test void getCredentialsWithoutClientCert() { final JsonObject authInfo = new JsonObject().put("tenant-id", tenantId).put("subject-dn", subjectDN); final SubjectDnCredentials credentials = provider.getCredentials(authInfo); assertEquals(tenantId, credentials.getTenantId()); assertEquals(subjectDN, credentials.getAuthId()); assertTrue(credentials.getClientContext().isEmpty()); }
@Test void getCredentialsWithClientCert() { final JsonObject authInfo = new JsonObject().put("tenant-id", tenantId).put("subject-dn", subjectDN); authInfo.put("client-certificate", encoded); final SubjectDnCredentials credentials = provider.getCredentials(authInfo); assertEquals(tenantId, credentials.getTenantId()); assertEquals(subjectDN, credentials.getAuthId()); assertTrue(credentials.getClientContext().containsKey("client-certificate")); assertArrayEquals(encoded, credentials.getClientContext().getBinary("client-certificate")); }