Spring Setting the cookie expiration should not invoke the initSessionCookie method.

Because I set the cookieInitializer callback, this callback sets maxAge to 30 days, causing the expiration time for clearing cookies to change from immediate expiration to 30 days. Currently, I have temporarily fixed this issue in my callback using the following code. However, I don't think this approach is elegant enough because it creates an additional cookie object; otherwise, I cannot read what the current maxAge is. In my opinion, if it's a case of clearing cookies, there is no need to execute the cookieInitializer callback because regardless of any settings made on the cookie, the ultimate goal is to delete that cookie.

 resolver.addCookieInitializer(cookie -> {
            ResponseCookie tempCookie = cookie.build();
            if (!tempCookie.getMaxAge().equals(Duration.ZERO)) {
                cookie.maxAge(CookieConstant.MAX_AGE);
            }
        });

Comment From: bclozel

Can we take a step back here and correctly state what the issue is?

Can you explain (or better share a minimal sample application) what you are trying to do, what have you tried, what result you are getting and what result you were expecting?

Comment From: asasas234

I have customized a WebSessionIdResolver.

@Bean
    public WebSessionIdResolver webSessionIdResolver(CookieUtils cookieUtils) {
        CookieWebSessionIdResolver resolver = new CookieWebSessionIdResolver();
        resolver.addCookieInitializer(cookie -> cookie.maxAge(CookieConstant.MAX_AGE));
        return resolver;
    }

When the expireSession method is executed, it will call the initSessionCookie method, causing the previously set CookieInitializer to be executed.

So it will result in the cookie not expiring immediately.

I expect that when executing the expireSession method, the CookieInitializer I have set should not be executed. I feel that it should not be executed in itself because its purpose is to destroy cookies.

Comment From: asasas234

@bclozel Did you understand what I said?

Comment From: snicoll

I am afraid not. Screenshots and partial code snippet doesn't make it easier unfortunately.

If you want support, please share a small sample that we can run ourselves. You can do so by attaching a zip to this issue or pushing the code to a GitHub repository.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.