From e5999135716a896830930d2be8a7548348652b47 Mon Sep 17 00:00:00 2001 From: Miroslav Blasko Date: Mon, 25 Nov 2024 14:42:58 +0100 Subject: [PATCH] [kbss-cvut/record-manager-ui#202] Add method to get current user without security context --- .../cz/cvut/kbss/study/service/UserService.java | 13 +++++++++++++ .../service/repository/RepositoryUserService.java | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/cz/cvut/kbss/study/service/UserService.java b/src/main/java/cz/cvut/kbss/study/service/UserService.java index af744aad..270bdcbe 100644 --- a/src/main/java/cz/cvut/kbss/study/service/UserService.java +++ b/src/main/java/cz/cvut/kbss/study/service/UserService.java @@ -9,8 +9,21 @@ public interface UserService extends BaseService { User findByUsername(String username); + /** + * Retrieve currently authenticated user. The returned User entity is populated + * with information from the security context. + * @return User currently authenticated user or null. + */ User getCurrentUser(); + /** + * Retrieve persisted user from the current authenticated user. The returned User + * entity is not populated with information from the security context. See + * {@link #getCurrentUser()} to retrieve security context as well. + * @return User currently authenticated user or null. + */ + User findCurrentUser(); + User findByEmail(String email); User findByToken(String token); diff --git a/src/main/java/cz/cvut/kbss/study/service/repository/RepositoryUserService.java b/src/main/java/cz/cvut/kbss/study/service/repository/RepositoryUserService.java index be04c2b2..f003bcd0 100644 --- a/src/main/java/cz/cvut/kbss/study/service/repository/RepositoryUserService.java +++ b/src/main/java/cz/cvut/kbss/study/service/repository/RepositoryUserService.java @@ -76,6 +76,12 @@ public User getCurrentUser() { return securityUtils.getCurrentUser(); } + @Transactional(readOnly = true) + @Override + public User findCurrentUser() { + return userDao.findByUsername(securityUtils.getCurrentUser().getUsername()); + } + @Transactional(readOnly = true) @Override public List findByInstitution(Institution institution) {