websphere 运行 作为 servlet 的用户

websphere run as user for servlet

我是 websphere 安全方面的新手。在我的应用程序中,我有一个 ejb,它作为用户具有 运行 的安全设置。当我对 ejb 执行 ping 命令时,它使用 运行as 配置中指定的用户执行方法。 是否可以对 servlet 做同样的事情?我的意思是当用户从 ui 发送请求并且 websphere 以用户身份从 运行 作为配置执行 dopost/doget 时?

如果您使用的是 Servlet 3.1 (Java EE 7),那么您可以在 servlet class.

上使用 @RunAs 注释

例如,这组 Servlet 注释将允许 Manager 和 Employee 角色访问 servlet,运行 作为 Employee 角色:

@RunAs("Employee")
@WebServlet("/myServlet")
@ServletSecurity(
  httpMethodConstraints = {
    @HttpMethodConstraint(value = "GET", rolesAllowed = "Manager"),
    @HttpMethodConstraint(value = "GET", rolesAllowed = "Employee") 
  }
)
public class MyServlet extends HttpServlet {
  // ...
}

有关 RunAs 配置的完整 Liberty 文档,请参阅此处:Configuring RunAs authentication in Liberty