Mike Hanafey
Mike Hanafey

Reputation: 5643

Is it possible to use programmatic login in an application client in Glassfish that also uses bean injection?

While playing with "cart-secure" example in the Glassfish Java EE 7 tutorial I attempted to do "Programmatic Login".

In the "CartClient", it is easy to do the programmatic login (say in the constructor). But the problem is the normal callback login mechanism runs first, and only after successfully authenticating interactively does the programmatic login take effect.

The question is how to do a programmatic login in the application client before injection invokes the callback login scheme.

Upvotes: 0

Views: 121

Answers (1)

Mike Hanafey
Mike Hanafey

Reputation: 5643

I appears that you cannot inject an EJB that requires authentication statically into the application client main class (and any injection must be into a static variable because the client container does not instantiate this class).

You can inject an EJB that does not require authentication, and have that bean inject EJB's that require authentication. Just make sure the programmatic login is done before referencing any bean that requires authentication.

More straightforwardly, just do an explicit JNDI lookup in the main client class.

Better still, avoid programmatic login unless is is absolutely necessary.

Upvotes: 0

Related Questions