/** * Public ctor, from exact values. * @param base Base URI where we're using it * @param message The message * @param level The level * @param msec Milliseconds consumed * @checkstyle ParameterNumber (5 lines) */ public Flash(@NotNull final URI base, @NotNull final String message, @NotNull final Level level, final long msec) { super( new CookieBuilder(base) .name(FlashInset.COOKIE) .value(FlashInset.Flash.encode(message, level, msec)) .temporary() .build() ); Validate.notBlank(message, "flash message can't be empty"); this.msg = message; this.lvl = level; Validate.isTrue( msec >= 0L || msec == -1L, "milliseconds can either be positive or equal to -1" ); this.millis = msec; } /**
/** * Logout authentication cookie. * * <p>Use this cookie to log user out of the system, for example: * * <pre> if (you_are_not_allowed()) { * throw new AuthException( * Response.seeOther(this.uriInfo().getBaseUri()) * .cookie(this.auth().logout()) * .build() * ); * } * </pre> * * @return The cookie */ @Cacheable.FlushAfter public NewCookie logout() { return new CookieBuilder(this.resource.uriInfo().getBaseUri()) .name(AuthInset.AUTH_COOKIE) .build(); }
@Override public void render(@NotNull final BasePage<?, ?> page, @NotNull final Response.ResponseBuilder builder) { if (this.resource.httpHeaders().getCookies() .containsKey(FlashInset.COOKIE)) { final FlashInset.Flash cookie = new FlashInset.Flash( this.resource.httpHeaders().getCookies().get(FlashInset.COOKIE) ); page.append( FlashInset.bundle( cookie.level(), cookie.message(), cookie.msec() ) ); builder.cookie( new CookieBuilder(this.resource.uriInfo().getBaseUri()) .name(FlashInset.COOKIE) .build() ); } }
/** * Authentication cookie. * @param identity The identity to wrap into the cookie * @return The cookie */ public NewCookie cookie(final Identity identity) { return new CookieBuilder(this.resource.uriInfo().getBaseUri()) .name(AuthInset.AUTH_COOKIE) .value(new Encrypted(identity, this.key).cookie()) .temporary() .build(); }