DefaultOAuthJwtAccessTokenValidator implements OAuthJwtAccessTokenValidator { @Override public void validateClientId(OAuthJwtAccessToken jwt, String clientId) throws OAuthJwtAccessTokenException { this.verifyClientId(jwt, clientId); } DefaultOAuthJwtAccessTokenValidator(String trustedIssuer, Set<String> requiredAudiences, Set<String> requiredScopes, Map<String, Set<String>> authorizedClientIds); @Override void validate(OAuthJwtAccessToken jwt); @Override void validateClientId(OAuthJwtAccessToken jwt, String clientId); @Override void validateCertificateBinding(OAuthJwtAccessToken jwt, String certificateThumbprint);  }
@Test public void testValidateClientId() { final DefaultOAuthJwtAccessTokenValidator validator = this.baseValidator; final OAuthJwtAccessToken mock = Mockito.spy(baseJwt); Mockito.doReturn(null).when(mock).getClientId(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, null); } }, "NO mapping of authorized client IDs for certificate principal (null)"); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "no_mapping_1"); } }, "NO mapping of authorized client IDs for certificate principal (no_mapping_1)"); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }, "client_id is not authorized for certificate principal (client_cert_common_name): got=null"); Mockito.doReturn("jwt_client_id").when(mock).getClientId(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, null); } }, "NO mapping of authorized client IDs for certificate principal (null)"); authorizedClientIds.put(null, new HashSet<>(Arrays.asList("null_1, null_2"))); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, null); } }, "client_id is not authorized for certificate principal (null): got=jwt_client_id"); authorizedClientIds.remove(null); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "no_mapping_2"); } }, "NO mapping of authorized client IDs for certificate principal (no_mapping_2)"); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }, "client_id is not authorized for certificate principal (client_cert_common_name): got=jwt_client_id"); Mockito.doReturn("match.principal.1").when(mock).getClientId(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "match.principal.1"); } }, "NO mapping of authorized client IDs for certificate principal (match.principal.1)"); Mockito.doReturn("client_id_1").when(mock).getClientId(); assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }); Mockito.doReturn("match.principal.PPP").when(mock).getClientId(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "match.principal.ppp"); } }, "NO mapping of authorized client IDs for certificate principal (match.principal.ppp)"); Mockito.doReturn("CLIENT_ID_2").when(mock).getClientId(); assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }); Mockito.doReturn("client_id_2").when(mock).getClientId(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }, "client_id is not authorized for certificate principal (client_cert_common_name): got=client_id_2"); }