/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final CharSequence value) { return set(name, value.toString()); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final long value) { return set(name, Long.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final char value) { return set(name, Character.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final float value) { return set(name, Float.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final byte value) { return set(name, Byte.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final boolean value) { return set(name, Boolean.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final short value) { return set(name, Short.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final int value) { return set(name, Integer.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final double value) { return set(name, Double.toString(value)); }
@Override public void set(final U profile) throws Exception { this.session.get().set(key(profile.getId()), AuthSerializer.objToStr(profile)); }
@Override public void setSessionAttribute(final String name, final Object value) { Session session = req.session(); if (value == null) { session.unset(name); } else { session.set(name, AuthSerializer.objToStr(value)); } }
@Override public void set(WebContext context, String key, Object value) { if (value == null) { req.ifSession().ifPresent(session -> session.unset(key)); } else { req.session().set(key, objToStr(value)); } }
@Override public void handle(final Request req, final Response rsp, final Route.Chain chain) throws Throwable { /** * Get or generate a token */ Session session = req.session(); String token = session.get(name).toOptional().orElseGet(() -> { String newToken = generator.apply(req); session.set(name, newToken); return newToken; }); req.set(name, token); if (requireToken.test(req)) { String candidate = req.header(name).toOptional() .orElseGet(() -> req.param(name).toOptional().orElse(null)); if (!token.equals(candidate)) { throw new Err(Status.FORBIDDEN, "Invalid Csrf token: " + candidate); } } chain.next(req, rsp); } }
String id = profile.getId(); req.set(Auth.ID, id); session.set(Auth.ID, id); store.set(profile);
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final char value) { return set(name, Character.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final int value) { return set(name, Integer.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final float value) { return set(name, Float.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final byte value) { return set(name, Byte.toString(value)); }
/** * Set a session local using a the given name. If a local already exists, it will be replaced * with the new value. Keep in mind that null values are NOT allowed. * * @param name Attribute's name. * @param value Attribute's value. * @return This session. */ @Nonnull default Session set(final String name, final double value) { return set(name, Double.toString(value)); }
@Override public void setSessionAttribute(final String name, final Object value) { Session session = req.session(); if (value == null) { session.unset(name); } else { session.set(name, AuthSerializer.objToStr(value)); } }