1 Reply Latest reply on Sep 10, 2010 6:45 AM by carln9

    JNDI lookup failure in Custom Login Module

    sahidkhn

      Hello,

      I am trying to implement a custom login module by extending the DatabaseServerLoginModule. Here I am overriding only getRoleSets(). Inside login-conf.xml I have given the jndi name for the datasource. But when I try to do the lookup in my LoginModule module class, it returns null.

      Here are the releven code snippets

      mysql-ds.xml:

      <datasources>
       <local-tx-datasource>
       <jndi-name>Appscale</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/?jdbcCompliantTruncation=false</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
      [...]
       </local-tx-datasource>
      
      </datasources>
      


      login-conf.xml:
       <application-policy name="drools">
       <authentication>
       <login-module code = "in.tibs.security.auth.DroolsLoginModule"
       flag = "required">
       <module-option name = "dsJndiName">java:/Appscale</module-option>
       </login-module>
       </authentication>
       </application-policy>
      


      DroolsLoginModule.java:
       InitialContext ctx = new InitialContext();
       DataSource ds = (DataSource) ctx.lookup(dsJndiName); //lookup is returning null here
      


      Am I doing anything wrong here? Please help.

      Thanks,
      Sahid

        • 1. Re: JNDI lookup failure in Custom Login Module
          carln9

          Hi Sahid

           

          I know this post is a couple of years old, but I am having the same problem. Did you ever find a solution?

           

          I know my datasource is ok, as I created a new war deployedment and the following jsp client worked.

           

          <%@page contentType="text/html"
          import="java.util.*,javax.naming.*,javax.sql.DataSource,java.sql.*"
          %>
          <%

           

            DataSource ds = null;
            Connection con = null;
            PreparedStatement pr = null;
            InitialContext ic;
            try {
            ic = new InitialContext();
            ds = (DataSource)ic.lookup( "java:/OracleDB" );
            con = ds.getConnection();
            pr = con.prepareStatement("SELECT TO_CHAR (SYSDATE, 'DD-MM-YYYY') AS CUR_DATE FROM DUAL");
            ResultSet rs = pr.executeQuery();
            while (rs.next()) {
            out.println("<br> " +rs.getString("CUR_DATE"));
            }
            rs.close();
            pr.close();
            }catch(Exception e){
            out.println("Exception thrown " +e);
            }finally{
            if(con != null){
            con.close();
          }
          }
          %>

           

          Cheers

           

          Carl