ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
1024
1024
EMPFEHLEN
-
15.12.09 21:45 #1
- Registriert seit
- Dec 2009
- Beiträge
- 125
Hi zusammen,
im Rahmen eines Semesterprojekts "muss" ich mich aktuell mit EJB, JBoss und deren Security beschäftigen.
Zum Einstieg habe ich folgendes Tutorial
http://www.tutorials.de/forum/enterp...s-4-0-2-a.html
übernommen, welches auch wunderbar funktioniert (Hierfür beide Daumen hoch an Thomas
)
Jetzt stehe ich vor dem Problem meine EJB-Anwendung bzw deren Methoden abzusichern, welche ich über RMI aus einer JSP aufrufe.
Hierfür habe ich folgende Annotations hinzugefügt:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
@Stateless public class TestBean implements TestBeanRemote { @PersistenceContext(unitName="testCoreUnit") EntityManager em; @Resource SessionContext context; @RolesAllowed("admin") public Employee test() { Employee e = new Employee("Mustermann", "Max", "1234", new Company("Ich AG")); System.out.println(e); System.out.println(context.getCallerPrincipal()); return e; } }
außerdem habe in META-INF die Datei jboss.xml hinzugefügt:
Code :1 2 3 4
<?xml version="1.0" encoding="UTF-8"?> <jboss> <security-domain>TestSecurityDomain</security-domain> </jboss>
Den Aufruf aus der JSP habe ich mir wie folgt gedacht:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<%@ page import="java.util.*" import="javax.naming.*" import="javax.rmi.PortableRemoteObject" import="de.hfu.test.ejb.core.beans.*" import="javax.ejb.EJBAccessException" %> <% try { Properties p = new Properties(); p.put(Context.SECURITY_CREDENTIALS,"geheim"); p.put(Context.SECURITY_PRINCIPAL,"admin"); p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.security.jndi.JndiLoginInitialContextFactory"); p.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "jnp://localhost:1099"); Context ctx = new InitialContext(p); Object ref = ctx.lookup(TestBeanRemote.JNDI_NAME); TestBeanRemote tbr = (TestBeanRemote) PortableRemoteObject .narrow(ref, TestBeanRemote.class); tbr.test(); } catch(EJBAccessException e) { e.printStackTrace(); }
Offensichtlich habe ich mir das ganze aber etwas zu leicht gemacht, denn sobald die test() Methode aufgerufen wird, fliegt mir ne EJBAcessException um die Ohren: InvalidUser.
Kann mir jemand vll auf die Sprünge helfen?
Hier noch mein System:
Ubuntu: 9.04
MySql: 5.1.31
JBoss: 5.1.0-GA
Java: 1.6.0_16
Viele Grüße und schonmal vielen Dank!
Sebastian
-
16.12.09 09:51 #2
- Registriert seit
- Dec 2009
- Beiträge
- 125
Hi zusammen,
offenbar habe ich hier nun ein funktionierendes Kontrukt gefunden, was genau das macht was ich brauche.
Falls jemand jedoch eine schönere Lösung hat, wäre ich sehr dankbar, wenn man mir diese mitteilen könnte =)
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Hashtable<String, String> props = new Hashtable<String, String>(); props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); props.put(Context.PROVIDER_URL,"jnp://" + "localhost"); props.put(Context.SECURITY_PRINCIPAL, "admin"); props.put(Context.SECURITY_CREDENTIALS, "admin"); Context ctx; try { ctx = new InitialContext(props); TestBeanRemote pbr = (TestBeanRemote) ctx.lookup(TestBeanRemote.JNDI_NAME); pbr.test(); } catch (NamingException e) { e.printStackTrace(); }
Aktuell hat sich jedoch ein anderes Problem ergeben und zwar benötige ich die eingegebenen Daten von j_username und j_password (siehe unten) in einer darauffolgenden JSP. An der action "j_security_check" kann ich leider nichts ändern, da sonst die JBoss authentifizierung nicht mehr funktioniert. Gibt es hierzu ein hübsche Methode die Werte durchzureichen?
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<form name=login method="post" action="j_security_check"> <tr> <td>Benutzername: </> <td><input type="text" maxlength="32" name="j_username"/></td> </tr> <tr> <td>Passwort: </> <td><input type="password" maxlength="32" name="j_password"/></td> </tr> <tr> <td> <input type="submit" value="Anmelden"/> </td> <td> </td> </tr> </form>
Viele Grüße
SebastianGeändert von sebastianb (16.12.09 um 11:23 Uhr)
Ähnliche Themen
-
Secure WebserviceCommunication
Von phi_2k im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 7Letzter Beitrag: 14.11.07, 11:06 -
This page contains both secure and non-secure items- JS ist das Prob
Von IR-Bastian im Forum Javascript & AjaxAntworten: 0Letzter Beitrag: 16.05.07, 13:24 -
WSF - World Secure Force
Von Master-E im Forum 3D-StillsAntworten: 7Letzter Beitrag: 31.08.05, 19:47 -
Omni Secure
Von Stelo im Forum PHPAntworten: 18Letzter Beitrag: 05.06.05, 19:34 -
secure ftp mit php
Von südpol im Forum PHPAntworten: 2Letzter Beitrag: 12.05.03, 13:57





Zitieren
Login





