Hi,
I have a very annoying issue with my secured Glassfish 3.1.2.
When I connect 2 (or more) users from my EJB client, I am having always the last connected user when I do this in my EJB: sessionContext.getCallerPrincipal().getName();
Could you please give me a help on this issue?
Here is my client:
public static void main(String[] args) {
new Thread(new Runnable() {
@Override
public void run() {
connectUser("userA", "pwdB");
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
connectUser("userB", "pwdB");
}
}).start();
}
public static void connectUser(String userName, String password) {
try {
ProgrammaticLogin login = new ProgrammaticLogin();
login.login(userName, password.toCharArray());
Context context = new InitialContext();
MyServiceRemote myService = (MyServiceRemote) context.lookup("MyService");
String remoteCaller = myService.getUserName();
System.out.println("Local is (" + userName + "), Remote is (" + remoteCaller + ")");
} catch (Exception e) {
e.printStackTrace();
}
}Here is my EJB:
@Stateless(mappedName = "MyService", name="MyServiceBean")
public class MyServiceBean implements MyServiceRemote{
@Resource
private SessionContext sessionContext;
public MyServiceBean () {
super();
}
public String getUserName() {
return sessionContext.getCallerPrincipal().getName();
}
}