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

Fix fetching user reference for change metadata #154

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SecurityUtils(UserDao userDao, SecurityConf config) {
* If the user is impersonating another user, the impersonated user is returned.
* Otherwise, the currently authenticated user is returned.
*
* @return
* @return the instance of the User class representing the currently authenticated user
*/
public User getCurrentUser() {
final SecurityContext context = SecurityContextHolder.getContext();
Expand All @@ -53,9 +53,21 @@ public User getCurrentUser() {
}
}

public String getCurrentUsername(){
final SecurityContext context = SecurityContextHolder.getContext();
assert context != null;
final Object principal = context.getAuthentication().getPrincipal();
if (principal instanceof Jwt) {
final OidcUserInfo userInfo = new OidcUserInfo(((Jwt)principal).getClaims());
return userInfo.getPreferredUsername();
} else {
return context.getAuthentication().getName();
}
}

public UserReference getCurrentUserReference() {
User user = getCurrentUser();
return new UserReference(user);
String username = getCurrentUsername();
return userDao.findUserReferenceByUsername(username);
}

// TODO map role, but I am not sure which changes in the model when be required if I add addRole method to User
Expand Down
Loading