EJB3& JAAS 主题/主体如何从 servlet 容器传播到 EJB 层?

发布于 2024-12-01 23:35:24 字数 299 浏览 1 评论 0原文

我试图了解 JAAS 主体如何从 Web 层传播到业务/EJB 层。

我读过,如果角色/领域是在 login-config & 中配置的, web.xmlsecurity-context 那么 servlet 容器也会透明地将经过身份验证的主体传递到 EJB 层。

两个问题
1.) 首先&更重要的是这是真的吗?无需开发商的任何干预!
2.) 其次,知道它在幕后是如何工作的。

I'm trying to understand how the JAAS principal propagates to the Business/EJB tier from web tier.

I've read that the if the roles/realm is configured in login-config & security-context of web.xml then the servlet container will also transparently pass the authenticated principal to the EJB Tier.

Two questions
1.) First & more importantly is that true ? Without any intervention from the developer !
2.) And secondly any idea how that works under the hood.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

薆情海 2024-12-08 23:35:24
  1. 是的,这是真的。这通常是 ejb 的目的,将“困难”的东西从开发人员手中夺走(例如安全性、事务、健壮性、多线程等),
  2. 它依赖于实现。我知道在jboss(至少4.x及之前)中,远程方法调用使用自定义序列化协议,该协议具有可以与请求一起发送的任意信息的附加映射。这是身份验证信息以及支持集群的其他内容。对于本地方法调用,我相信他们使用 ThreadLocals 之类的东西。
  1. yes it's true. that's generally the point of ejb, to take the "hard" stuff out of the hands of the developer (e.g. security, transactions, robustness, multithreading, etc.)
  2. it's implementation dependent. i know that in jboss (at least 4.x and before), remote method calls used a custom serialization protocol which had an additional Map of arbitrary information which could be sent along with the request. in this was the auth info as well as other stuff to support clustering. for local method calls i believe they use stuff like ThreadLocals.
那些过往 2024-12-08 23:35:24

在 EJB 调用中会传播各种“上下文”信息,一旦您进入 EJB 层并开始执行 EJB-EJB 调用,事务就是一个例子。有些容器也允许您创建自己的此类上下文对象。

线程本地存储可以在进程内使用,但通常只是假设容器负责并且可以做正确的事情 - 实际技术是特定于实现的。

There are various "context" pieces of information that get propagated in EJB calls, once you get inside the EJB layer and start doing EJB-EJB calls then Transactions would be an example. Some containers allow you to create your own such context objects too.

Thread-local storage can be used within a process, but generally just assume that the container is in charge and can do the right thing - the actual technique is implementation specific.

养猫人 2024-12-08 23:35:24

关于你的第一个问题——是的。
关于你的第二个问题——你熟悉 EJB3 拦截器吗?
容器使用 bean 的“拦截代码”创建代理对象,
此外,容器还可以跟踪方法和 bean 类上的其他注释,例如,检测 @PostConstruct 注释。
使用角色定义,它可以检查配置(旧版本的 jboss 中的 login-config.xml 或 JBoss AS 7 中的独立配置中的standalone.xml)并了解每个角色的定义是什么。
JAAS 按顺序使用为您提供身份验证和授权的抽象层。
JAAS 背后的概念之一是登录模块 - 它为您提供“特定于协议”的代码来处理实际的授权和身份验证。
例如,我以这种方式使用 Krb5LoginModule 来使用 kerberos。

Regarding your first question - yes.

Regarding your second question - are you familiar for example with EJB3 interceptors?

The container create proxied objects with "interception code" for the beans,

and in addition the container can track other annotations on the methods and the bean class,
for example, to detect the @PostConstruct annotation.

Using the role definition, it can check the configuration
(either login-config.xml at older versions of jboss, or standalone.xml in JBoss AS 7 at standalone configuration) and understand what is the definition per each role.

JAAS is used in order to provide you abstraction layer over authentication and authorization.

One of the concepts behind JAAS is login module - it provides you "protocol specific" code that takes care of the actual authorization and authentication.

For example, I'm using in this way Krb5LoginModule to use kerberos.

避讳 2024-12-08 23:35:24

正如您大部分猜测的那样,从 Web 层传播到 EJB 层的 Principal 是通过 web.xml 中的 login-config 配置的。

它的实现方式取决于实现。用户/组数据也依赖于实现,并且被配置为应用服务器的一部分。

然而,实现此目的的方法之一是通过 JASPIC 提供程序的实现,这是获取Principal的标准方法。与 WEB-INF/web.xml 提供的标准表单登录、基本身份验证或证书身份验证相比,使用此方法可以让您拥有不同的身份验证路径,但工作量要多一些。

JASPIC 身份验证路径允许更复杂的场景,例如基于标头的身份验证或双因素或 OpenID。用户数据库“通常”不需要与应用程序服务器中的数据库绑定。我说“通常”是因为 WebSphere Application Server 将身份验证与服务器上配置的用户联系起来。

The Principal propagates to the EJB tier from web tier is configured through the login-config in the web.xml as you had surmised for the most part.

How it is implemented is implementation dependent. The user/group data is also implementation dependent and is configured as part of the application server.

However, one of they ways this is done is through an implementation of the JASPIC provider which is a standard way of obtaining the Principal. Using this allows you to have a different authentication path compared to the standard form login, basic authentication or certificate authentication provided by WEB-INF/web.xml but it is a little bit more work.

JASPIC authentication paths allow more complex scenarios such as header based authentication or two-factor or OpenID. The user database "usually" does not need to be tied to the one in the application server. I say "usually" because WebSphere Application Server ties the authentication to a user configured on the server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文