以编程方式存储认证对象

时间:2014-07-11 06:17:32

标签: spring-security

我正在尝试创建usernamepasswordauthenticationtoken并直接添加到安全上下文中。在很多地方我都读过以下代码:

Authentication request = new UsernamePasswordAuthenticationToken( username, password );
Authentication result = authenticationManager.authenticate( request );
SecurityContextHolder.getContext().setAuthentication( result );

但对我来说,我需要添加下面提到的行以使其正常工作

HttpSession session = request.getSession(true);
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext); 

我做错了吗?因为我不想使用会话。

0 个答案:

没有答案