Auth0JwtParserFactory extends DefaultOAuthJwtAccessTokenParserFactory { @Override public OAuthJwtAccessTokenParser create(KeyStore keyStore) throws IllegalArgumentException { Auth0Jwt.setClaimClientId(GET_PROPERTY.apply(CLAIM_CLIENT_ID, Auth0Jwt.getClaimClientId())); Auth0Jwt.setClaimConfirm(GET_PROPERTY.apply(CLAIM_CONFIRM, Auth0Jwt.getClaimConfirm())); Auth0Jwt.setUserDomain(System.getProperty(AuthorityConsts.ATHENZ_PROP_USER_DOMAIN, Auth0Jwt.getUserDomain())); final String jwksUrl = GET_PROPERTY.apply(JWKS_URL, null); return new Auth0JwtParser(keyStore, jwksUrl); }  @Override OAuthJwtAccessTokenParser create(KeyStore keyStore); static final String CLAIM_CLIENT_ID; static final String CLAIM_CONFIRM; }
@Test public void testAuth0JwtParserFactory() throws OAuthJwtAccessTokenException { OAuthJwtAccessTokenParser parser = null; Auth0JwtParserFactory factory = new Auth0JwtParserFactory(); assertThrows(IllegalArgumentException.class, () -> factory.create(null)); parser = factory.create(baseKeyStore); assertNotNull(parser); String claimClientIdCache = Auth0Jwt.getClaimClientId(); System.clearProperty("athenz.auth.oauth.jwt.parser.auth0.claim_client_id"); parser = factory.create(baseKeyStore); assertEquals(Auth0Jwt.getClaimClientId(), "https: System.setProperty("athenz.auth.oauth.jwt.parser.auth0.claim_client_id", "https: parser = factory.create(baseKeyStore); System.clearProperty("athenz.auth.oauth.jwt.parser.auth0.claim_client_id"); assertEquals(Auth0Jwt.getClaimClientId(), "https: Auth0Jwt.setClaimClientId(claimClientIdCache); String claimConfirmCache = Auth0Jwt.getClaimConfirm(); System.clearProperty("athenz.auth.oauth.jwt.parser.auth0.claim_confirm"); parser = factory.create(baseKeyStore); assertEquals(Auth0Jwt.getClaimConfirm(), "https: System.setProperty("athenz.auth.oauth.jwt.parser.auth0.claim_confirm", "https: parser = factory.create(baseKeyStore); System.clearProperty("athenz.auth.oauth.jwt.parser.auth0.claim_confirm"); assertEquals(Auth0Jwt.getClaimConfirm(), "https: Auth0Jwt.setClaimConfirm(claimConfirmCache); String userDomainCache = Auth0Jwt.getUserDomain(); System.clearProperty("athenz.user_domain"); parser = factory.create(baseKeyStore); assertEquals(Auth0Jwt.getUserDomain(), "user"); System.setProperty("athenz.user_domain", "test_user"); parser = factory.create(baseKeyStore); System.clearProperty("athenz.user_domain"); assertEquals(Auth0Jwt.getUserDomain(), "test_user"); Auth0Jwt.setUserDomain(userDomainCache); String jwtString = "eyJraWQiOiJjOTk4NmVlMy03YjJhLTRkMjAtYjg2YS0wODM5ODU2ZjI1NDEiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJBdXRoMEp3dFBhcnNlckZhY3RvcnlUZXN0In0.FymtIiPJa_9R3xnHkint7sldcJaVdZvy4Y8ENX1SHh4-4tAfGSRVZThwwJhTuqQT8F2HyN-2fynI_lqv58a095MoNarUlLaFmywrmRnmW98fyrnAYNo-bOB7M_x_xnW8ei77y-kXVViK2k2PWAcLYlRUq3Un8XvO5HnzTpF9GjqZzOKdOpRIGFaDTchQ0Fj-gdfGoWfhhjIV4cFF6mJNaEzxgVaWE_f0gCoXNwM0dcgKAhQb1CzwvVMGaAPdqomgwXTOd_wyjIaLSXqMrv66fomjDxg7Kv99HB7P4suQAJUIRUF5gkcXWDrDUTvRqoWWHUVMH-9wOaYcILCybk3gP1ahIfecF6eaQz8P8mEqMMK-EPk6g2m-Tbybv1HS_-LzvCYDCFES8KtZ2FNUljOWW7eIr9Z6TUXKEr-DTs8tIh_SjNhqLM4d1dmZkNa48aHqjTyNqapj2AjWbyzKPqFxkVrs1IuNqH51ofIkRFZmqsBbwim3Ol_R4H78eim1zhISmiJxNuGdU9hCV0XnFm152t-U51MvFvRadm0Puxfw-uYThet2D42qPzA5vC2qLOLoa7NcvfCPxhPaG-yQNo0bHksJI3vkVCNB4vvJvWa112fbl4-Ds5NFQmIkNovg79MYgFmVBWl9FJ4UaSCH8nqB9nHaHQNFkRBzicGmRDiKu88"; System.setProperty("athenz.auth.oauth.jwt.parser.jwks_url", this.classLoader.getResource("jwt_jwks.json").toString()); parser = factory.create(baseKeyStore); System.clearProperty("athenz.auth.oauth.jwt.parser.jwks_url"); OAuthJwtAccessToken token = parser.parse(jwtString); assertEquals(token.getIssuer(), "Auth0JwtParserFactoryTest"); }