4 Replies Latest reply on Feb 9, 2005 4:00 PM by Scott Stark

    Problem to add Principal to the Subject

    Boris Novos Newbie

      Hi,
      I am trying to add my own Principal to Subject and extract it on server side on JBoss 3.2.6. For some reason it seems like Subject does not contain it on server. Here is what I am doing:

      On client:

      UsernamePasswordHandler handler = new UsernamePasswordHandler(id, pass.toCharArray());

      Subject subject = new Subject();

      Principal principal = new IpPrincipal("someIpAddress");
      subject.getPrincipals().add(principal);

      LoginContext lc = new LoginContext("client-login", subject, handler);
      lc.login();


      //after that look up bean and call a method?



      I would expect that Subject retrived on server would have IpPrincipal, but apparently it doesn?t.


      Here is IpPrincipal class


      public class IpPrincipal implements java.security.Principal, Serializable {
      private String ip;
      public IpPrincipal(String address) {
      ip = address;
      }

      public String getName() {
      return ip;
      }

      public String toString() {
      return ip;
      }

      }


      On server side to get Subject I do:

      Context environment = (Context)new InitialContext().lookup("java:comp/env");
      org.jnp.interfaces.NamingContext secContext = (org.jnp.interfaces.NamingContext)environment.lookup("security");
      javax.security.auth.Subject subject = (javax.security.auth.Subject)secContext.lookup("subject");

      System.out.println("getPrincipals: " + subject.getPrincipals());


      Here is output:
      15:07:44,524 INFO [STDOUT]:getPrincipals: [boris, Roles(members:everyone)]

      So my IpPrincipal is not propagated to the server.

      Any idea what I am missing ?

      Thanks
      Boris