1 Reply Latest reply on May 29, 2003 2:24 PM by Fabrizio Giudici

    Changing the name of a Principal

    Fabrizio Giudici Newbie

      Hi guys. My problem is: I want to customize my Principal so that it does not hold the "username", but another value.

      To explain better, I have a LOGIN table that contains the values USERNAME, PASSWORD, ID, e.g. "johnsmith", "password", 45. If a user logs in as johnsmith/password, I want its Principal to be bound to 45 and not to johnsmith.

      Note that this is a different topic than "adding" more information to the Principal.

      Anyway I thought it was pretty simple, just subclass DatabaseServerLoginModule, override the getIdentity() method et voila'. But it does not work :-( It just always says that the login is wrong.

      So I tried to patch the "javax.security.auth.login.name" property in the sharedContext parameter of the init() method (making a clone). Does not work.

      Even tried to directly change the sharedContext (knowing that is probably a hard move :-) but no luck.

      What's wrong? I'm starting to think that the *LoginModule is not the right place to make the change.

        • 1. Re: Changing the name of a Principal
          Fabrizio Giudici Newbie

          Puzzled and frustrated :-(

          I managed in changing the principal by overriding the method getUsernameAndPassword().

          protected String[] getUsernameAndPassword()
          throws LoginException
          {
          String[] s = super.getUsernameAndPassword();
          s[0] = getChangedPrincipalName(s[0]);

          return s;
          }

          It *seemed* to work because the getIdentity() method now returns what I want.

          protected Principal getIdentity()
          {
          Principal p = super.getIdentity();
          log.info("********* " + p);

          return p;
          }

          But both in servlets and ejbs the Principal is still "johnsmith". What am I doing wrong? :(