Home > EJB, Glassfish, Java > How to call a secured remote EJB on Glassfish 2

How to call a secured remote EJB on Glassfish 2

I’ve recently needed to call an EJB deployed on a Glassfish 2.1 server from a standalone Java application.

The EJB was secured, under a custom security realm. I had trouble finding answers on-line regarding how the secured EJBs are supposed to be called, and, after a lot of work I finally found the solution with the programmatic login. I suppose it’s a basic thing to know, but given how long I’ve spent googling for an answer, I figured an extra information source can’t be that bad.

Here is the version of the code I’ve ended up using:

“<some local path>\\auth.conf”);

ProgrammaticLogin pl = new ProgrammaticLogin();
pl.login(“user”, “password”);

Properties props = new Properties();

props.setProperty(“org.omg.CORBA.ORBInitialHost”, “localhost”);
props.setProperty(“org.omg.CORBA.ORBInitialPort”, “3700”);

InitialContext ic = new InitialContext(props);

entityService = (MyBeanRemote) ic


The contents of the auth.conf file were something like:

default {
com.sun.enterprise.security.auth.login.ClientPasswordLoginModule required debug=true;

This means that the default security realm is used, so I needed to set as default the realm on which the application was authenticated.

This worked without any issues.

An option which I haven’t tried, to improve the code, would be to call an overloaded version of the login method, in order to also specify the realm.

login(String user, String password, String realm, boolean errors)

There is additional information about the ProgrammaticLogin class here:


  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s