当前位置: 首页 > 知识库问答 >
问题:

在wildfly中注入EJB时出现安全异常

岑炯
2023-03-14

我尝试从JBoss AS 7迁移到Wildfly 8.2。从Java 1.6到Java 1.7。在将ejb bean注入批处理作业时,我会遇到一些安全异常。

这是我的调度程序:(每分钟运行一次)

@Startup
@Singleton
public class MyBatchScheduler {

    @Inject
    MyBatch myBatch;

    @Schedule(second = "30", minute = "*/1", hour = "*", persistent = false)
    public void runBackgroundTasks() {
        myBatch.runBackgroundTasksAsync();
    }
}

这是我的批处理:(调度程序每分钟调用一次)

 @Stateless
 public class MyBatch {

    @Inject
    MyTestbean myTestbean;

    @Asynchronous
    public void runBackgroundTasksAsync() {
        myTestbean.doSomething();
        System.out.println("Batch");
    }
 }

这是我的无状态bean,它产生了问题:(只是一个空方法)

public class MyTestbean implements Serializable {

    private static final long serialVersionUID = 1L;

    public void doSomething() {

    }
}

我的jboss-ejb3。具有安全域的xml:

<?xml version="1.1" encoding="UTF-8"?>
<jboss:ejb-jar
    xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:s="urn:security"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd"
    version="3.2">
    <assembly-descriptor>
        <s:security>
            <ejb-name>*</ejb-name>
            <s:security-domain>myXXXRealm</s:security-domain>
        </s:security>
    </assembly-descriptor>
</jboss:ejb-jar>

我的jboss网站。xml与我的安全域:

<?xml version="1.1" encoding="UTF-8"?>
<jboss-web>
    <security-domain>myXXXRealm</security-domain>
    <context-root>/</context-root>
</jboss-web>

在我的standalone.xml我还将myXXXRealm定义为安全域:

<subsystem xmlns="urn:jboss:domain:security:1.2">
   <security-domains>
       <security-domain name="other" cache-type="default">
           <authentication>
               <login-module code="Remoting" flag="optional">
                   <module-option name="password-stacking" value="useFirstPass"/>
               </login-module>
               <login-module code="RealmUsersRoles" flag="required">
                   <module-option name="usersProperties" value="${jboss.server.config.dir}/application-users.properties"/>
                   <module-option name="rolesProperties" value="${jboss.server.config.dir}/application-roles.properties"/>
                   <module-option name="realm" value="ApplicationRealm"/>
                   <module-option name="password-stacking" value="useFirstPass"/>
               </login-module>
           </authentication>
       </security-domain>
       <security-domain name="jboss-web-policy" cache-type="default">
           <authorization>
               <policy-module code="Delegating" flag="required"/>
           </authorization>
       </security-domain>
       <security-domain name="jboss-ejb-policy" cache-type="default">
           <authorization>
               <policy-module code="Delegating" flag="required"/>
           </authorization>
       </security-domain>
       <security-domain name="myXXXRealm">
           <authentication>
               <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
                   <module-option name="dsJndiName" value="java:/db/auraDS"/>
                   <module-option name="principalsQuery" value="select &quot;PASSWORD&quot; from aura.&quot;USER&quot; where &quot;USERNAME&quot;=?"/>
                   <module-option name="rolesQuery" value="SELECT r.&quot;NAME&quot;, 'Roles' FROM aura.&quot;ROLE&quot; r, aura.&quot;USER_ROLE&quot; ur, aura.&quot;USER&quot; u WHERE u.&quot;USERNAME&quot;=? AND u.&quot;ID&quot;=ur.&quot;USER_ID&quot; AND ur.&quot;ROLE_ID&quot;=r.&quot;ID&quot;"/>
                   <module-option name="hashAlgorithm" value="MD5"/>
                   <module-option name="hashEncoding" value="hex"/>
               </login-module>
           </authentication>
       </security-domain>
   </security-domains>
</subsystem>

