I got this work, but needed to write my own RememberMe Service. I extended PersistentTokenBasedRememberMeServices and overrided the setCookie method to set the path as /
Code:
package com.company.spring.security.custom.rememberme;
import java.lang.reflect.Method;
import javax.servlet.http.Cookie;
import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
import org.springframework.util.ReflectionUtils;
public class CustomDomainCookieRememberMe extends PersistentTokenBasedRememberMeServices {
//This allows us to name or own cookie and "hide" the face we are using spring security
private Boolean useSecureCookie = null;
private Method setHttpOnlyMethod;
private String cookiePathForSecurity = "/"; //This is what allows "Single Sign On". The path of the cookie is set to the
//top domain (website.org) or just /. If the app is in the path
//the cookie is only available to that app
@Override
protected void setCookie(java.lang.String[] tokens,
int maxAge,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
{
/*
System.out.println("Dumping Cookies");
for (int i = 0; i < tokens.length; i++) {
String theCookie = tokens[i];
System.out.println("string: " + theCookie);
}
*/
String cookieValue = encodeCookie(tokens);
Cookie cookie = new Cookie(getCookieName(), cookieValue);
cookie.setMaxAge(maxAge); //I think we can overwrite this with our own
cookie.setPath(cookiePathForSecurity);
if (useSecureCookie == null) {
cookie.setSecure(request.isSecure());
} else {
cookie.setSecure(useSecureCookie);
}
if(setHttpOnlyMethod != null) {
ReflectionUtils.invokeMethod(setHttpOnlyMethod, cookie, Boolean.TRUE);
}
response.addCookie(cookie);
}
}