Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFLY-13527 Thousand of unauthorized requests in between balancer and … #13332

Merged
merged 1 commit into from Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,7 +30,10 @@
import io.undertow.security.handlers.AuthenticationConstraintHandler;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.Cookie;
import io.undertow.server.handlers.CookieImpl;
import io.undertow.server.handlers.PathHandler;
import io.undertow.server.session.SecureRandomSessionIdGenerator;
import io.undertow.util.StatusCodes;
import org.jboss.as.domain.management.SecurityRealm;
import org.jboss.as.web.session.SimpleRoutingSupport;
import org.jboss.as.web.session.SimpleSessionIdentifierCodec;
Expand Down Expand Up @@ -84,11 +87,17 @@ public void stop(StopContext stopContext) {

private HttpHandler setupRoutes(HttpHandler handler) {
final SimpleSessionIdentifierCodec codec = new SimpleSessionIdentifierCodec(new SimpleRoutingSupport(), this.host.getValue().getServer().getRoute());
final SecureRandomSessionIdGenerator generator = new SecureRandomSessionIdGenerator();
return exchange -> {
exchange.addResponseCommitListener(ex -> {
Cookie cookie = ex.getResponseCookies().get(JSESSIONID);
if(cookie != null ) {
if (cookie != null ) {
cookie.setValue(codec.encode(cookie.getValue()).toString());
} else if (ex.getStatusCode() == StatusCodes.UNAUTHORIZED) {
// add a session cookie in order to avoid sticky session issue after 401 Unauthorized response
cookie = new CookieImpl("JSESSIONID", codec.encode(generator.createSessionId()).toString());
cookie.setPath(ex.getResolvedPath());
exchange.getResponseCookies().put("JSESSIONID", cookie);
}
});
handler.handleRequest(exchange);
Expand Down