I have one application that, basically, receives messages from multiple applications and send them through JMS to a JMS listener. One of the applications that use the previous one, connects to a LDAP server.

In the JMS application , I must initialize the context in this way:

Java Code:
public static Context generateContext() throws NamingException{
		Hashtable<String, String> properties = new Hashtable<String, String>();
		properties.put(Context.INITIAL_CONTEXT_FACTORY,	"weblogic.jndi.WLInitialContextFactory");
		properties.put(Context.PROVIDER_URL, Constants.JMS_URL);
		properties.put(Context.SECURITY_PRINCIPAL, Constants.JMS_USER);
		properties.put(Context.SECURITY_CREDENTIALS, Constants.JMS_PASS);
		return new InitialContext(properties);;
In the application that connects to the LDAP server, I initialize the context like this:
Java Code:
public synchronized static Hashtable<Object, Object> getInitialContextConfiguration() throws NamingException {
		Hashtable<Object, Object> env = new Hashtable<Object, Object>();
		env.put(Context.SECURITY_PRINCIPAL, Constants.LDAP_SERVER_USER);
		env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
		env.put(Context.PROVIDER_URL, Constants.LDAP_SERVER_URL);
		return env;

InitialContext ctx = new InitialContext(getInitialContextConfiguration());
The point is that, when I need to send a JMS message, it looses it's own context and uses the last one that was created, and of course, throws a Security Exception. Is there any way to avoid this besides keep closing and opening contexts indefinitely?

Hope I was clear enough.

Thanks in advance