6 Replies Latest reply on Apr 7, 2004 11:41 AM by antoine

    Datasource not binding when trying to access DatabaseServerL

    sanjuthomas Newbie

      hi all,
      wer are trying use DatabaseServerLoginModule to secure EJBs, but when we try to access DatabaseServerLoginModule we are getting Exception that Datasource not bound. please see the code

      login-config.xml

      <application-policy name="OptiwiseDatabase">

      <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
      <module-option name="dsJndiName">java:/OracleDS</module-option
      <module-option name="principalsQuery">"SELECT OW_PASSWORD FROM OW_T_USER WHERE OW_USERID=?"</module-option>
      <module-option name="rolesQuery">"SELECT OW_T_ROLE.OW_NAME FROM OW_T_ROLE WHERE OW_OID IN (SELECT OW_T_USERROLE.OW_ROLEOID FROM OW_T_USERROLE WHERE OW_USEROID = (SELECT OW_T_USER.OW_OID FROM OW_T_USER WHERE OW_USERID=?))"</module-option>
      </login-module>

      </application-policy>

      client program

      import javax.naming.Context;
      import java.util.Hashtable;
      import javax.naming.InitialContext;
      import javax.security.auth.login.LoginContext;
      import org.apache.log4j.Logger;
      import org.jboss.security.auth.callback.UsernamePasswordHandler;

      /**
      *
      * @author Optiwise
      */
      public class OptiwiseTestClient
      {
      public static void main(String args[]) throws Exception
      {
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      Logger log = Logger.getLogger("OptiwiseDatabase");
      log.info("Login with username="+args[0]+", password="+args[1]);
      UsernamePasswordHandler handler = new UsernamePasswordHandler(args[0], args[1].toCharArray());
      LoginContext lc = new LoginContext("OptiwiseDatabase", handler);
      lc.login();

      log.info("Looking up RequestMgr Bean");
      InitialContext iniCtx = new InitialContext(env);
      Object ref = iniCtx.lookup("RequestMgr");
      RequestMgrHome home = (RequestMgrHome) ref;
      RequestMgr ob1 = home.create();
      log.info(ob1);
      System.out.println(ob1);
      log.info("Created Request Manager Object");
      lc.logout();
      }
      }


      auth.conf

      OptiwiseDatabase
      {
      org.jboss.security.auth.spi.DatabaseServerLoginModule required
      dsJndiName="java:/OracleDS";
      };

      Exception when running the client program


      F:\sanju\work\JBoss>java -Djava.security.auth.login.config=%JBOSS_HOME%\client\a
      uth.conf OptiwiseTestClient sanju sanju
      Exception in thread "main" javax.security.auth.login.LoginException: javax.namin
      g.NameNotFoundException: OracleDS not bound
      at org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPasswor
      d(DatabaseServerLoginModule.java:110)
      at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(Usernam
      ePasswordLoginModule.java:150)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at javax.security.auth.login.LoginContext.invoke(LoginContext.java:664)
      at javax.security.auth.login.LoginContext.access$000(LoginContext.java:1
      29)
      at javax.security.auth.login.LoginContext$4.run(LoginContext.java:599)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.login.LoginContext.invokeModule(LoginContext.java
      :596)
      at javax.security.auth.login.LoginContext.login(LoginContext.java:523)
      at OptiwiseTestClient.main(OptiwiseTestClient.java:24)


      if anybody know waht is the error please help me.......

      thanking you
      sanju

        • 1. Re: Datasource not binding when trying to access DatabaseSer
          antoine Newbie

          did you reference in your deploy directory a oracle-ds.xml ?
          it must contain a driver and an url. is it the same name for datasource.

          I try to use DatabaseServerLogin but I fail when i create logincontext

          I receive this message :
          access denied (javax.security.auth.AuthPermission createLoginContext.MyLogin)

          I create a file poliy with grant codebase "file:./*" { permission javax.security.auth.AuthPermission "createLoginContext.MyLogin"; };

          thanks for your help

          • 2. Re: Datasource not binding when trying to access DatabaseSer
            sanjuthomas Newbie

            yes I have written Oracle-ds.xml and kept in the .../server/default/deploy directory. and it is working fine. my other simple EJBs are able to access this ConnectionPoll. but when trying to access using this secure client its generating exception. if you know the reason please help me.
            then about your problem... you please give all permission, i have given that. i am not clear on this topics, really a beginner. if you know please help me....

            policy file.
            grant {
            // Allow everything for now
            permission java.security.AllPermission;
            };

            thank you for your comment.

            • 3. Re: Datasource not binding when trying to access DatabaseSer
              antoine Newbie

              I begin with authentication
              I don't know if it's good because of my problem (I give allpermission but nothing) but in auth.conf i don't put dsjndi
              try without and tell me what it does


              my auth.conf :
              MyLogin
              {
              //Login Module Needed - I use Database (Note it correlates to what I had in login-config.xml
              org.jboss.security.auth.spi.DatabaseServerLoginModule required;
              };
              //NOT 100% SURE IF THIS IS NEEDED, SINCE I HAVEN'T DONE THIS IN A WHILE AND I FORGET,
              //BUT IT'S IN MY FILE (Although I think it's not needed)
              other
              {
              //DEFAULT CLIENT-LOGIN MODULE
              org.jboss.security.ClientLoginModule required;
              };

              • 4. Re: Datasource not binding when trying to access DatabaseSer
                sanjuthomas Newbie

                you are right so far about the auth.conf , now see in your client you are creating the LoginContext like this
                UsernamePasswordHandler handler = new UsernamePasswordHandler(args[0], args[1].toCharArray());

                LoginContext lc = new LoginContext("MyLogin", handler);
                lc.login();

                try it out , i am also not sure, me too a beginner.
                best of luck

                • 5. Re: Datasource not binding when trying to access DatabaseSer
                  antoine Newbie

                  I try but nothing

                  can you give me your command line with arguments to compare with me ?

                  thanks

                  • 6. Re: Datasource not binding when trying to access DatabaseSer
                    antoine Newbie

                    excuse me for my advice that wasn't very good

                    I succeed to silve my problem and I ah the same problem that you

                    javax.security.auth.login.LoginException: javax.naming.NameNotFoundException: FwkDS not bound

                    Fwkds is my mysql datasource.

                    I add in my auth.conf my dsjndiname but noting hapened

                    org.jboss.security.auth.spi.DatabaseServerLoginModule required dsJndiName="java:/FwkDS";

                    did you succeed to siolve your problem ?

                    thanks for your help