3 Replies Latest reply on Mar 3, 2004 7:32 PM by cbuckley

    LDAP Login Help

    cbuckley

      The code below I can get to work from a stand alone java application if I take the contents of the ejbCreate() and the createUpstrem... and put it in a main method. However when I try to make the following code execute as a session bean, it won't work. I'm not sure where the break down is. Below it the code I am using. Any help would be much appreciated.


      /*
      * Created on Feb 17, 2004
      *
      */
      package intuinet.session;

      import intuinet.callback.UpstreamCallbackHandler;
      import intuinet.util.LdapLoginProxy;

      import java.rmi.RemoteException;

      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import javax.security.auth.login.LoginContext;
      import javax.security.auth.login.LoginException;



      /**
      * @author cbuckley
      * @ejb.bean description="Stateful LDAP Login Bean"
      * display-name="LdapLoginSession"
      * jndi-name="ejb/intuinet/LdapLoginHomeRemote"
      * name="LdapLoginSession"
      * type="Stateless"
      * view-type="remote"
      *
      * @ejb.env-entry name = "java.security.policy"
      * type = "java.lang.String"
      * value = "jaas.policy"
      *
      * @ejb.env-entry name = "java.security.auth.login.config"
      * type = "java.lang.String"
      * value = "jaas.conf"
      *
      * @ejb.util generate = "physical"
      */
      public class LdapLoginSession implements SessionBean {

      private LdapLoginProxy login;


      /* (non-Javadoc)
      * @see javax.ejb.SessionBean#ejbActivate()
      */
      public void ejbActivate() throws EJBException, RemoteException {
      }

      /**
      *
      * @throws CreateException
      *
      * @ejb.create-method
      */
      public void ejbCreate() throws CreateException{

      String policy = Thread.currentThread().getContextClassLoader().getResource("jaas.policy").toString();
      String conf = Thread.currentThread().getContextClassLoader().getResource("jaas.conf").toString();
      //Setting system variables....
      String sep = System.getProperty("file.separator");
      java.util.Properties p = new java.util.Properties(System.getProperties());
      p.setProperty("java.security.krb5.realm", "upstream.cutthroatcom.com");
      p.setProperty("java.security.krb5.kdc", "madison.upstream.cutthroatcom.com");
      p.setProperty("java.security.policy", policy);
      p.setProperty("java.security.auth.login.config", conf);
      System.setProperties(p);

      }



      /**
      * @ejb.interface-method
      * @param user
      * @param pass
      * @return
      */
      public boolean createUpstreamLogin(String user, String pass){

      LoginContext lc = null;
      boolean valid = false;
      UpstreamCallbackHandler callback = new UpstreamCallbackHandler(user, pass);
      try {
      lc = new LoginContext("JaasIntuinet", callback);
      } catch (LoginException le) {
      System.err.println("Cannot create LoginContext. "
      + le.getMessage());
      } catch (SecurityException se) {
      System.err.println("Cannot create LoginContext. Security Exception"
      + se.getMessage());
      }

      try {
      // attempt authentication
      lc.login();
      valid = true;
      System.out.println("Your logged in");
      } catch (LoginException le) {
      System.err.println("Authentication failed:");
      System.err.println(" " + le.getMessage());
      }

      return valid;
      }



      /* (non-Javadoc)
      * @see javax.ejb.SessionBean#ejbPassivate()
      */
      public void ejbPassivate() throws EJBException, RemoteException {
      }

      /* (non-Javadoc)
      * @see javax.ejb.SessionBean#ejbRemove()
      */
      public void ejbRemove() throws EJBException, RemoteException {
      }



      /* (non-Javadoc)
      * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
      */
      public void setSessionContext(SessionContext arg0)
      throws EJBException, RemoteException {
      }


      }

        • 1. Re: LDAP Login Help
          starksm64

          You cannot set the java.security.auth.login.config system property to pickup a the JAAS config. You have to use the server/xxx/conf/login-config.xml version. See the JAAS howto:
          http://sourceforge.net/docman/display_doc.php?docid=18240&group_id=22866



          • 2. Re: LDAP Login Help
            cbuckley

            Thanks Scott,

            I got this particular problem solved by:

            <application-policy name = "domain-contoller">

            <login-module code="com.sun.security.auth.module.Krb5LoginModule"
            flag = "required" />

            </application-policy>

            Now I am going to work on turning this into a LoginModule, I am kind of stumped by how the CallbackHandler would get invoked bye a BASIC authentication.

            • 3. Re: LDAP Login Help
              cbuckley

               

              "cbuckley" wrote:
              Thanks Scott,

              I got this particular problem solved by:

              <application-policy name = "domain-contoller">
              <authentication>
              <login-module code="com.sun.security.auth.module.Krb5LoginModule"
              flag = "required" />
              </authentication>
              </application-policy>

              Now I am going to work on turning this into a LoginModule, I am kind of stumped by how the CallbackHandler would get invoked by a BASIC authentication.