How can I authenticate a user immediately after registration?

Hi. I started studying Spring Security and ran into a problem - when a user registers, he does not log in (that is, he has to go through authorization). I searched for information on various forums and websites - it says that you need to use UsernamePasswordAuthenticationToken, AuthenticationManager and SecurityContext. The problem is that the user becomes anonymous when going to any page, which makes it necessary to log in. Is it really necessary to use this particular option? Are there any examples of proper usage? Are there any other ways?
No description
No description
No description
7 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @JVyacheslav! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JVyacheslav
JVyacheslavOP6mo ago
No exceptions are caught
Yanis
Yanis6mo ago
Use a bean for your brcriptpasswordencoder. You're initalizing one at each request
dan1st
dan1st6mo ago
you could try setting SecurityContextHolder.getContext().setAuthentication(...) when registering - though you might need to set a session attribute with the key SPRING_SECURITY_CONTEXT and the value being the SecurityContext
JVyacheslav
JVyacheslavOP6mo ago
@dan1st | Daniel Thank you, it helped a lot! ❤️
JavaBot
JavaBot6mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot6mo ago
Post Closed
This post has been closed by <@917367712525742090>.

Did you find this page helpful?