【发布时间】:2015-08-17 15:52:55
【问题描述】:
SecurityContextHolder.getContext().getAuthentication()
is returning Null
I enter an URL into the browser **http::/myntrac.com/udp**, it calls
index.jsp and forward the page to Spring Controller
索引.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<script type="text/javascript" >
</script>
</head>
<body>
<jsp:forward page="/udp/auth" />
</body>
</html>
Spring Controller
--------------------------
It is redirecting to the page on the basis whether user has
authenticated or not
@RequestMapping(value = "/auth")
public String authentication()
throws IOException {
Authentication auth =
SecurityContextHolder.getContext().getAuthentication();
if(auth == null || !auth.isAuthenticated()) {
return "redirect:/udp/redirectLogin";
} else {
return "redirect:/udp/home";
}
}
如果用户未通过身份验证,则会重定向到登录页面。认证后(google api 认证),到达登陆页面。在这里我检查了 SecurityContextHolder.getContext().getAuthentication() 不是 Null。
我再次输入网址 http::/myntrac.com/udp 。由于用户已经通过身份验证,它应该被重定向到主页而不是登录页面,但它再次进入登录页面但用户会话已经存在。因为 SecurityContextHolder.getContext().getAuthentication() 这里是 Null。
【问题讨论】:
标签: spring authentication spring-security