Skip to main content

@RunAs and Role Propagation

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
laminos
Offline
Joined: 2012-10-03

Glassfish-3.1.2.2

I have 1 Servlet and 2 EJB in my project.

Servlet--------->Init--------------->Print

// EJB init code

@Stateless
@RunAs("SYSTEM")
@DeclareRoles({"SYSTEM"})
public class Init {

@Resource
EJBContext ejb;
@EJB
private Print print;

public String initialize() {

System.out.println("**********" + ejb.getCallerPrincipal().getName());
System.out.println("**********" + ejb.isCallerInRole("SYSTEM"));

return print.printline();
}
}

// EJB Print code:

@Stateless
@DeclareRoles({"SYSTEM"})
public class Print {

@Resource
EJBContext ejb;

public void printline() {

System.out.println("**********" + ejb.getCallerPrincipal().getName());
System.out.println("*********" + ejb.isCallerInRole("SYSTEM"));

}
}

// Execution result:

INFO: **********ANONYMOUS (OK)
INFO: **********false (OK)

INFO: **********system (OK)
INFO: **********false (? )

Why Am I getting the second false (I am expecting true) ?

mapping of web project and ejb project


SYSTEM
system

Thank you.