但我总是得到例外“方法权限不足”和“JBAS014134: EJB调用在组件上失败”:

14:09:30,005 DEBUG [org.jboss.security] (EJB default - 8) PBOX000291: Method: runBackgroundTasksAsync, interface: Local, required roles: Roles(<NOBODY>,)
14:09:30,005 DEBUG [org.jboss.security] (EJB default - 8) PBOX000292: Insufficient method permissions [principal: null, EJB name: MyBatch, method: runBackgroundTasksAsync, interface: Local, required roles: Roles(<NOBODY>,), principal roles: Roles(), run-as roles: null]
14:09:30,005 DEBUG [org.jboss.security] (EJB default - 8) PBOX000299: Required module org.jboss.security.authorization.modules.DelegatingAuthorizationModule failed
14:09:30,005 DEBUG [org.jboss.security] (EJB default - 8) PBOX000325: Authorization processing error: org.jboss.security.authorization.AuthorizationException: PBOX000017: Acces denied: authorization failed 
    at org.jboss.security.plugins.authorization.JBossAuthorizationContext.invokeAuthorize(JBossAuthorizationContext.java:268) [picketbox-4.0.21.Final.jar:4.0.21.Final]
    at org.jboss.security.plugins.authorization.JBossAuthorizationContext.access$000(JBossAuthorizationContext.java:71) [picketbox-4.0.21.Final.jar:4.0.21.Final]
    at org.jboss.security.plugins.authorization.JBossAuthorizationContext$1.run(JBossAuthorizationContext.java:147) [picketbox-4.0.21.Final.jar:4.0.21.Final]
    at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_65]
    at org.jboss.security.plugins.authorization.JBossAuthorizationContext.authorize(JBossAuthorizationContext.java:143) [picketbox-4.0.21.Final.jar:4.0.21.Final]
    at org.jboss.security.plugins.JBossAuthorizationManager.internalAuthorization(JBossAuthorizationManager.java:429) [picketbox-4.0.21.Final.jar:4.0.21.Final]
    at org.jboss.security.plugins.JBossAuthorizationManager.authorize(JBossAuthorizationManager.java:115) [picketbox-4.0.21.Final.jar:4.0.21.Final]
    at org.jboss.security.plugins.javaee.EJBAuthorizationHelper.authorize(EJBAuthorizationHelper.java:318) [picketbox-4.0.21.Final.jar:4.0.21.Final]
    at org.jboss.as.security.service.SimpleSecurityManager.authorize(SimpleSecurityManager.java:303) [wildfly-security-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.security.AuthorizationInterceptor.processInvocation(AuthorizationInterceptor.java:133) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:439)
    at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
    at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185)
    at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.LogDiagnosticContextRecoveryInterceptor.processInvocation(LogDiagnosticContextRecoveryInterceptor.java:79) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.AsyncFutureInterceptorFactory$1$2.runInvocation(AsyncFutureInterceptorFactory.java:97) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.component.interceptors.AsyncInvocationTask.run(AsyncInvocationTask.java:73) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_65]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_65]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122)

