spring security. display user name on every page

前端 未结 3 1482
执笔经年
执笔经年 2021-02-04 21:18

I want to store user information after logging in and to display my login and username on every page (using jsp). How can I get access in my jsp views to the session bean that w

3条回答
  •  日久生厌
    2021-02-04 21:52

    This is a near duplicate to When using Spring Security, what is the proper way to obtain current username (i.e. SecurityContext) information in a bean?. The Spring endorsed method is

    final String currentUser = SecurityContextHolder.getContext().getAuthentication().getName();
    

    but the linked discussion has alternatives.

提交回复
热议问题