/** * Check if the access token is expired or not. * @return */ public boolean expired() { boolean ret = delegate.expired(); return ret; }
/** * Check if the access token is expired or not. * @return */ public boolean expired() { boolean ret = delegate.expired(); return ret; }
@Override public OAuth2Auth introspectToken(String token, String tokenType, Handler<AsyncResult<AccessToken>> handler) { try { // attempt to create a token object from the given string representation final AccessToken accessToken = new OAuth2TokenImpl(this, new JsonObject().put(tokenType, token)); // if token is expired avoid going to the server if (accessToken.expired()) { handler.handle(Future.failedFuture("Expired token")); return this; } // perform the introspection accessToken.introspect(introspect -> { if (introspect.failed()) { handler.handle(Future.failedFuture(introspect.cause())); return; } // the access token object should have updated it's claims/authorities plus expiration, recheck if (accessToken.expired()) { handler.handle(Future.failedFuture("Expired token")); return; } // return self handler.handle(Future.succeededFuture(accessToken)); }); } catch (RuntimeException e) { handler.handle(Future.failedFuture(e)); } return this; }
@Test public void tokenShouldNotBeExpired() { config = oauthConfig; oauth2.authenticate(tokenConfig, res -> { if (res.failed()) { fail(res.cause().getMessage()); } else { AccessToken token = (AccessToken) res.result(); assertFalse(token.expired()); testComplete(); } }); await(); }
@Test public void tokenShouldBeExpiredWhenExpirationDateIsInThePast() { config = oauthConfig; oauth2.authenticate(tokenConfig, res -> { if (res.failed()) { fail(res.cause().getMessage()); } else { AccessToken token = (AccessToken) res.result(); // hack the token to set the expires_at (to yesterday) token.principal().put("expires_at", System.currentTimeMillis() - 24 * 60 * 60 * 1000); assertTrue(token.expired()); testComplete(); } }); await(); }