How to change Grails Spring Security Cookie Path

白昼怎懂夜的黑 提交于 2019-12-06 07:41:34

When the remember-me filter creates the remember-me cookie, it sets the cookie path to the context path obtained from the request object (see related source code here). If you want to customize this behavior, you'll need to override the setCookie() and cancelCookie() methods of the remember-me service implementation your application uses (either TokenBasedRememberMeServices or PersistentTokenBasedRememberMeServices) in a subclass, and configure the RememberMeAuthenticationFilter to use your custom implementation.

Here's how I impltemented it. create a new service with extends TokenBasedRememberMeServices override setCookie and cancelCookie method to set cookie path. Add cookiePath variable and add method to setCookepath()

Update resources.groovy

rememberMeServices(YourTokenBasedRememberMeServices) { 
    userDetailsService = ref("userDetailsService")
    key = conf.rememberMe.key
    cookieName = conf.rememberMe.cookieName
    alwaysRemember = conf.rememberMe.alwaysRemember
    tokenValiditySeconds = conf.rememberMe.tokenValiditySeconds
    cookiePath = some config variable 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!