我对 Spring 和 Spring 安全性相对较新。
我正在尝试编写一个需要使用 Spring 安全性在服务器端验证用户的程序,
我想到了以下内容:
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
}
}
我的使用情况是,当用户通过身份验证时,我需要放置一个属性,例如:session.setAttribute("userObject", myUserObject);
myUserObject是某个类的对象,我可以在整个服务器代码中通过多个用户请求进行访问。