@Override public <T> Optional<T> ifGet(final String name) { return req.ifGet(name); }
@Override public Object getRequestAttribute(final String name) { Optional<Object> attr = req.ifGet(name); return attr.orElse(null); }
/** * @param name Attribute's name. * @return True if the local attribute is set. */ default boolean isSet(final String name) { return ifGet(name).isPresent(); }
@Override public Object resolve(final Object context, final String name) { Object value = null; if (context instanceof Request) { value = ((Request) context).ifGet(name).orElse(null); } return value == null ? UNRESOLVED : value; }
@Override public Object getRequestAttribute(String name) { return req.ifGet(name).orElse(null); }
/** * Get a request local attribute. * * @param name Attribute's name. * @param def A default value. * @param <T> Target type. * @return A local attribute. */ @Nonnull default <T> T get(final String name, final T def) { Optional<T> opt = ifGet(name); return opt.orElse(def); }
@Override public String getRequestParameter(String name) { String value = req.ifGet("pac4j." + name) .map(Objects::toString) .orElse(params.getOrDefault(name, NO_PARAM)[0]); return value; }
/** * Get a request local attribute. * * @param name Attribute's name. * @param <T> Target type. * @return A local attribute. * @throws Err with {@link Status#BAD_REQUEST}. */ @Nonnull default <T> T get(final String name) { Optional<T> opt = ifGet(name); return opt.orElseThrow( () -> new Err(Status.BAD_REQUEST, "Required local attribute: " + name + " is not present")); }
/** * Give you access to flash scope. Usage: * * <pre>{@code * { * use(new FlashScope()); * * get("/", req -> { * Map<String, String> flash = req.flash(); * return flash; * }); * } * }</pre> * * As you can see in the example above, the {@link FlashScope} needs to be install it by calling * {@link Jooby#use(org.jooby.Jooby.Module)} otherwise a call to this method ends in * {@link Err BAD_REQUEST}. * * @return A mutable map with attributes from {@link FlashScope}. * @throws Err Bad request error if the {@link FlashScope} was not installed it. */ @Nonnull default Flash flash() throws Err { Optional<Flash> flash = ifGet(FlashScope.NAME); return flash.orElseThrow(() -> new Err(Status.BAD_REQUEST, "Flash scope isn't available. Install via: use(new FlashScope());")); }
private String profileID(final boolean useSession, final Request req) { return req.<String>ifGet(Auth.ID) .orElseGet(() -> useSession ? req.session().get(Auth.ID).value(null) : null); }
@Override public void handle(Request req, Response rsp) { WebContext context = req.require(WebContext.class); String redirectTo = req.<String>ifGet("pac4j.logout.redirectTo").orElse(defaultUrl); conf.getLogoutLogic() .perform(context, conf, conf.getHttpActionAdapter(), redirectTo, logoutUrlPattern, localLogout, destroySession, centralLogout); } }
@SuppressWarnings("unchecked") @Override public void handle(final Request req, final Response rsp) throws Throwable { // DON'T create a session for JWT/param/header auth (a.k.a stateless) Optional<Session> ifSession = req.ifSession(); if (ifSession.isPresent()) { Session session = ifSession.get(); Optional<String> profileId = session.unset(Auth.ID).toOptional(); if (profileId.isPresent()) { Optional<CommonProfile> profile = req.require(AuthStore.class).unset(profileId.get()); log.debug("logout {}", profile); session.destroy(); } } else { log.debug("nothing to logout from session"); } String redirectTo = req.<String> ifGet("auth.logout.redirectTo").orElse(this.redirectTo); rsp.redirect(redirectTo); }
@Override public <T> Optional<T> ifGet(final String name) { return req.ifGet(name); }
@Override public Object resolve(final Object context, final String name) { Object value = null; if (context instanceof Request) { value = ((Request) context).ifGet(name).orElse(null); } return value == null ? UNRESOLVED : value; }
/** * @param name Attribute's name. * @return True if the local attribute is set. */ default boolean isSet(final String name) { return ifGet(name).isPresent(); }
@Override public Object getRequestAttribute(final String name) { Optional<Object> attr = req.ifGet(name); return attr.orElse(null); }
/** * Get a request local attribute. * * @param name Attribute's name. * @param def A default value. * @param <T> Target type. * @return A local attribute. */ @Nonnull default <T> T get(final String name, final T def) { Optional<T> opt = ifGet(name); return opt.orElse(def); }
/** * Get a request local attribute. * * @param name Attribute's name. * @param <T> Target type. * @return A local attribute. * @throws Err with {@link Status#BAD_REQUEST}. */ @Nonnull default <T> T get(final String name) { Optional<T> opt = ifGet(name); return opt.orElseThrow( () -> new Err(Status.BAD_REQUEST, "Required local attribute: " + name + " is not present")); }
private String profileID(final boolean useSession, final Request req) { return req.<String>ifGet(Auth.ID) .orElseGet(() -> useSession ? req.session().get(Auth.ID).value(null) : null); }
@SuppressWarnings("unchecked") @Override public void handle(final Request req, final Response rsp) throws Throwable { // DON'T create a session for JWT/param/header auth (a.k.a stateless) Optional<Session> ifSession = req.ifSession(); if (ifSession.isPresent()) { Session session = ifSession.get(); Optional<String> profileId = session.unset(Auth.ID).toOptional(); if (profileId.isPresent()) { Optional<CommonProfile> profile = req.require(AuthStore.class).unset(profileId.get()); log.debug("logout {}", profile); session.destroy(); } } else { log.debug("nothing to logout from session"); } String redirectTo = req.<String> ifGet("auth.logout.redirectTo").orElse(this.redirectTo); rsp.redirect(redirectTo); }