gpt4 book ai didi

java - 检查当前用户是否通过 Spring Security 中的记住我过滤器登录

转载 作者:搜寻专家 更新时间:2023-11-01 02:26:21 27 4
gpt4 key购买 nike

如何以编程方式检查用户是否使用 Spring Security 中的记住我过滤器登录?

例如如何在 Spring Controller 中执行此操作

@RequestMapping({"/sell-all-assets"})
public String sellAllAssets(Model model, HttpServletRequest request) {
if (isRememberMeAuthenticated()) {
return "redirect:/login";
} else {
accountService.sellAllAssets(getCurrentUser());
return "pages/myaccount";
}
}

public static boolean isRememberMeAuthenticated() {
???
}

最佳答案

看起来 AuthenticationTrustResolverImpl 类包含回答我的问题的代码。在这里

public static boolean isRememberMeAuthenticated() {
// Check authentication exists
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return false;
}

return RememberMeAuthenticationToken.class.isAssignableFrom(authentication.getClass());
}

关于java - 检查当前用户是否通过 Spring Security 中的记住我过滤器登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22226366/

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