Getting Tomcat user in Java

前端 未结 2 1062
北恋
北恋 2021-01-05 10:08

is there a way to get the logged in user name (and group) from a Tomcat system. I read something about configuring Tomcat, so it is getting the user information out of a dat

相关标签:
2条回答
  • 2021-01-05 10:17

    You can try these two methods from the HttpServletRequest interface.

    getUserPrincipal() returns a Principal from which you can get the logged used as getUserPrincipal().getName().

    isUserInRole("Administrators") returns true if the current Principal is in the provided role.

    Of course this only works if you are using tomcat realm authentication found here.

    0 讨论(0)
  • 2021-01-05 10:18

    getUserPrincipal().getName()

    There's a typo in above answer.

    0 讨论(0)
提交回复
热议问题