public CompletionStage<Result> call(final Context ctx) { Authenticator authenticator = injector.instanceOf(configuration.value()); String username = authenticator.getUsername(ctx); if (username == null) { Result unauthorized = authenticator.onUnauthorized(ctx); return CompletableFuture.completedFuture(unauthorized); } else { try { ctx.request().setUsername(username); return delegate .call(ctx) .whenComplete((result, error) -> ctx.request().setUsername(null)); } catch (Exception e) { ctx.request().setUsername(null); throw e; } } }
public Result call(Context ctx) { try { Authenticator authenticator = configuration.value().newInstance(); String username = authenticator.getUsername(ctx); if (username == null) { return authenticator.onUnauthorized(ctx); } else { try { ctx.request().setUsername(username); return deleguate.call(ctx); } finally { ctx.request().setUsername(null); } } } catch (RuntimeException e) { throw e; } catch (Throwable t) { throw new RuntimeException(t); } }