Wie authentifizieren ich einen Anwendungs-Client 3.0-Server EJB
Frage
Ich bin sehr neu in der ganzen J2EE-Architektur. Könnte mir jemand helfen?
Ich habe einen Swing-Client mit Login, Passwort Felder auf Maschine A.
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");
Ich habe eine EJB 3.0 auf JBoss5 auf Maschine B:
@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;
}
}
Ich habe eine DB mit Benutzern und Rollen auf dem Server (conf / login-conf.xml):
<application-policy name="jboss-secure">
<authentication>
<login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
<module-option name="unauthenticatedIdentity">guest</module-option>
<module-option name="dsJndiName">java:/MyDerby</module-option>
<module-option name="principalsQuery">SELECT Password FROM Users WHERE Username=?</module-option>
<module-option name="rolesQuery">SELECT Role, 'Roles' FROM Users WHERE Username=?</module-option>
</login-module>
</authentication>
</application-policy>
META-INF / jboss.xml:
<jboss>
<security-domain>java:/jaas/jboss-secure</security-domain>
</jboss>
Wie ich verstehe, soll ich nicht ejb Referenz erhalten, bis Client korrekt authentifiziert ist. Wie verwende ich Logincontext und verwende ich es überhaupt? Kann / soll ich @EJB private MyBeanRemote ejb
benutzen? Und wie kann ich das Ganze funktioniert?
Ich versuche nur, eine scheinbar triviale Sache zu bauen: Genehmigung von Anwendungs-Client. Ich fühle mich dumm.
Vielen Dank.
Lösung
Ich habe einige Arbeit mit JAAS kuerzlich und fand kann es ziemlich schwierig sein. Schauen Sie sich diese beiden Ressourcen, die ich fand sie sehr nützlich http://www.jaasbook.com/ und http://docs.jboss.org/jbossas/admindevel326/html/ch8. chapter.html
Ich habe auch eine Last von anderem JAAS Buch Ressourcen markiert unter http://delicious.com/chronosMark / JAAS hoffentlich einer von ihnen wird Ihnen helfen, wenn die beiden anderen nicht tun.
Andere Tipps
Es gibt ein Tutorial hier