Java EE/JBoss AS 6 中的预身份验证用户
我正在将一些 Java EE 模块从 Spring 迁移到 EJB,现在面临的问题是在调用服务方法之前需要某种预身份验证。
问题其实很简单。调用来自内部协议处理程序(某些线程启动专有协议处理程序并使用自定义 TCP 协议接收请求)。该连接尚未对用户进行身份验证,并且接下来想要调用服务方法。该服务方法需要主体信息(用户名)进行处理。
因此,在 Spring 中,我们只是将 SecurityContext 推送到本地线程,并在调用完成后将其删除。
协议处理程序 ->设置SecContext->致电->删除 SexContext ->结束
Java EE/JBoss 中有类似的东西吗?我知道有“@RunAs”构造,但我不知道它们是否可以以编程方式使用。或者有没有办法使用 JAAS LoginContext 类“登录”?那么我该如何配置 JAAS 呢?
I am migrating some Java EE modules from Spring to EJB and are now facing the problem that I need some sort of pre-authentication prior to calling a service method.
The problem is actually quite easy. A call comes in from an internal protocol handler (some thread started the proprietary protocol handler and received requests using a custom TCP protocol). Not this connection already authenticated the user and wants to call a service method next. This service method requires a principal information (user name) for processing.
So in Spring we simply pushed the SecurityContext to the local thread and removed it when the call was done.
Protocol Handler -> Set SecContext -> Call -> Remove SexContext -> End
Is there anything similar to that in Java EE/JBoss? I know there are "@RunAs" constructs but I don't know if they can be used programmatically. Or is there a way to "log in" using the JAAS LoginContext class? But how do I configure JAAS then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这纯粹是在 JAAS 上下文中获取身份的问题,那么您应该能够执行以下操作:
请注意,您可以通过将 PrivilegedAction 绑定到 Void 以外的类型来从 PrivilegedAction 返回一个值,并通过以下方式抛出异常:相反,实施 PrivilegedExceptionAction。
显然,如果您对主体是什么有更复杂的了解,您可以使用它(实现 toString、hashCode 和 equals 将是一个好主意)。
If this is purely a matter of getting an identity into the JAAS context, you should be able to do something like this:
Note that you can return a value from the PrivilegedAction by binding it to a type other than Void, and throw an exception by implementing PrivilegedExceptionAction instead.
Obviously if you have a more sophisticated idea of what a principal is, you could use that (implementing toString, hashCode, and equals would be a good idea).