@Test public void testCorrectBehaviourWhenNoTokenInSession() throws Exception { PowerMockito. mockStatic(UUID.class); when(UUID.randomUUID()).thenReturn(RANDOM_UUID); final CompletableFuture<String> future = new CompletableFuture<>(); final DefaultAsyncCsrfTokenGenerator generator = new DefaultAsyncCsrfTokenGenerator(); vertx.runOnContext(v -> { final CompletableFuture<String> csrfToken = generator.get(webContext); csrfToken.thenAccept(s -> future.complete(s)); }); final String retrievedCsrfToken = future.get(); assertThat(retrievedCsrfToken, is(RANDOM_UUID.toString())); }
@Override public CompletableFuture<String> get(AsyncWebContext context) { return withFallback(context.getSessionStore().get(context, Pac4jConstants.CSRF_TOKEN), () -> { final String token = UUID.randomUUID().toString(); final CompletableFuture<String> tokenFuture = new CompletableFuture<>(); context.getSessionStore().set(context, Pac4jConstants.CSRF_TOKEN, token) .thenAccept(v -> { tokenFuture.complete(token); }); return tokenFuture; }); }
DefaultAsyncCsrfTokenGenerator implements AsyncCsrfTokenGenerator { @Override public CompletableFuture<String> get(AsyncWebContext context) { return withFallback(context.getSessionStore().get(context, Pac4jConstants.CSRF_TOKEN), () -> { final String token = UUID.randomUUID().toString(); final CompletableFuture<String> tokenFuture = new CompletableFuture<>(); context.getSessionStore().set(context, Pac4jConstants.CSRF_TOKEN, token) .thenAccept(v -> { tokenFuture.complete(token); }); return tokenFuture; }); } }
DefaultAsyncCsrfTokenGenerator implements AsyncCsrfTokenGenerator { @Override public CompletableFuture<String> get(AsyncWebContext context) { return withFallback(context.getSessionStore().get(context, Pac4jConstants.CSRF_TOKEN), () -> { final String token = UUID.randomUUID().toString(); final CompletableFuture<String> tokenFuture = new CompletableFuture<>(); context.getSessionStore().set(context, Pac4jConstants.CSRF_TOKEN, token) .thenAccept(v -> { tokenFuture.complete(token); }); return tokenFuture; }); }  }
DefaultAsyncCsrfTokenGenerator implements AsyncCsrfTokenGenerator { @Override public CompletableFuture<String> get(AsyncWebContext context) { return withFallback(context.getSessionStore().get(context, Pac4jConstants.CSRF_TOKEN), () -> { final String token = UUID.randomUUID().toString(); final CompletableFuture<String> tokenFuture = new CompletableFuture<>(); context.getSessionStore().set(context, Pac4jConstants.CSRF_TOKEN, token) .thenAccept(v -> { tokenFuture.complete(token); }); return tokenFuture; }); }  @Override CompletableFuture<String> get(AsyncWebContext context); }
DefaultAsyncCsrfTokenGenerator implements AsyncCsrfTokenGenerator { @Override public CompletableFuture<String> get(AsyncWebContext context) { return withFallback(context.getSessionStore().get(context, Pac4jConstants.CSRF_TOKEN), () -> { final String token = UUID.randomUUID().toString(); final CompletableFuture<String> tokenFuture = new CompletableFuture<>(); context.getSessionStore().set(context, Pac4jConstants.CSRF_TOKEN, token) .thenAccept(v -> { tokenFuture.complete(token); }); return tokenFuture; }); }  @Override CompletableFuture<String> get(AsyncWebContext context);  }