Hi, Your actual error is caused by the login module trying to access the default initial context (you don't have one).
It wont be able to access the java:/ namespace anyway (this is only available inside the same virtual machine using naming properties that don't specify a providerurl). The connection pool is not a remote object. Regards, Adrian On Sun, 2003-08-24 at 19:13, Maiquel Sampaio de Melo wrote: > Hi all, > Hi trying to run a test client with jaas. I'm > using mySQL and DatabaseServerLoginModule. Can anybody > help me? > This is my code: > > package br.ufc.npd.votacao.client; > > import java.util.ArrayList; > import java.util.Properties; > > import javax.naming.Context; > import javax.naming.InitialContext; > import javax.rmi.PortableRemoteObject; > import javax.security.auth.callback.CallbackHandler; > import javax.security.auth.login.LoginContext; > import javax.security.auth.login.LoginException; > > import > br.ufc.npd.votacao.interfaces.NPDCallbackHandler; > import > br.ufc.npd.votacao.interfaces.UnidVotacaoServicosHome; > import > br.ufc.npd.votacao.interfaces.UnidVotacaoServicos; > > public class TesteUnidade > { > public static void main(String[] args) > { > try > { > System.out.println("Run Test-Client..."); > > Properties p = new Properties(); > > p.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); > > p.setProperty("java.naming.provider.url","jnp://localhost:1100"); > > p.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces"); > > p.setProperty("jnp.socketFactory","org.jnp.interfaces.TimedSocketFactory"); > /* > p.put(Context.INITIAL_CONTEXT_FACTORY, > "org.jnp.interfaces.NamingContextFactory"); > > p.put(Context.URL_PKG_PREFIXES,"jboss.naming:org.jnp.interfaces"); > p.put(Context.PROVIDER_URL,"localhost:1100"); > */ > InitialContext ctx = new InitialContext(p); > > > Object ref = > ctx.lookup(UnidVotacaoServicosHome.JNDI_NAME); > UnidVotacaoServicosHome ejbHome = > (UnidVotacaoServicosHome)PortableRemoteObject.narrow(ref, > UnidVotacaoServicosHome.class); > > // create the session-bean > UnidVotacaoServicos ejbObj = ejbHome.create(); > > testMethod(ejbHome, ejbObj); // call your > test-method > > // remove the session-bean > ejbObj.remove(); > System.out.println("Test-Client finished without > errors."); > } > catch(Exception ex) > { > ex.printStackTrace(); > } > } > > > /*************************************************************************** > * +++ Private Helper-Methods > +++ > > **************************************************************************/ > > /** > * this is your test-method > */ > private static void > testMethod(UnidVotacaoServicosHome ejbHome, > UnidVotacaoServicos ejbObj) throws Exception > { > // now you can call the business-methods of the > ejb > // Example: > // ejbHome.yyyyy(); -> method from the > Home-Interface > // ejbObj.xxxxx(); -> method from the > Remote-Interface > String login = "maiquel"; > String senha = "1234563"; > char[] password; > password = senha.toCharArray(); > > try > { > NPDCallbackHandler handler = new > NPDCallbackHandler(login, password); > LoginContext lc = new LoginContext("votacao", > handler); > System.out.println("Created LoginContext"); > lc.login(); > } > catch (LoginException le) > { > System.out.println("Login failed"); > le.printStackTrace(); > } > > try > { > ArrayList lista = ejbObj.listarUnidades(); > System.out.println("Nr. de Unidades: "+ > lista.size()); > ejbObj.remove(); > } > catch (Exception e) > { > e.printStackTrace(); > } > } > > } > > This is my auth.conf: > votacao { > /* A JDBC based LoginModule > LoginModule options: > dsJndiName: The name of the DataSource of the database > containing the Principals, Roles tables > principalsQuery: The prepared statement query > equivalent to: > "select Password from Principals where > PrincipalID=?" > rolesQuery: The prepared statement query equivalent > to: > "select Role, RoleGroup from Roles where > PrincipalID=?" > */ > > org.jboss.security.auth.spi.DatabaseServerLoginModule > required > dsJndiName="java:/MysqlVotacaoDS" > principalsQuery="select Password from Principals > where PrincipalID=?" > rolesQuery="select Role, RoleGroup from Roles > where PrincipalID=?" > unauthenticatedIdentity=nobody > ; > }; > > This is my program result: > Run Test-Client... > Created LoginContext > Login failed > javax.security.auth.login.LoginException: > javax.naming.NoInitialContextException: Need to > specify class name in environment or system property, > or as an applet parameter, or in an application > resource file: java.naming.factory.initial > at > org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPassword(DatabaseServerLoginModule.java:110) > at > org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:143) > 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:324) > at > javax.security.auth.login.LoginContext.invoke(LoginContext.java:675) > at > javax.security.auth.login.LoginContext.access$000(LoginContext.java:129) > at > javax.security.auth.login.LoginContext$4.run(LoginContext.java:610) > at java.security.AccessController.doPrivileged(Native > Method) > at > javax.security.auth.login.LoginContext.invokeModule(LoginContext.java:607) > at > javax.security.auth.login.LoginContext.login(LoginContext.java:534) > at > br.ufc.npd.votacao.client.TesteUnidade.testMethod(TesteUnidade.java:79) > at > br.ufc.npd.votacao.client.TesteUnidade.main(TesteUnidade.java:44) > Nr. de Unidades: 4 > Test-Client finished without errors. > > Thanks, > Maiquel > > _______________________________________________________________________ > Desafio AntiZona: participe do jogo de perguntas e respostas que vai > dar um Renault Clio, computadores, câmeras digitais, videogames e muito > mais! www.cade.com.br/antizona > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines > at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0 > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user ------------------------------------------------------- This SF.net email is sponsored by: VM Ware With VMware you can run multiple operating systems on a single machine. WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0 _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user