Skip to content

Commit

Permalink
better workaround for cookie max-age
Browse files Browse the repository at this point in the history
  • Loading branch information
Athou committed Aug 19, 2024
1 parent 181dd24 commit ece5572
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 90 deletions.
4 changes: 4 additions & 0 deletions commafeed-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-routes</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-security</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.commafeed.security;

import io.quarkus.vertx.http.runtime.HttpConfiguration;
import io.quarkus.vertx.http.runtime.security.FormAuthenticationMechanism;
import io.quarkus.vertx.web.RouteFilter;
import io.vertx.core.http.Cookie;
import io.vertx.core.http.impl.ServerCookie;
import io.vertx.ext.web.RoutingContext;
import jakarta.inject.Singleton;
import lombok.RequiredArgsConstructor;

/**
* Intercepts responses and sets a Max-Age on the cookie created by {@link FormAuthenticationMechanism} because it has no value by default.
*
* This is a workaround for https://github.com/quarkusio/quarkus/issues/42463
*/
@RequiredArgsConstructor
@Singleton
public class FormAuthenticationCookieInterceptor {

private final HttpConfiguration config;

@RouteFilter(Integer.MAX_VALUE)
public void cookieInterceptor(RoutingContext context) {
context.addHeadersEndHandler(v -> {
Cookie cookie = context.request().getCookie(config.auth.form.cookieName);
if (cookie instanceof ServerCookie sc && sc.isChanged()) {
cookie.setMaxAge(config.auth.form.timeout.toSeconds());
}
});

context.next();
}
}

This file was deleted.

0 comments on commit ece5572

Please sign in to comment.