Accessing my custom user object in jsp page, using spring 3 security

前端 未结 3 1309
情话喂你
情话喂你 2021-01-19 01:40

I have implemented UserDetailsService, it returns an instance of MyUser (which implements UserDetails)

public MyUser l         


        
3条回答
  •  天命终不由人
    2021-01-19 02:15

    After analyzing the HTTPSesson, immediately after the successful log in, I found out that there is an attribute named SPRING_SECURITY_CONTEXT. For example, mine custom UserDetails has object named user, which has property firstName. In JSP, value of this property can be reached with the following:

    ${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.user.firstName}
    

提交回复
热议问题