How do I change callerPrincipal from EJB timer?

516 views Asked by At

My EJB timer always runs with UNAUTHENTICATED user. I tried to put @RunAs but did not work. I tried to change the value with reflection and did not work, I need call a remote EJB from this and I need a user that has permission.

@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

There are 0 answers