DefaultOAuthJwtAccessTokenParser implements OAuthJwtAccessTokenParser { public DefaultOAuthJwtAccessTokenParser(KeyStore keyStore, String jwksUrl) throws IllegalArgumentException { if (keyStore == null) { throw new IllegalArgumentException("DefaultOAuthJwtAccessTokenParser: keyStore is null"); } SigningKeyResolver signingKeyResolver = new KeyStoreJwkKeyResolver(keyStore, jwksUrl, null); this.parser = Jwts.parserBuilder() .setSigningKeyResolver(signingKeyResolver) .setAllowedClockSkewSeconds(ALLOWED_CLOCK_SKEW_SECONDS) .build(); } DefaultOAuthJwtAccessTokenParser(KeyStore keyStore, String jwksUrl); @Override OAuthJwtAccessToken parse(String jwtString); static final int ALLOWED_CLOCK_SKEW_SECONDS; }
@Test public void testDefaultOAuthJwtAccessTokenParser() { BiFunction<Field, DefaultOAuthJwtAccessTokenParser, Object> getFieldValue = (f, object) -> { try { f.setAccessible(true); return f.get(object); } catch (IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } }; DefaultOAuthJwtAccessTokenParser parser = null; assertThrows(IllegalArgumentException.class, () -> new DefaultOAuthJwtAccessTokenParser(null, null)); parser = new DefaultOAuthJwtAccessTokenParser(baseKeyStore, null); assertNotNull(parser); for (Field f : parser.getClass().getDeclaredFields()) { switch (f.getName()) { case "parser": assertNotNull(getFieldValue.apply(f, parser)); break; } } parser = new DefaultOAuthJwtAccessTokenParser(baseKeyStore, ""); assertNotNull(parser); for (Field f : parser.getClass().getDeclaredFields()) { switch (f.getName()) { case "parser": assertNotNull(getFieldValue.apply(f, parser)); break; } } parser = new DefaultOAuthJwtAccessTokenParser(baseKeyStore, this.classLoader.getResource("jwt_jwks.json").toString()); assertNotNull(parser); for (Field f : parser.getClass().getDeclaredFields()) { switch (f.getName()) { case "parser": assertNotNull(getFieldValue.apply(f, parser)); break; } } parser = new DefaultOAuthJwtAccessTokenParser(baseKeyStore, "https: assertNotNull(parser); for (Field f : parser.getClass().getDeclaredFields()) { switch (f.getName()) { case "parser": assertNotNull(getFieldValue.apply(f, parser)); break; } } }