业务层如何避免session相关参数?
我有一个 Java EE 应用程序(简单的 Web GUI、大型 EJB 3 业务层、JPA),其大部分功能取决于当前登录的用户。
因此,EJB 中充斥着无处不在的 String userName
参数。您几乎找不到没有它的重要方法,并且它一直下降到最基本的 EJB。有时它会由其他与会话相关的参数进行补充,例如用户的区域设置。
结果,参数列表不断增长,代码清晰度也受到影响。这可能是一个常见问题,如何避免呢?将更多代码推送到 GUI 客户端似乎是更疯狂的想法。
I have a Java EE application (simple web GUI, a large EJB 3 business layer, JPA) whose most functions depend on the currently logged-on user.
Because of this, the EJBs are infested with omnipresent String userName
parameter. You can hardly find a non-trivial method that goes without it, and it descends all the way down to the most basic EJBs. Occasionally it is supplemented by other session-related parameters, like user's locale.
As a result, parameter lists grow and code clarity suffers. It's probably a common problem, how to avoid it? Pushing more code to the GUI client seems even crazier idea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Java EE 支持跨各个层的安全上下文传播。例如,检查 EJBContext 上与身份验证/授权相关的各种方法,例如 getCallerPrincipal()、isCallerInRole()。我建议您阅读以下两篇文章
Java EE has support for security context propogation across various layers. For e.g. checkout various methods on the EJBContext related to authentication/authorization such as
getCallerPrincipal()
,isCallerInRole()
. I suggest you read the below two articles