getting the current logged in user in JHipster

后端 未结 3 1000
情话喂你
情话喂你 2020-12-07 00:16

I am building a jhipster application. and I am trying to get a list of objects based on the current logged in user. there are a few simple examples online such as jhipster b

3条回答
  •  情深已故
    2020-12-07 00:48

    Currently the best answer is to use built-in UserService - the one provided by JHipster. You don't have to repeat calling SecurityUtils.getCurrentUserLogin() twice (once yourself and once in UserService - check implementation). Usage would look like this:

    final Optional isUser = userService.getUserWithAuthorities();
    if(!isUser.isPresent()) {
       log.error("User is not logged in");
       return new Shinything()
    }
    
    final User user = isUser.get();
    // continue with the user
    

提交回复
热议问题