Thank you for you answer, i will try to explain better:
I have a jboss server with many EJB services (E1, E2, ..., En) and to connect to that jboss server i need to use JAAS.
I have a client application that is not a web application.
The client application needs to call different EJBs with different logins at different stages (modules) of a client transaction.
That being told, at stage 1 the client application calls service E1 with authentication A1, new InitialContext, new LoginContext.
Context context = new InitialContext(properties);
LoginContext lc = new LoginContext("serverLogin", new NeoCallbackHandler(username1, password1));
lc.login();
Later in transaction, the client application needs to call service E2 with authentication A2, once again, new InitialContext, new LoginContext.Context context = new InitialContext(properties);
LoginContext lc = new LoginContext("serverLogin", new NeoCallbackHandler(username2, password2));
lc.login();
Since the client is processing many transactions, when it calls service E1 again, the authentication A1 has been replaced by A2, so when E1 is called again by the client, the login context is from A2.
This is all in the same thread.
I think there is a problem with JAAS where a VM can hold only 1 login context so i need to know if i can cache the login contexts and switch between them instead of creating a new login context for every call.
Thank you for your patience
[ April 15, 2008: Message edited by: Joel de Matos ]