vendredi 12 juin 2015

how I change callerPrincipal from Ejb timer?

My ejb timer run always with "UNAUTHENTICATED" user, I tried to put @RunAs but don't work. I tried to change the value with reflection and not work, I need call a remote ejb from this and I need a user that have 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()
     }

Aucun commentaire:

Enregistrer un commentaire