14:09:30,008 TRACE [org.jboss.security.audit] (EJB default - 8) [Failure]Source=org.jboss.security.plugins.javaee.EJBAuthorizationHelper;Action=authorization;Resource:=[org.jboss.security.authorization.resources.EJBResource:contextMap={policyRegistration=null}:method=public void hugo.MyBatch.runBackgroundTasksAsync():ejbMethodInterface=Local:ejbName=MyBatch:ejbPrincipal=null:MethodRoles=Roles(<NOBODY>,):securityRoleReferences=null:callerSubject=Subject:
    Principal: anonymous
:callerRunAs=null:callerRunAs=null:ejbRestrictionEnforcement=false:ejbVersion=2.0];Exception:=PBOX000017: Acces denied: authorization failed ;policyRegistration=null;
14:09:30,008 TRACE [org.jboss.security] (EJB default - 8) PBOX000354: Setting security roles ThreadLocal: null
14:09:30,008 ERROR [org.jboss.as.ejb3.invocation] (EJB default - 8) JBAS014134: EJB Invocation failed on component MyBatch for method public void hugo.MyBatch.runBackgroundTasksAsync(): javax.ejb.EJBAccessException: JBAS014502: Invocation on method: public void hugo.MyBatch.runBackgroundTasksAsync() of bean: MyBatch is not allowed
    at org.jboss.as.ejb3.security.AuthorizationInterceptor.processInvocation(AuthorizationInterceptor.java:135) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:439)
    at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
    at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185)
    at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.LogDiagnosticContextRecoveryInterceptor.processInvocation(LogDiagnosticContextRecoveryInterceptor.java:79) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.AsyncFutureInterceptorFactory$1$2.runInvocation(AsyncFutureInterceptorFactory.java:97) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.component.interceptors.AsyncInvocationTask.run(AsyncInvocationTask.java:73) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_65]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_65]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122)

我到底做错了什么?

共有1个答案

吴单鹗
2023-03-14

在JBoss 7.2中,调用EJB方法的行为变得更加受限。因此,如果有一个安全域,那么对EJB的所有调用都将在没有明确许可的情况下被拒绝,而不受安全限制(PermitAll、RolesAllowed或类似的注释/描述符条目)。

要更改此行为,可以添加jboss-ejb3。xml描述符以下选项:

<jboss:jboss
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
        xmlns:s="urn:security:1.1"
        version="3.1" impl-version="2.0">

    <assembly-descriptor>
        <s:security>
            <ejb-name>*</ejb-name>
            <s:missing-method-permissions-deny-access>false</s:missing-method-permissions-deny-access>
        </s:security>
    </assembly-descriptor>
</jboss:jboss>
  • jboss-ejb3。xml引用
 类似资料:
  • 我试图调用一个安全的远程ejb,但我不能。我使用ejb-client-API。 应用程序部署在名为som的ear中。耳朵 我用的是Wildfly 8.2.0决赛 代码客户端: JBossEJB客户端。财产 EJB 独立的。xml 服务器日志 客户端日志 我可以看到,之所以使用安全域“som_security_domain”的配置,是因为它运行查询以获取密码和主体的角色,但在尝试执行安全域的Auth

  • 问题内容: 使用新的EJB 3.1规范,是否可以将EJB注入pojo?我知道在EJB 3.0中,@ EJB批注可用于注入EJB,但这不适用于简单的pojos。 如果不是,我必须在JNDI中查找bean,因为我知道您不能简单地使用new关键字。 问题答案: 是的,使用JNDI查找。 由于您的POJO是由您创建的(我假设),因此容器不负责注入依赖项。

  • 当我从EJB调用一个方法时,我遇到了一个奇怪的异常。EJB的方法只是参考BD并返回一个VO。当我从一个独立的客户机调用该方法时,所有这些都能很好地工作,但是当我从同一台服务器、从另一个EJB调用该方法时,它返回:org。天啊。科尔巴。未知:重新引发挂起的异常时发现意外异常:(.VOObject)vmcid:IBM次要代码:EA5已完成:可能 服务器是WebSphereApplicationServ

  • 问题内容: 每当我想测试使用资源注入的类时,我最终都会包含一个仅在测试中使用的构造函数: 还有另一种模拟资源注入的方式,或者这是遵循的正确模式吗? 问题答案: 您可以使用简单的光泽效果,它可以模拟EJB注入系统。 另一种方法是在测试中使用反射来设置字段,我有时使用类似这样的内容:

  • 我正在遵循快速入门指南,但我得到了一个错误 除非说明书遗漏了什么,否则我想我已经把每件事都做得不折不扣了 com.parse.parserequest$ParserequestException:com.parse.parserequest.newTemporaryException(parserequest.java:368)在com.parse.parserequest$2处发生I/O失败。然

  • WildFly中安全域和安全域的主要区别是什么? 独立的。xml 和