Skip to content

Commit

Permalink
[kbss-cvut/record-manager-ui#202] Add method to get current user with…
Browse files Browse the repository at this point in the history
…out security context
  • Loading branch information
blcham committed Nov 25, 2024
1 parent d23dead commit e599913
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/cz/cvut/kbss/study/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ public interface UserService extends BaseService<User> {

User findByUsername(String username);

/**
* Retrieve currently authenticated user. The returned <code>User</code> 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 <code>User</code>
* 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<User> findByInstitution(Institution institution) {
Expand Down

0 comments on commit e599913

Please sign in to comment.