DefaultOAuthJwtAccessTokenParser implements OAuthJwtAccessTokenParser { @Override public OAuthJwtAccessToken parse(String jwtString) throws OAuthJwtAccessTokenException { OAuthJwtAccessToken accessToken = null; try { Jws<Claims> jws = this.parser.parseClaimsJws(jwtString); accessToken = new DefaultOAuthJwtAccessToken(jws); } catch (Exception ex) { throw new OAuthJwtAccessTokenException(ex); } return accessToken; } DefaultOAuthJwtAccessTokenParser(KeyStore keyStore, String jwksUrl); @Override OAuthJwtAccessToken parse(String jwtString); static final int ALLOWED_CLOCK_SKEW_SECONDS; }
@Test @SuppressWarnings("rawtypes") public void testParse() throws Exception { DefaultOAuthJwtAccessTokenParser parser = new DefaultOAuthJwtAccessTokenParser(baseKeyStore, this.classLoader.getResource("jwt_jwks.json").toString()); JwtParser jwtParserMock = Mockito.mock(JwtParser.class); Field f = parser.getClass().getDeclaredField("parser"); f.setAccessible(true); f.set(parser, jwtParserMock); Mockito.when(jwtParserMock.parseClaimsJws(null)).thenThrow(new NullPointerException()); assertThrows(OAuthJwtAccessTokenException.class, () -> parser.parse(null)); String jwtString = "dummy-jwt-string"; Jws<Claims> jws = new Jws<Claims>() { public JwsHeader getHeader() { return null; } public Claims getBody() { return null; } @Override public String getSignature() { return "dummy-jwt-signature"; } }; Mockito.when(jwtParserMock.parseClaimsJws(jwtString)).thenReturn(jws); OAuthJwtAccessToken token = parser.parse(jwtString); assertNotNull(token); assertTrue(token instanceof DefaultOAuthJwtAccessToken); assertEquals(token.getSignature(), "dummy-jwt-signature"); }