ผมค่อนข้างใหม่ในฤดูใบไม้ผลิและฤดูใบไม้ผลิการรักษาความปลอดภัย
ฉันพยายามเขียนโปรแกรมที่ฉันต้องการรับรองความถูกต้องของผู้ใช้ที่ส่วนท้ายของเซิร์ฟเวอร์โดยใช้ Spring security
ฉันคิดสิ่งต่อไปนี้:
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 เป็นอ็อบเจ็กต์ของคลาสบางคลาสที่ฉันสามารถเข้าถึงได้ตลอดทั้งรหัสเซิร์ฟเวอร์ของฉันในคำขอของผู้ใช้หลายคน