我有一個匿名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