2015-01-21 125 views
0

在QuartzMDB中使用quartz-ra.rar將應用程序遷移到Jboss AS 6.1中的EJB定時器後,我遇到了上述異常。 (作爲將應用程序升級到wildfly 8.1的一部分)javax.ejb.EJBAccessException:調用者未經授權

在使用以下ejb的作業中發生異常。

@Stateless 
@TransactionAttribute(TransactionAttributeType.REQUIRED) 
@RolesAllowed({"admin"}) 
public class PlatformPluginBean implements PlatformPluginRemote { 

    // some code here 

    public Collection<PlatformPlugin> getPlugins() { 
     return new ArrayList<PlatformPlugin>(schemaToPlugin.values()); 
    } 

} 

以下是遷移前的工作,工作正常。

@MessageDriven(activationConfig = { 
    @ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0 0 * * * ?"), 
    @ActivationConfigProperty(propertyName = "jobName", propertyValue = "PruneJob")}) 
@ResourceAdapter("quartz-ra.rar") 
@RunAs("admin") 
public class PruneJob implements Job { 

    @EJB 
    private PlatformPluginRemote platformPluginRemote; 

    @Override 
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { 

     for (PlatformPlugin platformPlugin: platformPluginRemote.getPlugins()) { 
      // some stuff here 
     } 
    } 
} 

以下是更改爲ejb自動定時器後的工作。

@Stateless 
@RunAs("admin") 
public class PruneJob { 

    @EJB 
    private PlatformPluginRemote platformPluginRemote; 

    @Schedule(hour="*", minute="0", persistent=false) 
    public void execute() { 

     for (PlatformPlugin platformPlugin: platformPluginRemote.getPlugins()) { 
      // some stuff here 
     } 
    } 
} 

例外發生在platformPluginRemote.getPlugins()呼叫。

回答

0

@RunAs("admin")註釋似乎並沒有出於某種原因(JBoss的錯誤?)

同樣可以通過調用EJB之前添加以下代碼來完成。

SecurityContextAssociation.getSecurityContext().setOutgoingRunAs(new RunAsIdentity("admin", "admin")); 
0

有此issue到JBoss 5日報道這也影響到JBoss應用服務器6.1,修復它,你可以在文件JBOSS_HOME/serve/<instance>/deploy/ejb3-interceptors-aop.xml添加org.jboss.ejb3.security.RunAsSecurityInterceptorFactory攔截:

如:

<! - The additional MDB specific ones -> 
<interceptor-ref name = "org.jboss.ejb3.ENCPropagationInterceptor" /> 
<interceptor-ref name = "org.jboss.ejb3.security.RunAsSecurityInterceptorFactory" /> 
<interceptor-ref name = "CMTTx" /> 
<interceptor-ref name = "org.jboss.ejb3.stateless.StatelessInstanceInterceptor" /> 
<interceptor-ref name = "org.jboss.ejb3.tx.BMTTxInterceptorFactory" /> 
<interceptor-ref name = "org.jboss.ejb3.AllowedOperationsInterceptor" /> 
<interceptor-ref name = "org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor" /> 

在實踐中,提出了我一些問題,而不是所有的角色被傳播的調用以及一些授權錯誤發生。

或者,您可以使用中的Subject.doAs()方法。不要忘記在安全域中添加登錄模塊ClientLoginModule。

+0

感謝您的信息,但我想這對**作爲JBoss 6.1不是7.2 ** – 2015-01-22 03:49:55

+0

@KosalaAlmeda是的,你說得對,是這個問題的解釋的錯誤。再次看到我的答案。 – 2015-01-22 16:08:51

相關問題