1 Reply Latest reply on Jul 15, 2004 2:47 PM by Alec Lanter

    Retrieve Username after authentication

    Vincenzo Sorrentino Newbie

      Dear All,

      JBoss 3.2.5 work differently that 3.2.3 version becouse when authenticate (I use DatabaseServerLoginModule) the principal name doesn't contain a username but the role name

      How Can I obtain the username authenticate from HTTP request

      I used:

      Principal p = request.getUserPrincipal();


      My software doesn't work fine becouse in 3.2.5 getName() return the role's name and not the login/username


        • 1. Re: Retrieve Username after authentication
          Alec Lanter Newbie

          Hi there.

          I'm afraid I don't have terribly useful information, but I did want to let you know that in some instances, Principal.getName() does indeed return the username. I'm using a custom written database login module, and after returning from authentication, I can perform the following to locate the username (jsm is the variable name for a JaasSecurityManager looked up via JNDI using the JNDI name of the security realm my web app is using):

           Subject s = jsm.getActiveSubject();
           Set pr = s.getPrincipals();
           Iterator i = pr.iterator();
           while (i.hasNext())
           Principal p = (Principal)i.next();
           out.println("<h3>Principal: " + p.getName() + "</h3>");

          This block iterates through all principals in the current user, and displays their name. The first principal entry comes back as the username used to log in, while the second entry comes back as "Roles". I'm not sure where that second one comes from, but I'm still rather new to JAAS, so it doesn't surprise me when weird things happen. ;)

          Hope that helps a little. Maybe it will at least point you in a new direction to look.

          -- Alec