2012-09-13 35 views
3

我有一个匿名WebService EJB - webservice调用正在正常工作。@RunAs for @WebService EJB

现在我想将WebService作为一个特定的SecurityRole来运行。

在一个Webservice,我有以下注释:

@Stateless 
@WebService 
@DeclareRoles({ "LoggedUser" }) 
@SecurityDomain("my-jboss-real") 
@RunAs("LoggedUser") 
public class MyWebService { ... 

现在我想从Webservice的方法有与@RolesAllowed({"LoggedUser"})访问@EJB我得到:

ERROR [org.jboss.aspects.tx.TxPolicy] javax.ejb.EJBTransactionRolledbackException: javax.ejb.EJBAccessException.message: 'Caller unauthorized' 
WARN [org.jboss.ejb3.stateless.StatelessBeanContext] EJBTHREE-1337: do not get WebServiceContext property from stateless bean context, it should already have been injected 
ERROR [org.jboss.ws.core.jaxws.SOAPFaultHelperJAXWS] SOAP request exception 
javax.ejb.EJBTransactionRolledbackException: javax.ejb.EJBAccessException.message: 'Caller unauthorized' 
     at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115) 

我在JBoss 5.1上运行GA

这是否正确使用@RunAs还是有另一种方法来做到这一点。

编辑

补充:

@Resource 
private WebServiceContext wsCtx; 
@Resource 
private EJBContext ejbCtx; 

myWebServiceMethod(){ 
    ... 
    System.out.println("EJBCtx: " + ejbCtx.getCallerPrincipal()); 
    System.out.println("EJBCtx: " + ejbCtx.isCallerInRole("LoggedUser")); 
    System.out.println("WebContext: " + wsCtx.getUserPrincipal()); 
    System.out.println("WebContext: " + wsCtx.isUserInRole("LoggedUser")); 
    ... 

此输出:

EJBCtx: anonymous 
EJBCtx: false 
WebContext: anonymous 
WebContext: false 

回答

4

JBoss AS中5和6特别是非常错误关于安全上下文和@RunAs在任何但最基本的用例。

大量这些错误已在 AS 7中修复。您可以尝试在那里设置测试用例,看看是否遇到同样的问题。

请认识到@RunAs不适用于在应用了注释的bean中运行的代码。相反,它只适用于从bean中调用的bean。您可以将其视为“传出/传出”角色。

更麻烦的是Java EE有一个严重的遗漏,那就是没有办法同时定义一个RunAs 的标识。当您为“未经身份验证的”身份定义RunAs角色时,某些服务器的反应不佳。 JBoss拥有RunAs标识的专有注释。如果这会让你更进一步,你可能会想尝试。