/** * Provides a token generator which tries to always provide a valid token. * * @param config the configuration to fetch a token * @param httpClient used http client * @param closeHttpClient set to true, if the httpClient should be closed with the created SphereAccessTokenSupplier * @return token service */ static SphereAccessTokenSupplier ofAutoRefresh(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(config, httpClient, closeHttpClient); }
public static SphereAccessTokenSupplier createAndBeginRefreshInBackground(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return new AutoRefreshSphereAccessTokenSupplierImpl(config, httpClient, closeHttpClient); }
@Override protected void internalClose() { closeQuietly(authActor); closeQuietly(tokenActor); }
private boolean currentTokenIsOlder(final Tokens newTokens) { return (currentTokensOption.isPresent() && oldExpiringZonedDateTime().isBefore(newExpiringZonedDateTime(newTokens))); }
private void requestUpdateFailedStatus(final Throwable error) { if (!currentTokensOption.isPresent()) { currentAccessTokenFuture.completeExceptionally(error); } else if (lastTokenIsStillValid()) { //keep the old token } else { currentTokensOption = Optional.empty(); currentAccessTokenFuture = CompletableFutureUtils.failed(error); } authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage());// }
private void requestUpdateTokens(final Tokens tokens) { if (!currentTokensOption.isPresent() || currentTokenIsOlder(tokens)) { currentTokensOption = Optional.ofNullable(tokens); final String accessToken = tokens.getAccessToken(); if (currentAccessTokenFuture.isDone()) { currentAccessTokenFuture = CompletableFutureUtils.successful(accessToken); } else { currentAccessTokenFuture.complete(accessToken); } } }
private boolean currentTokenIsOlder(final Tokens newTokens) { return (currentTokensOption.isPresent() && oldExpiringZonedDateTime().isBefore(newExpiringZonedDateTime(newTokens))); }
private void requestUpdateFailedStatus(final Throwable error) { if (!currentTokensOption.isPresent()) { currentAccessTokenFuture.completeExceptionally(error); } else if (lastTokenIsStillValid()) { //keep the old token } else { currentTokensOption = Optional.empty(); currentAccessTokenFuture = CompletableFutureUtils.failed(error); } authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage());// }
private void requestUpdateTokens(final Tokens tokens) { if (!currentTokensOption.isPresent() || currentTokenIsOlder(tokens)) { currentTokensOption = Optional.ofNullable(tokens); final String accessToken = tokens.getAccessToken(); if (currentAccessTokenFuture.isDone()) { currentAccessTokenFuture = CompletableFutureUtils.successful(accessToken); } else { currentAccessTokenFuture.complete(accessToken); } } }
/** * Provides a token generator which tries to always provide a valid token. * * @param config the configuration to fetch a token * @param httpClient used http client * @param closeHttpClient set to true, if the httpClient should be closed with the created SphereAccessTokenSupplier * @return token service */ static SphereAccessTokenSupplier ofAutoRefresh(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(config, httpClient, closeHttpClient); }
private boolean currentTokenIsOlder(final Tokens newTokens) { return (currentTokensOption.isPresent() && oldExpiringZonedDateTime().isBefore(newExpiringZonedDateTime(newTokens))); }
@Override protected void internalClose() { closeQuietly(supervisor); closeQuietly(authActor); }
public static SphereAccessTokenSupplier createAndBeginRefreshInBackground(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return new AutoRefreshSphereAccessTokenSupplierImpl(config, httpClient, closeHttpClient); }
/** * Provides a token generator which tries to always provide a valid token. * * @param config the configuration to fetch a token * @param httpClient used http client * @param closeHttpClient set to true, if the httpClient should be closed with the created SphereAccessTokenSupplier * @return token service */ static SphereAccessTokenSupplier ofAutoRefresh(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(config, httpClient, closeHttpClient); }
@Override protected void internalClose() { closeQuietly(authActor); closeQuietly(tokenActor); }
public static SphereAccessTokenSupplier createAndBeginRefreshInBackground(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return new AutoRefreshSphereAccessTokenSupplierImpl(config, httpClient, closeHttpClient); }
/** * Provides a token generator which tries to always provide a valid token. * * @param config the configuration to fetch a token * @param httpClient used http client * @param closeHttpClient set to true, if the httpClient should be closed with the created SphereAccessTokenSupplier * @return token service */ static SphereAccessTokenSupplier ofAutoRefresh(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(config, httpClient, closeHttpClient); }
@Override protected void internalClose() { closeQuietly(supervisor); closeQuietly(authActor); }
public static SphereAccessTokenSupplier createAndBeginRefreshInBackground(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return new AutoRefreshSphereAccessTokenSupplierImpl(config, httpClient, closeHttpClient); }
@Test public void refreshesAfterTimeoutOfToken() throws Exception { final TestDoubleHttpClient httpClient = getHttpClient(); try(final SphereAccessTokenSupplier supplier = AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(SphereAuthConfig.of("project-key", "client-id", "clientSecret"), httpClient, true)) { Thread.sleep(3000); assertThat(httpClient.getTimesCalledCount()).isGreaterThan(2).isLessThan(5); } }