Using @RunAs in my EJB Schedulers

自作多情 提交于 2019-12-10 19:56:03

问题


I have many EJBs with my business methods. These methods use @RolesAllowed annotation to check if user can execute this method.

So I have an EJB Scheduler that calls these EJB methods. EJB schedulers runs with anonymous user, so authorization fails.

How I can run my schedulers with other role? For testing proposes, I run with @RunAs("SYSTEM") annotation, but I don't know if this is right.

My scheduler class

@RunAs("SYSTEM")
public class InboxScheduler {
    protected void inboxFileScan(Timer t) {
        receiptFilesService.receiptFiles();
    }
}

My EJB class

@RolesAllowed("SYSTEM")
public void receiptFiles() {
    // do anything
}

回答1:


Yes, that's a right use.

The section 12.3.4.1 of the EJB 3.2 specification says that all methods of your bean (including timeout callback methods) will have the identity defined in run-as.

From spec: The run-as identity applies to the enterprise bean as a whole, that is, to all methods of the enterprise bean’s business, home, and component interfaces, no-interface view, and/or web service endpoint; to the message listener methods of a message-driven bean; and to the timeout callback methods of an enterprise bean; and all internal methods of the bean that they might in turn call.



来源:https://stackoverflow.com/questions/4914804/using-runas-in-my-ejb-schedulers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!