Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent lazy initialize exception in spring security authentication object #669

Merged

Conversation

donggyu04
Copy link
Contributor

@donggyu04 donggyu04 commented Oct 8, 2020

Currently, we are using the SecuredUser object as a spring security's authentication principal.
It is used in some of our codes.

case of below, It emits lazy initialize exception(no session).
because the User object stored in SecuredUser at login time is not properly initialized the fields that require lazy fetch.

so, I changed a SecuredUser to have eager fetched user object at login time.

SecuredUser secureUser = cast(authentication.getPrincipal());
User user = secureUser.getUser();

...

// Emit lazy initialize exception (no session)
List<User> owners = user.getOwners();

Code snippet link

@donggyu04 donggyu04 self-assigned this Oct 8, 2020
@donggyu04 donggyu04 force-pushed the bugfix/prevent-lazy-initialize-exception-at-secured-user branch 2 times, most recently from 6f33d82 to afa1e76 Compare October 8, 2020 10:14
imbyungjun
imbyungjun previously approved these changes Oct 8, 2020
@donggyu04 donggyu04 force-pushed the bugfix/prevent-lazy-initialize-exception-at-secured-user branch from afa1e76 to 4b605a1 Compare October 8, 2020 10:20
songeunwoo
songeunwoo previously approved these changes Oct 15, 2020
@donggyu04 donggyu04 force-pushed the bugfix/prevent-lazy-initialize-exception-at-secured-user branch from 4b605a1 to 5ef4511 Compare October 22, 2020 10:15
@imbyungjun imbyungjun merged commit aba46f5 into develop Oct 27, 2020
@donggyu04 donggyu04 deleted the bugfix/prevent-lazy-initialize-exception-at-secured-user branch October 29, 2020 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants