感謝伊夫·馬丁的建議。我試着按照你的建議嘗試添加jboss.xml和ejb-jar.xml,不幸的是它沒有工作。
我一遍又一遍地檢查了代碼,最後我找到了解決這個問題的辦法。我原來的代碼設置情況如下:
ObjectRepository接口:
public interface ObjectRepository<T extends DomainObject>
{
public T save(T object);
...
}
TaskServiceBeanLocal接口:
@Local
public interface TaskServiceBeanLocal extends ObjectRepository<Task>
{
}
任務EJB:
@Stateless
@LocalBinding(jndiBinding = TaskServiceBean.LOOKUP_STRING)
@SecurityDomain(value = Security.DOMAIN)
@DeclareRoles({ Roles.ADMIN, Roles.CLERK, Roles.READ_ONLY })
//By default, allow no one access, we'll enable access at the method level
@RolesAllowed({})
public class TaskServiceBean implements TaskServiceBeanLocal
{
public static final String LOOKUP_STRING = "TaskServiceBean/local";
@RolesAllowed({ Roles.ADMIN, Roles.CLERK })
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Override
public Task save(Task task)
{
...
}
}
的的Arquillian無法訪問TaskServiceBean .save()方法的錯誤,如問題:
TRACE [org.jboss.security.authorization.modules.ejb.EJBPolicyModuleDelegate] Exception:Insufficient method permissions, principal=myuser, ejbName=SecureServiceBean, method=save, interface=Local, requiredRoles=Roles(), principalRoles=Roles(Admin,)
從TRACE日誌記錄中,由於未知原因,requiredRoles()爲空。我測試通過實施不同的方法將TaskServiceBeanLocal和TaskServiceBean具有相同的權限:
@Local
public interface TaskServiceBeanLocal extends ObjectRepository<Task>
{
public void test();
}
//and implement the test() method, having the same permission as the save() method.
public class TaskServiceBean implements TaskServiceBeanLocal
{
@RolesAllowed({ Roles.ADMIN, Roles.CLERK })
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Override
public Task save(Task task)
{
...
}
@RolesAllowed({ Roles.ADMIN, Roles.CLERK })
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Override
public void test()
{
System.out.println("hello");
}
}
令我驚訝的是,檢測試驗()方法是成功的。因此,我然後在界面中重新聲明save()方法:
@Local
public interface TaskServiceBeanLocal extends ObjectRepository<Task>
{
public Task save(Task object);
public void test();
}
現在,測試save()方法成功。在TRACE日誌記錄中,我可以看到我的requiredRoles完全填充在方法簽名中。
13:44:35,399 TRACE [org.jboss.security.authorization.modules.ejb.EJBPolicyModuleDelegate] method=public au.com.infomedix.harvey.humantask.domain.Task au.com.infomedix.harvey.ejb.TaskServiceBean.save(au.com.infomedix.harvey.humantask.domain.Task), interface=Local, requiredRoles=Roles(Clerk,Admin,)
我的猜測是,Arquillian沒有注入通用方法簽名的安全信息,但老實說我並不完全理解這一點。
無論如何,重新聲明界面中的方法可以修復問題。 Arquillian現在可以訪問我的受保護的EJB。感謝大家的寶貴意見。
- Linh
您可以發佈您的測試代碼嗎? –