如何拆分SFSB Facade?
我在开发基于 EJB 3 技术的应用程序时遇到一些问题。
我想在会话 bean 中使用外观模式来将我的客户端(一个 Web 应用程序)与我的实体 Bean 分离。
我正在使用 SFSB 来管理用户会话。
所以我有一个 FacadeLoginRemote
远程接口,它向客户端公开方法 doLogin()
、doLogout()
等... 目前该SFSB还包括一些其他方法,例如getCourse(int id)
、getResource(int id)
。并非所有用户都能真正获取课程并获取资源,因此外观在将值返回给客户端之前会执行一些检查。
我想拆分 Facade,将方法 getCourse()
和 getResource()
放在一个特殊的类中,但留给 FacadeLoginRemote
> 查看用户权限的功能。
如果我制作一些不同的 SLSB,我会将它们暴露给客户。因此,客户端可以直接连接到它们,从而避免来自 FacadeLoginRemote 的检查。
我错了吗?有什么办法可以做到这一点吗?
预先感谢,
安德里亚
I am having some problems devoloping an application based on EJB 3 technology.
I would like to use a Facade Pattern in the Session beans to decouple my client (a web application) from my Entity Beans.
I am using a SFSB to manage the user session.
So I have a FacadeLoginRemote
remote interface, which exposes to the client the methods doLogin()
, doLogout()
, etc...
Currently this SFSB also includes some other methods such as getCourse(int id)
, getResource(int id)
. Not all the users can actually get the course and get the resource, so the Facade perform some checks before returning the values to the client.
I would like to split the Facade, putting the methods getCourse()
and getResource()
in a special class for them, but leaving to the FacadeLoginRemote
the functions of checking users privileges.
If I make some different SLSBs I will expose them to the client. So the client would have the possibility to connect directly to them avoiding checks from the FacadeLoginRemote
.
Am I wrong? Is there any way to do this?
Thanks in advance,
Andrea
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个建议;如果您正在构建 Web 应用程序,那么更典型的做法是将 Web 层和业务层放在同一个应用程序中。在这种情况下不需要远程处理。您的会话 Bean 将在与 Web 层相同的 JVM 中运行。
这并不是说没有任何合理的理由使用远程接口(有很多),但是阅读你的问题描述,在我看来,使用本地 bean 可能会更好。
或者您所说的 Web 应用程序是由其他人在其服务器上托管的远程应用程序,并且它们是否使用来自您的 EJB bean 的服务?
在Java EE中,身份验证可以在Web模块中完成。特别是如果您使用本地 bean,此身份验证(安全主体)将自动传播到 EJB bean。您可以注释 EJB bean 以要求特定的安全角色。如果用户未经过身份验证,则她不具有该角色,并且服务将被拒绝。
在这种情况下,客户端是否尝试直接连接到具有 getCourse() 等方法的 bean 并不重要。
我确实想知道您是如何在 EJB 中实现
doLogin()
的。我的猜测是您在那里做了一些定制的事情,不幸的是,据我所知,EJB3 没有一种直接的方法来通过特定 bean 上的特定方法进行编程登录。安全性主要是声明性的,并且在访问任何 bean 时客户端必须提供身份验证详细信息。例如,当您从远程 JNDI 请求 Bean 时,您必须提供这些详细信息以及到远程服务器的初始 JNDI 连接。First one word of advice; if you are building a web application, then it's more typical to have the web tier and the business tier within the same application. There is no need for remoting in that case. Your session beans will run in the same JVM as the web tier.
That's not to say there aren't any legitimate reasons to use remote interfaces (there are plenty), but reading your problem description it seems to me that you might be better off using local beans.
Or is the web application you speak of a remote application hosted by someone else on their servers, and do they consume services from your EJB beans?
In Java EE, the authentication can be done in the web module. Especially if you are using local beans, this authentication (the security principal) will be propagated automatically to the EJB beans. You can annotate your EJB beans to require a specific security role. If the user isn't authenticated, she doesn't has that role and service will be rejected.
In that case it doesn't matter if the client tries to connect directly to the beans having the
getCourse()
etc methods.I do wonder how you implemented the
doLogin()
in your EJB. My guess is that you did something custom there, as unfortunately to the best of my knowledge EJB3 does not have a straightforward way to do a programmatic login via a specific method on a specific bean. Security is mostly declarative, and authentication details will then have to be provided by the client when accessing any bean. E.g. when you request beans from a remote JNDI, you have to provide those details with the initial JNDI connection to the remote server.