2 Replies Latest reply on Jun 21, 2006 10:27 AM by Andy W. Clements

    receiving null for j_username when using FormAuthValue

    Andy W. Clements Newbie

      Hello Forum Folks,

      I'm trying to retrieve the j_username value from the session after a user SUCCESSFULLY logs in. I have the form authenticator setup and the user is able to log in correctly, however, I am getting null for the j_username value. I'm probably missing some small detail somewhere.

      in the context.xml of the applicaiton, I have the following:

       <Valve className="org.apache.catalina.authenticator.FormAuthenticator" disableProxyCaching="false" />
       <Valve className="org.jboss.web.tomcat.security.FormAuthValve" includePassword="false" />

      I'm able to see the FormAuthValue listed in the valveObjectNames under the JMX Mbean View - so I know it is being loaded. Also, I'm getting feedback in the logs from it's behavior. Here is a snippet from the logs:

      2006-06-20 17:17:20,669 DEBUG [org.apache.catalina.realm.RealmBase] Username 12345678 has role subcontractor
      2006-06-20 17:17:20,669 TRACE [org.jboss.web.tomcat.security.JBossSecurityMgrRealm] No role found: subcontractor
      2006-06-20 17:17:20,669 DEBUG [org.apache.catalina.authenticator.AuthenticatorBase] Successfully passed all security constraints
      2006-06-20 17:17:20,669 TRACE [org.jboss.web.tomcat.security.FormAuthValve] Enter, j_username=null
      2006-06-20 17:17:20,669 TRACE [org.jboss.web.tomcat.security.SecurityAssociationValve] Begin invoke, callerGenericPrincipal[12345678(subcontractor,)]

      and this as well:
      2006-06-20 17:17:21,407 TRACE [org.jboss.web.tomcat.security.RunAsListener] jsp, runAs: null
      2006-06-20 17:17:21,407 TRACE [org.jboss.web.tomcat.security.RunAsListener] jsp, runAs: null
      2006-06-20 17:17:21,407 TRACE [org.jboss.security.SecurityAssociation] popRunAsIdentity, runAs=null
      2006-06-20 17:17:21,407 TRACE [org.jboss.web.tomcat.security.SecurityAssociationValve] End invoke, callerGenericPrincipal[12345678(subcontractor,)]
      2006-06-20 17:17:21,407 TRACE [org.jboss.web.tomcat.security.FormAuthValve] SessionID: mWGFptpNKjrU1uHatsb47g**
      2006-06-20 17:17:21,407 TRACE [org.jboss.web.tomcat.security.FormAuthValve] SecurityAssociation.exception: null
      2006-06-20 17:17:21,407 TRACE [org.jboss.web.tomcat.security.FormAuthValve] Exit, username: null
      2006-06-20 17:17:21,407 TRACE [org.jboss.security.SecurityAssociation] clear, server=true

      You can see that the j_username is null, for some reason.

      Placing this in the jsp gives me null as well:
       String username = (String) session.getAttribute("j_username");
       <p>Username: <%=username%></p>

      I've read through the wiki that was presented in the FAQ, butI'm not sure what I am missing....

      Any ideas?

      thanks in advance!


        • 1. Re: receiving null for j_username when using FormAuthValue
          chris griffith Expert


          The FormAuthValve and ExtFormAuthenticator were recently replaced by a new version of ExtFormAuthenticator. This work was done per JIRA task http://jira.jboss.com/jira/browse/JBAS-3286, to solve some unexpected behavior. If you can use the newer version, then all will be good. Otherwise, have you tried just calling HttpServletRequest's getUserPrincipal() method?

          Also, one small thing you might want to change. In your context.xml you have added the FormAuthenticator valve. This is not necessary (and may actually be part of the problem) since if you have configured your web app to use FORM authentication (by setting auth-method element in web.xml to "FORM"), that valve is added automatically to pipeline.

          Let us know if you still have problems, cgriffith

          • 2. Re: receiving null for j_username when using FormAuthValue
            Andy W. Clements Newbie

            Thanks cgriffith!

            I'm not too keen on updating all our jboss platforms at the moment so I will try the getUserPrincipal() method... which I should of thought of before.

            Just to let you know, I don't have the FormAuthentictor directive in the context.xml for the authentication, but rather for the disableProxyCaching="false" call. It appears that IE has a problem uploading files if the Proxy Caching is disabled - hence the need for the directive. Hopefully, this isn't interferring with anything else, but I haven't noticed anything odd, til now.

            Thanks again.