SimpleTokenManager implements TokenManager { @Override public Optional<SignedJWT> verifyToken(String tokenString) { for (TokenVerifier verifier : verifiers.values()) { LOG.debug("Verifying Token with " + verifier.getName()); try { Optional<SignedJWT> signedJWT = verifier.verifyToken(tokenString); if (signedJWT.isPresent()) { LOG.debug("Token verified with " + verifier.getName()); return signedJWT; } else { LOG.debug("Token could not be verified with " + verifier.getName()); } } catch (Exception ex) { LOG.debug("Token could not be verified with " + verifier.getName()); } } return Optional.empty(); }  @Activate void start(Map<String, Object> props); @Modified void modified(Map<String, Object> props); @Override Optional<SignedJWT> verifyToken(String tokenString); @Override SignedJWT generateUnauthToken(); @Override SignedJWT generateAuthToken(String username); @Override String getTokenString(ContainerRequestContext requestContext); @Override String getTokenString(HttpServletRequest servletRequest); @Override Cookie createSecureTokenCookie(SignedJWT token); @Override NewCookie createSecureTokenNewCookie(SignedJWT token);  }
@Test public void verifyTokenNotValidTest() throws Exception { Optional<SignedJWT> result = manager.verifyToken("error"); assertFalse(result.isPresent()); verify(mobiTokenVerifier).verifyToken("error"); verify(otherVerifier).verifyToken("error"); }
@Test public void verifyTokenIllegalArgumentTest() throws Exception { when(mobiTokenVerifier.verifyToken("error")).thenThrow(new IllegalArgumentException()); Optional<SignedJWT> result = manager.verifyToken("error"); assertFalse(result.isPresent()); verify(mobiTokenVerifier).verifyToken("error"); verify(otherVerifier).verifyToken("error"); }
@Test public void verifyTokenOneValidTest() throws Exception { Optional<SignedJWT> result = manager.verifyToken(MOBI_TOKEN); assertTrue(result.isPresent()); assertEquals(jwt, result.get()); verify(mobiTokenVerifier).verifyToken(MOBI_TOKEN); }