@Test public void verifyShouldReturnFalseWhenSubjectIsNull() { String tokenWithNullSubject = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOm51bGwsIm5hbWUiOiJKb2huIERvZSJ9.EB" + "_1grWDy_kFelXs3AQeiP13ay4eG_134dWB9XPRSeWsuPs8Mz2UY-VHDxLGD-fAqv-xKXr4QFEnS7iZkdpe0tPLNSwIjqeqkC6KqQln" + "oC1okqWVWBDOcf7Acp1Jzp_cFTUhL5LkHvZDsyCdq5T9OOVVkzO4A9RrzIUsTrYPtRCBuYJ3ggR33cKpw191PulPGNH70rZqpUfDXe" + "VPY3q15vWzZH9O9IJzB2KdHRMPxl2luRjzDbh4DLp56NhZuLX_2a9UAlmbV8MQX4Z_04ybhAYrcBfxR3MgJyr0jlxSibqSbXrkXuo-" + "PyybfZCIhK_qXUlO5OS6sO7AQhKZO9p0MQ"; assertThat(sut.verify(tokenWithNullSubject)).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);  }