2012-04-11 9 views
0

Ich versuche, eine Authentifizierung von Datenbank JAAS mit auszuführen ich die login-config.xml wie dieseJAAS + Authentifizierung von Datenbank

<application-policy name="e-procurment_domaine"> 
<authentication> 
<login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required"> 
<module-option name = "dsJndiName">BasepfeDS</module-option> 
<module-option name="securityDomain">java:/jaas/e-procurment_domaine</module-option> 
<module-option name="principalsQuery">SELECT pass FROM personne WHERE login=?</module-option> 
<module-option name="rolesQuery">SELECT disc FROM personne WHERE login=?</module-option> 
</login-module> 
</authentication> 
</application-policy> 

so konfiguriert haben, und ich habe einen Test geschrieben: diese ein

@Test 
    public void testFindALL() { 
     System.out.println("Debut test de la méthode findALL"); 

//  WebAuthentication wa=new WebAuthentication(); 
//  wa.login("zahrat", "zahrat"); 
     securityClient.setSimple("zahrat", "zahrat"); 

     try { 
      securityClient.login(); 
     } catch (LoginException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     Acheteur acheteur = new Acheteur(); 
     System.out.println("" + acheteurRemote.findAll().size()); 

     // } catch (EJBAccessException ex) { 
     // System.out.println("Erreur attendue de type EJBAccessException: " 
     // + ex.getMessage()); 

     // } catch (Exception ex) { 

     // ex.printStackTrace(); 
     // fail("Exception pendant le test find ALL"); 
     System.out.println("Fin test find ALL");} 

    // } 

der Test ist, ich weiß nicht, warum nicht, aber wenn ich die POLYCY ändern sich mit der Methode von .property Datei funktioniert ..

ich bin mit der Anmerkung zu den s ITZUNG BEAN Klassen

@SecurityDomain("e-procurment_domaine") 
@DeclareRoles({"acheteur","vendeur","physique"}) 
@RolesAllowed({"acheteur","vendeur","physique"}) 

und die Anmerkung auf der Sitzung für die Methode

@RolesAllowed("physique") 
    @Override 
    public List<Acheteur> findAll() { 
     log.debug("fetching all Acheteur"); 
     return daoGenerique.findWithNamedQuery("Acheteur.findAll"); 
    } 

ich denke, dass der Test doe es brauchen MySQL-Treiber oder eine spezielle Konfiguration auf JBOSS ein acess zu meiner Datenbank haben ?


der Stack-Trace ist:

javax.ejb.EJBAccessException: Invalid User 
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:161) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.interceptor.EJB3TCCLInterceptor.invoke(EJB3TCCLInterceptor.java:86) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:392) 
    at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:53) 
    at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91) 
    at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82) 
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:898) 
    at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:791) 
    at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:744) 
    at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:548) 
    at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:234) 
    at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:216) 
    at org.jboss.remoting.Client.invoke(Client.java:1961) 
    at org.jboss.remoting.Client.invoke(Client.java:804) 
    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:77) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.async.impl.interceptor.AsynchronousClientInterceptor.invoke(AsynchronousClientInterceptor.java:143) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62) 
    at $Proxy12.invoke(Unknown Source) 
    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:185) 
    at $Proxy11.findAll(Unknown Source) 
    at com.soutem.test.UtilsateurSessionBean.testFindALL(UtilsateurSessionBean.java:180) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:77) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.ejb3.async.impl.interceptor.AsynchronousClientInterceptor.invoke(AsynchronousClientInterceptor.java:143) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) 
    at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62) 
    at $Proxy12.invoke(Unknown Source) 
    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:185) 
    at $Proxy11.findAll(Unknown Source) 
    at com.soutem.test.UtilsateurSessionBean.testFindALL(UtilsateurSessionBean.java:180) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

Antwort

0

MySQL-Treiber, muss natürlich auf JBoss eingesetzt werden. Und Sie müssen die JDBC-Verbindung mit dem Namen "BasepfDS" an der JBoss-Konfigurationskonsole definieren.

Voll Stack-Trace kann viel hilfreicher für debuggen ...

+0

die BasepfeDS ist corectly geschrieben, weil mein Web- und Android-Client korrekt funktioniert und mein Treiber mysql auf dem Server ist, sind alle Tests korrekt; – AhmedDrira

+0

bitte überprüfen Sie das Ergebnis: SELECT Disc, übergeben von Person WHERE login = 'zahrat' –

+0

es funktioniert, mit dieser Richtlinie – AhmedDrira

0

es funktioniert, mit dieser Politik

<application-policy name="testDB"> <authentication><login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule"flag="required"> 
<module-option name="dsJndiName">java:/BasepfeDS</module-option><module-option name="principalsQuery"> select pass from personne where login=?</module-option><module-option name="rolesQuery"> select disc, 'Roles' from personne where login=?</module-option></login-module></authentication> 

die JBOSS Dokumentation sehr nützlich ist und klar http://docs.jboss.org/jbosssecurity/docs/6.0/security_guide/html_single/index.html#sect-DatabaseServerLoginModule

Verwandte Themen