In your web application, when searching for beans using JNDI, you need to pass the user / password information to the InitialContext constructor (code from: http://schuchert.wikispaces.com/EJB3+Tutorial+6+-+Security )
public InitialContext getInitialContextFor(final String user,
final String password) throws NamingException {
final Properties p = new Properties();
p.setProperty(Context.SECURITY_PRINCIPAL, user);
p.setProperty(Context.SECURITY_CREDENTIALS, password);
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.security.jndi.JndiLoginInitialContextFactory");
return new InitialContext(p);
}
If you want your web application container to do this automatically for you, I don’t know how to do it.
By the way - are you using the same container for web applications and ejbs?
source
share