gpt4 book ai didi

java - Cookie 在本地被删除,但在部署时不会被删除

转载 作者:行者123 更新时间:2023-12-01 18:18:11 24 4
gpt4 key购买 nike

我正在尝试使我的代码创建的 cookie 无效。我想创建一个新的注销端点。我必须根据端点是否返回数据在两条路径之间进行选择以进行重定向。当我在本地运行代码时,它就像一个魅力。删除 cookie 并重定向到正确的 url,但是,如果我测试它部署在远程服务器上,它不起作用,这意味着它会正确重定向,但不会使 cookie 过期,也不会修改其值。我的整个代码必须是后端代码,因此我无法重定向到会删除 cookie 并再次重定向的 JavaScript。

@RequestMapping(value = "/logout", method = RequestMethod.GET)
public void cookieKiller(
@CookieValue(name = "theCookie", required = false) Cookie myCookie,
HttpServletResponse response, HttpServletRequest request) {


if (myCookie != null) {
} else { // Just being cautious, if the cookie is not retrieved, would be overwritten anyway just in case
myCookie = new Cookie("theCookie","");
}
myCookie.setMaxAge(0);
myCookie.setValue("");
myCookie.setPath("/");
response.addCookie(myCookie);

boolean endpointHealthy = true;

if(haveITheEndpointUrls()) {
endpointHealthy = false;
} else {
try {
String eaiResponseJson = restTemplateAutowired.getForEntity(new URI(oneUrl),String.class).getBody();

if (eaiResponseJson != null && !eaiResponseJson.isBlank()) {
response.sendRedirect(eaiSamlUrl);
} else {
endpointHealthy = false;
}

} catch (IOException e) {
endpointHealthy = false;
} catch (ResourceAccessException e) {
endpointHealthy = false;
} catch (HttpClientErrorException e) {
endpointHealthy = false;
} catch (Exception e) {
endpointHealthy = false;
}
}

if (!endpointHealthy) {
try {
response.sendRedirect(request.getContextPath() + "/internal/Path");
} catch (IOException ex) {
// ...
}
}

}

如果我添加一个新的 cookie,生成的域与应用程序前面部分介绍的原始域不同。作为后面的“domain.com”和前面的“.domain.com”,所以我猜这是一个域的事情

我一直在尝试更改路径、更改值等,但它也不起作用,我在 stackoverflow 上冲浪了很多次来寻找答案,但没有任何结果。有关域的一些建议或线索,或者我可能遗漏的任何提示?

最佳答案

我在本地的代码生成了一个像domain.com这样的cookie,但是SHibboleth需要以点开头的cookie域。我尝试以这种方式创建 cookie,但在 Tomcat 中这是不可能的,除非您使用 LegacyCookieManager。

关于java - Cookie 在本地被删除,但在部署时不会被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60325355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com