首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Spring中获取Session对象?

如何在Spring中获取Session对象?
EN

Stack Overflow用户
提问于 2009-10-27 15:26:25
回答 5查看 200.1K关注 0票数 90

我对Spring和Spring安全性比较陌生。

我试图写一个程序,我需要在服务器端使用Spring安全来验证用户,

我想出了以下几点:

代码语言:javascript
复制
public class CustomAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider{
    @Override
    protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken)
                    throws AuthenticationException
    {
        System.out.println("Method invoked : additionalAuthenticationChecks isAuthenticated ? :"+usernamePasswordAuthenticationToken.isAuthenticated());
    }

    @Override
    protected UserDetails retrieveUser(String username,UsernamePasswordAuthenticationToken authentication) throws AuthenticationException 
    {
        System.out.println("Method invoked : retrieveUser");
        //so far so good, i can authenticate user here, and throw exception if not authenticated!!
        //THIS IS WHERE I WANT TO ACCESS SESSION OBJECT
    }
}

我的用例是,当用户通过身份验证时,我需要放置一个属性,如下所示:

代码语言:javascript
复制
session.setAttribute("userObject", myUserObject);

myUserObject是某个类的对象,我可以跨多个用户请求在整个服务器代码中访问它。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1629211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档