@Test public void verifyShouldReturnFalseWhenEmptySubject() { String tokenWithEmptySubject = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIiLCJuYW1lIjoiSm9obiBEb2UifQ.UdY" + "s2PPzFCegUYspoDCnlJR_bJm8_z1InOv4v3tq8SJETQUarOXlhb_n6y6ujVvmJiSx9dI24Hc3Czi3RGUOXbnBDj1WPfd0aVSiUSqZr" + "MCHBt5vjCYqAseDaP3w4aiiFb6EV3tteJFeBLZx8XlKPYxlzRLLUADDyDSQvrFBBPxfsvCETZovKdo9ofIN64o-yx23ss63yE6oIOd" + "zJZ1Id40KSR2d7l3kIQJPLKUWJDnro5RAh4DOGOWNSq0JSbMhk7Zn3cXIBUpv3R8p79tui1UQpzwHMC0e6OSuWEDNQHtq-Cz85u8GG" + "sUSbogmgObA_BimNtUq_Q1p0SGtIYBXmQ"; assertThat(sut.verify(tokenWithEmptySubject)).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);  }