Java @@WebService EJB的运行方式

Java @@WebService EJB的运行方式,java,web-services,security,ejb,Java,Web Services,Security,Ejb,我有一个匿名WebService EJB-WebService调用正在流行 现在我希望Web服务作为特定的SecurityRole运行 在Webservice中,我有以下注释: @Stateless @WebService @DeclareRoles({ "LoggedUser" }) @SecurityDomain("my-jboss-real") @RunAs("LoggedUser") public class MyWebService { ... 现在,我想使用@RolesAllowe

我有一个匿名WebService EJB-WebService调用正在流行

现在我希望Web服务作为特定的SecurityRole运行

在Webservice中,我有以下注释:

@Stateless
@WebService
@DeclareRoles({ "LoggedUser" })
@SecurityDomain("my-jboss-real")
@RunAs("LoggedUser")
public class MyWebService { ...
现在,我想使用
@RolesAllowed({“LoggedUser”})
从Web服务方法访问
@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)
我正在运行JBoss5.1GA

这是
@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

JBossAS5,尤其是6在安全上下文和@RunAs方面都有很大的缺陷,除了最基本的用例

这些bug中有大量已经在中修复 如图7所示。您可以尝试在那里设置一个测试用例,看看是否遇到相同的问题

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

更麻烦的是JavaEE有一个严重的任务,那就是无法同时定义RunAs标识。当您为“未经身份验证”标识定义RunAs角色时,某些服务器的反应不好。JBoss对RunAs标识有一个专有的注释。如果这能让你更进一步,你可能想试试