如何从EJB计时器更改callerPrincipal?

时间:2015-06-12 21:46:46

标签: java java-ee ejb websphere ejb-timer

我的EJB计时器始终与UNAUTHENTICATED用户一起运行。我试图放@RunAs但是没有用。我尝试用反射更改值并且不起作用,我需要从中调用远程EJB,我需要有权限的用户。

@Resource
private SessionContext context;

@Schedule(second= "*/5", minute = "*", hour = "*", persistent = false)
public void executa(){

    Principal callerPrincipal = context.getCallerPrincipal();
    final Field field = getField(callerPrincipal.getClass(), "name");
    field.setAccessible(true);

    try {
        field.set(callerPrincipal,"MYUSER");
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    this.iMyRemoteEjb.doWork()
 }

0 个答案:

没有答案