使用 Tomcat 领域时获取用户详细信息 [英] Getting user details when using Tomcat realm

查看:45
本文介绍了使用 Tomcat 领域时获取用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Tomcat 域来保证安全,我的问题是我不知道登录后从哪里获取用户信息.

I am using Tomcat realm for security and my question is that I didn't know where to get the user's information after logging in.

想使用已登录用户的角色,登录后不知道Tomcat在其会话中设置了什么.

I want to use the role of the user that has logged on and I don't know what Tomcat sets in it's session after logging on.

推荐答案

Tomcat 遵循 servlet 规范,并通过两种方式使用户的信息可用于您的 web 应用程序:

Tomcat follows the servlet specification and makes the user's information available to your webapp in two ways:

  1. 使用 request.getUserPrincipal 获取代表用户的 java.security.Principal.您可以调用 Principal.getName 来获取用户名.
  2. 使用 request.isUserInRole 检查用户是否具有特定角色.

请注意,您不能只获得用户的角色",因为用户可能有多个角色.标准 API 不包括获取所有用户角色的方法:您必须单独检查它们.

Note that you can't just get "the user's role" because the user may have multiple roles. The standard API does not include a way to get all the user's roles: you have to check for them individually.

这篇关于使用 Tomcat 领域时获取用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