0 Replies Latest reply on May 22, 2002 3:17 AM by francesco milesi

    DatabaseServerloginModule question

    francesco milesi Newbie

      Hi everybody,

      I have a mssql database with users and password and I want to authenticate them against it
      with JBoss 3.0.

      This is what I did:

      1. I defined a dataSource with mssql-service.xml, in particular I uncommented the lines relative
      to username and password, because I understand that that way all accesses to my database are
      authenticated with that username and password.



      <config-property name="ConnectionURL" type="java.lang.String">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=SISTest</config-property>
      <config-property name="DriverClass" type="java.lang.String">com.microsoft.jdbc.sqlserver.SQLServerDriver</config-property>
      <!--set these only if you want only default logins, not through JAAS-->
      <config-property name="UserName" type="java.lang.String">SISTest</config-property>
      <config-property name="Password" type="java.lang.String">SISTest</config-property>
      <!---->




      2. I put the following entry in the login-config.xml (I think it should define a security realm
      named SISDomain). This realm uses the data source defined at point 1. to authenticate users.

      <!-- Security domain for SISApplication -->
      <application-policy name = "SISDomain">

      <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"
      flag = "required">
      <module-option name = "dsJndiName">java:/MSSQLDS</module-option>
      <module-option name = "principalsQuery">SELECT Password FROM RisorseUmane WHERE UserName=?</module-option>
      <module-option name = "rolesQuery">SELECT Gruppo FROM RisorseUmane WHERE UserName=?</module-option>
      <module-option name = "unauthenticatedIdentity">guest</module-option>
      </login-module>

      </application-policy>



      3. I wrote the following client code (it is only an attempt to understand how things work):

      public class Client implements Serializable {
      static class AppCallbackHandler implements CallbackHandler
      {
      private String username;
      private char[] password;

      public AppCallbackHandler(String username, char[] password)
      {
      this.username = username;
      this.password = password;
      }

      public void handle(Callback[] callbacks) throws
      java.io.IOException, UnsupportedCallbackException
      {
      for (int i = 0; i < callbacks.length; i++)
      {
      if (callbacks instanceof NameCallback)
      {
      NameCallback nc = (NameCallback)callbacks
      ;
      nc.setName(username);
      }
      else if (callbacks instanceof PasswordCallback)
      {
      PasswordCallback pc = (PasswordCallback)callbacks
      ;
      pc.setPassword(password);
      }
      else
      {
      throw new UnsupportedCallbackException(callbacks, "Unrecognized Callback");
      }
      }
      }
      }

      public Client() {
      }

      public String whoIsHe(){
      try{
      CallbackHandler handler = new AppCallbackHandler("betta", "xxx".toCharArray());
      LoginContext lc = new LoginContext("SISDomain", handler);
      lc.login();
      java.util.Properties props = new java.util.Properties();
      props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      props.put("java.naming.provider.url", "localhost:1099");
      props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
      Context ctx = new InitialContext(props);
      Object o = ctx.lookup("proveJBoss30");
      proveJBoss30Home h = (proveJBoss30Home) PortableRemoteObject.narrow(o, proveJBoss30Home.class);
      proveJBoss30Remote r = h.create();
      return r.theCallerIs();
      }
      catch(Exception e){
      e.printStackTrace();
      }
      return null;
      }

      public static void main(String[] args) {
      Client client1 = new Client();
      System.out.println("The caller is ........ " + client1.whoIsHe());
      }
      }


      Here are the question:
      1. What I did at point 1. and 2. is correct ?
      2. I think the line LoginContext lc = new LoginContext("SISDomain.txt", handler);
      expects a configuration file, but I have no idea of what I should put into it and how should I
      named it. I point out that I launched the client passing it the parameter
      -Djava.security.auth.login.config=SecConfig,
      but I do not understand what I should put into this file.


      Thanks in advance,
      Ciao Francesco