Getting Tomcat user in Java

前端 未结 2 1057
北恋
北恋 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.

提交回复
热议问题