Java settting domain on a session cookie

If you need to override the domain on a session cookie you can add the following method to your AuthProvidersSecurityConfig class to do so. It’s not common you’d need to do this, but our domain wasn’t setting correctly in our cookie and this cleared the issue up.

public class AuthProvidersSecurityConfig extends WebSecurityConfigurerAdapter {

  @Bean
  public ServletContextInitializer servletContextInitializer() {
    return servletContext -> {
      servletContext.getSessionCookieConfig().setDomain("mrbusche.com");
    };
  }
}
Matt Busche's Picture

About Matt Busche

Software Engineer and Wheel of Fortune Expert If this article helped you, please consider buying me a book.

Des Moines, IA https://www.mrbusche.com