jakarta-ee - 拦截器没有捕获 EJBAccessException
问题描述
我正在使用 Wildfly 12 (EE 8)。
我试图通过我的拦截器捕获 EJBAccessException 以将其重新抛出为我自己的异常类型,但无济于事。我的 Interceptor 中的代码在被抛出时根本不会被调用。它确实有效并且确实捕获了其他异常,所以我不确定出了什么问题。关于这个“内部”问题,EJB 是否以某种方式无法识别我的拦截器,或者它是否可能仅在 Wildfly 自己的 AuthorizationInterceptor 被调用后才被调用?
我的 ejb-jar.xml:
<interceptors>
<interceptor>
<interceptor-class>myExceptionInterceptor</interceptor-class>
</interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>myExceptionInterceptor</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
我的 beans.xml 是空的,我也尝试将 Interceptor 声明放在那里,但没有任何效果。
我的拦截器:
@Throws
@Interceptor
@Priority(Interceptor.Priority.APPLICATION) // Tried playing with this too
public class myExceptionInterceptor implements Serializable {
@AroundInvoke
public Object check(InvocationContext invocationContext) throws Exception {
try {
return invocationContext.proceed();
}
catch (javax.ejb.EJBAccessException e) {
//rethrow as own exception
}
我关于 EJB 安全性的standalone.xml 的一部分:
<default-security-domain value="jaspitest"/>
<default-missing-method-permissions-deny-access value="true"/>
我的拦截器绑定:
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target( {ElementType.METHOD, ElementType.TYPE} )
public @interface Throws {}
我正在调用它的示例 bean:
@Stateless
public class UserService extends Service<User> {
@RolesAllowed(Role.ADMIN)
public void delete() {}
}
解决方案
这不起作用,因为您的拦截器必须能够访问与其关联的业务方法所具有的相同javax.ejb.EJBContext对象。请参阅 EJB 规范 (3.2) §4.7.2 中的表 2。
因此,在调用拦截器之前应用安全检查。
解决这个问题的唯一方法是将您的服务包装在一个不安全的外观中,并将您的拦截器应用于该外观。
推荐阅读
- xamarin.forms - 如何在表单android中检测DispatchTouchEvent方法中的单击
- excel - 在 Excel 2019 上运行 Selenium VBA 时出现自动化错误
- python - 从 2 个列表中减去字符串列表元素
- python - 将正则表达式格式应用于与 pandas 列匹配的术语列表
- android - 当我将 isCloseIconVisible 设置为 false 时的筹码保证金问题
- php - 如果我不知道有多少个数组,如何在 GraphQL 中返回一个数组(PHP,rebing/graphql-laravel)
- angular - Angular 后端 HTTP 请求
- python - Mixture parameters from a TensorFlow Probability mixture density network
- android - 有没有办法同时反编译多个android apk?
- angular - 运行 npm install 时出现 Angular 应用程序错误 - 无法解析依赖项