/** * Creates a TypedKey with the given name. * * @param displayName The name to display when printing this key. * @param <A> The type of value this key is associated with. * @return A fresh key. */ public static <A> TypedKey<A> create(String displayName) { return new TypedKey<>(TypedKey$.MODULE$.apply(displayName)); }
/** * Add an attribute to the request. * * @param key The key of the attribute to add. * @param value The value of the attribute to add. * @param <T> The type of the attribute to add. * @return the request builder with extra attribute */ public <T> RequestBuilder attr(TypedKey<T> key, T value) { req = req.addAttr(key.asScala(), value); return this; }
@Override public Object getAttribute(final String name) { return ofNullable(attributes.get(name)) .orElseGet(() -> playDelegate.attrs().getOptional(TypedKey.create(name)).orElse(null)); }
@Override public CompletionStage<F.Tuple<Optional<? extends Subject>, Http.RequestHeader>> apply(final DeadboltHandler deadboltHandler, final Http.RequestHeader requestHeader) { if (cacheUserPerRequestEnabled) { final TypedKey<Subject> deadboltHandlerCacheId = this.typedKeyCache.computeIfAbsent(deadboltHandler.getId(), k -> TypedKey.create("deadbolt.java.cache-user." + k)); final Optional<? extends Subject> cachedUser = requestHeader.attrs().getOptional(deadboltHandlerCacheId); if (cachedUser.isPresent()) { return CompletableFuture.completedFuture(F.Tuple(cachedUser, requestHeader)); } else { return deadboltHandler.getSubject(requestHeader).thenApply(subjectOption -> subjectOption.map(s -> F.<Optional<? extends Subject>, Http.RequestHeader>Tuple(Optional.of(s), requestHeader.addAttr(deadboltHandlerCacheId, s))).orElseGet(() -> F.Tuple(Optional.empty(), requestHeader))); } } return deadboltHandler.getSubject(requestHeader).thenApply(subjectOption -> subjectOption.map(s -> F.<Optional<? extends Subject>, Http.RequestHeader>Tuple(Optional.of(s), requestHeader)).orElseGet(() -> F.Tuple(Optional.empty(), requestHeader))); } }
/** * Creates a TypedKey without a name. * * @param <A> The type of value this key is associated with. * @return A fresh key. */ public static <A> TypedKey<A> create() { return new TypedKey<>(TypedKey$.MODULE$.apply()); }
/** * Get a value from the map, throwing an exception if it is not present. * * @param key The key for the value to retrieve. * @param <A> The type of value to retrieve. * @return The value, if it is present in the map. * @throws java.util.NoSuchElementException If the value isn't present in the map. */ public <A> A get(TypedKey<A> key) { return underlying.apply(key.asScala()); }
@Override public CompletionStage<F.Tuple<Optional<? extends Subject>, Http.RequestHeader>> apply(final DeadboltHandler deadboltHandler, final Http.RequestHeader requestHeader) { if (cacheUserPerRequestEnabled) { final TypedKey<Subject> deadboltHandlerCacheId = this.typedKeyCache.computeIfAbsent(deadboltHandler.getId(), k -> TypedKey.create("deadbolt.java.cache-user." + k)); final Optional<? extends Subject> cachedUser = requestHeader.attrs().getOptional(deadboltHandlerCacheId); if (cachedUser.isPresent()) { return CompletableFuture.completedFuture(F.Tuple(cachedUser, requestHeader)); } else { return deadboltHandler.getSubject(requestHeader).thenApply(subjectOption -> subjectOption.map(s -> F.<Optional<? extends Subject>, Http.RequestHeader>Tuple(Optional.of(s), requestHeader.addAttr(deadboltHandlerCacheId, s))).orElseGet(() -> F.Tuple(Optional.empty(), requestHeader))); } } return deadboltHandler.getSubject(requestHeader).thenApply(subjectOption -> subjectOption.map(s -> F.<Optional<? extends Subject>, Http.RequestHeader>Tuple(Optional.of(s), requestHeader)).orElseGet(() -> F.Tuple(Optional.empty(), requestHeader))); } }
/** * Creates a TypedKey with the given name. * * @param displayName The name to display when printing this key. * @param <A> The type of value this key is associated with. * @return A fresh key. */ public static <A> TypedKey<A> create(String displayName) { return new TypedKey<>(TypedKey$.MODULE$.apply(displayName)); }
/** * Add an attribute to the request. * * @param key The key of the attribute to add. * @param value The value of the attribute to add. * @param <T> The type of the attribute to add. * @return the request builder with extra attribute */ public <T> RequestBuilder attr(TypedKey<T> key, T value) { req = req.addAttr(key.asScala(), value); return this; }
@Override public CompletionStage<F.Tuple<Optional<Result>, Http.RequestHeader>> apply(final DeadboltHandler deadboltHandler, final Http.RequestHeader requestHeader, final Optional<String> content) { final CompletionStage<Optional<Result>> promise; if (cacheBeforeAuthCheckPerRequestEnabled) { final TypedKey<Boolean> deadboltHandlerCacheId = this.typedKeyCache.computeIfAbsent(deadboltHandler.getId(), k -> TypedKey.create("deadbolt.java.cache-before-auth-check." + k)); if (requestHeader.attrs().containsKey(deadboltHandlerCacheId)) { return CompletableFuture.completedFuture(F.Tuple(Optional.empty(), requestHeader)); } else { return deadboltHandler.beforeAuthCheck(requestHeader, content) .thenApply(beforeAuthCheckOption -> beforeAuthCheckOption.map(r -> F.Tuple(Optional.of(r), requestHeader)).orElse(F.Tuple(Optional.empty(), requestHeader.addAttr(deadboltHandlerCacheId, true)))); } } return deadboltHandler.beforeAuthCheck(requestHeader, content).thenApply(beforeAuthCheckOption -> beforeAuthCheckOption.map(r -> F.Tuple(Optional.of(r), requestHeader)).orElseGet(() -> F.Tuple(Optional.empty(), requestHeader))); } }
/** * Creates a TypedKey with the given name. * * @param displayName The name to display when printing this key. * @param <A> The type of value this key is associated with. * @return A fresh key. */ public static <A> TypedKey<A> create(String displayName) { return new TypedKey<>(TypedKey$.MODULE$.apply(displayName)); }
/** * Add an attribute to the request. * * @param key The key of the attribute to add. * @param value The value of the attribute to add. * @param <T> The type of the attribute to add. * @return the request builder with extra attribute */ public <T> RequestBuilder attr(TypedKey<T> key, T value) { req = req.addAttr(key.asScala(), value); return this; }
@Override public CompletionStage<F.Tuple<Optional<Result>, Http.RequestHeader>> apply(final DeadboltHandler deadboltHandler, final Http.RequestHeader requestHeader, final Optional<String> content) { final CompletionStage<Optional<Result>> promise; if (cacheBeforeAuthCheckPerRequestEnabled) { final TypedKey<Boolean> deadboltHandlerCacheId = this.typedKeyCache.computeIfAbsent(deadboltHandler.getId(), k -> TypedKey.create("deadbolt.java.cache-before-auth-check." + k)); if (requestHeader.attrs().containsKey(deadboltHandlerCacheId)) { return CompletableFuture.completedFuture(F.Tuple(Optional.empty(), requestHeader)); } else { return deadboltHandler.beforeAuthCheck(requestHeader, content) .thenApply(beforeAuthCheckOption -> beforeAuthCheckOption.map(r -> F.Tuple(Optional.of(r), requestHeader)).orElse(F.Tuple(Optional.empty(), requestHeader.addAttr(deadboltHandlerCacheId, true)))); } } return deadboltHandler.beforeAuthCheck(requestHeader, content).thenApply(beforeAuthCheckOption -> beforeAuthCheckOption.map(r -> F.Tuple(Optional.of(r), requestHeader)).orElseGet(() -> F.Tuple(Optional.empty(), requestHeader))); } }
/** * Creates a TypedKey without a name. * * @param <A> The type of value this key is associated with. * @return A fresh key. */ public static <A> TypedKey<A> create() { return new TypedKey<>(TypedKey$.MODULE$.apply()); }
/** * Check if the map contains a value with the given key. * * @param key The key to check for. * @return True if the value is present, false otherwise. */ public boolean containsKey(TypedKey<?> key) { return underlying.contains(key.asScala()); }
/** * Creates a TypedKey without a name. * * @param <A> The type of value this key is associated with. * @return A fresh key. */ public static <A> TypedKey<A> create() { return new TypedKey<>(TypedKey$.MODULE$.apply()); }
/** * Check if the map contains a value with the given key. * * @param key The key to check for. * @return True if the value is present, false otherwise. */ public boolean containsKey(TypedKey<?> key) { return underlying.contains(key.asScala()); }
/** * @param id the id to be used * @return the builder instance */ public RequestBuilder id(Long id) { attr(new TypedKey<>(RequestAttrKey.Id()), id); return this; }
/** * Get a value from the map, throwing an exception if it is not present. * * @param key The key for the value to retrieve. * @param <A> The type of value to retrieve. * @return The value, if it is present in the map. * @throws java.util.NoSuchElementException If the value isn't present in the map. */ public <A> A get(TypedKey<A> key) { return underlying.apply(key.asScala()); }
/** * @param id the id to be used * @return the builder instance */ public RequestBuilder id(Long id) { attr(new TypedKey<>(RequestAttrKey.Id()), id); return this; }