tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
1024
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    sebastianb sebastianb ist offline Mitglied Gold
    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
     

  2. #2
    sebastianb sebastianb ist offline Mitglied Gold
    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

    Sebastian
    Geändert von sebastianb (16.12.09 um 11:23 Uhr)
     

Ähnliche Themen

  1. Secure WebserviceCommunication
    Von phi_2k im Forum Enterprise Java (JEE, J2EE, Spring & Co.)
    Antworten: 7
    Letzter Beitrag: 14.11.07, 11:06
  2. Antworten: 0
    Letzter Beitrag: 16.05.07, 13:24
  3. WSF - World Secure Force
    Von Master-E im Forum 3D-Stills
    Antworten: 7
    Letzter Beitrag: 31.08.05, 19:47
  4. Omni Secure
    Von Stelo im Forum PHP
    Antworten: 18
    Letzter Beitrag: 05.06.05, 19:34
  5. secure ftp mit php
    Von südpol im Forum PHP
    Antworten: 2
    Letzter Beitrag: 12.05.03, 13:57

Stichworte