1 Reply Latest reply on Jun 1, 2012 11:41 AM by raneves

    get object, java.security.Principal, in the persistence layer

    raneves

      People,

       

       

      does anyone know how I do to get the Principal object in the persistence layer?

      happens that my application can not depend on request.getUserPrincipal coming fromservlet api.

      need to somehow retrieve the security context and then get the authenticated user.

      I tried to do the following:


      1. AccessControlContext  accessControlContext = AccessController.getContext();   
      2. Subject subject = Subject.getSubject(accessControlContext);   
      3. for( Principal principal: subject.getPrincipals() ){   
      4.     System.out.println("this is a principal: " + principal.getName());   
      5. }  

      but, getSubject is returning a null object.

      any suggestions?