@Test public void shouldReturnFalseOnMismatchingSigningKey() { String invalidToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0.Pd6t82" + "tPL3EZdkeYxw_DV2KimE1U2FvuLHmfR_mimJ5US3JFU4J2Gd94O7rwpSTGN1B9h-_lsTebo4ua4xHsTtmczZ9xa8a_kWKaSkqFjNFa" + "Fp6zcoD6ivCu03SlRqsQzSRHXo6TKbnqOt9D6Y2rNa3C4igSwoS0jUE4BgpXbc0"; assertThat(sut.verify(invalidToken)).isFalse(); }
public boolean verify(String token) { try { String subject = extractLogin(token); if (Strings.isNullOrEmpty(subject)) { throw new MalformedJwtException("'subject' field in token is mandatory"); } return true; } catch (JwtException e) { LOGGER.info("Failed Jwt verification", e); return false; } }
JwtTokenVerifier { public boolean verify(String token) { try { String subject = extractLogin(token); if (Strings.isNullOrEmpty(subject)) { throw new MalformedJwtException("'subject' field in token is mandatory"); } return true; } catch (JwtException e) { LOGGER.info("Failed Jwt verification", e); return false; } } }
JwtTokenVerifier { public boolean verify(String token) { try { String subject = extractLogin(token); if (Strings.isNullOrEmpty(subject)) { throw new MalformedJwtException("'subject' field in token is mandatory"); } return true; } catch (JwtException e) { LOGGER.info("Failed Jwt verification", e); return false; } } @Inject @VisibleForTesting  JwtTokenVerifier(PublicKeyProvider pubKeyProvider); }
JwtTokenVerifier { public boolean verify(String token) { try { String subject = extractLogin(token); if (Strings.isNullOrEmpty(subject)) { throw new MalformedJwtException("'subject' field in token is mandatory"); } return true; } catch (JwtException e) { LOGGER.info("Failed Jwt verification", e); return false; } } @Inject @VisibleForTesting  JwtTokenVerifier(PublicKeyProvider pubKeyProvider); boolean verify(String token); String extractLogin(String token); boolean hasAttribute(String attributeName, Object expectedValue, String token); }
JwtTokenVerifier { public boolean verify(String token) { try { String subject = extractLogin(token); if (Strings.isNullOrEmpty(subject)) { throw new MalformedJwtException("'subject' field in token is mandatory"); } return true; } catch (JwtException e) { LOGGER.info("Failed Jwt verification", e); return false; } } @Inject @VisibleForTesting  JwtTokenVerifier(PublicKeyProvider pubKeyProvider); boolean verify(String token); String extractLogin(String token); boolean hasAttribute(String attributeName, Object expectedValue, String token);  }