Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I authenticate an application client to EJB 3.0 server
    primarykey
    data
    text
    <p>I am very new to the whole J2EE architecture. Could somebody help me out?</p> <p>I have a Swing client with Login, Password fields on machine A.</p> <pre><code>Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "jnp://localhost:1099/"); InitialContext ctx = new InitialContext(p); ejb = (MyBeanRemote) ctx.lookup("DemoServer/MyBean/remote"); </code></pre> <p>I have an EJB 3.0 on JBoss5 on machine B:</p> <pre><code>@Stateful @DeclareRoles({"editor", "viewer"}) public class MyBean implements MyBeanRemote, Serializable { @RolesAllowed({"editor"}) public boolean modify() throws Exception { if(!ctx.isCallerInRole("editor")) throw new SecurityException("Can't modify"); return true; } @RolesAllowed({"viewer","editor"}) public boolean view() throws Exception { if(!ctx.isCallerInRole("viewer")) throw new SecurityException("Can't view"); return true; } } </code></pre> <p>I have a DB with users and roles on server (conf/login-conf.xml):</p> <pre><code>&lt;application-policy name="jboss-secure"&gt; &lt;authentication&gt; &lt;login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required"&gt; &lt;module-option name="unauthenticatedIdentity"&gt;guest&lt;/module-option&gt; &lt;module-option name="dsJndiName"&gt;java:/MyDerby&lt;/module-option&gt; &lt;module-option name="principalsQuery"&gt;SELECT Password FROM Users WHERE Username=?&lt;/module-option&gt; &lt;module-option name="rolesQuery"&gt;SELECT Role, 'Roles' FROM Users WHERE Username=?&lt;/module-option&gt; &lt;/login-module&gt; &lt;/authentication&gt; &lt;/application-policy&gt; </code></pre> <p>META-INF/jboss.xml:</p> <pre><code>&lt;jboss&gt; &lt;security-domain&gt;java:/jaas/jboss-secure&lt;/security-domain&gt; &lt;/jboss&gt; </code></pre> <p>As I understand, I shouldn't get ejb reference until client is authenticated properly. How do I use LoginContext, and do I use it at all? Can/should I use <code>@EJB private MyBeanRemote ejb</code>? And how do I make the whole thing work?</p> <p>I am just trying to build a seemingly trivial thing: authorization of application client. I feel stupid.</p> <p>Thank you very much.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload