code: public static Subject getSubject(UserGroupInformation ugi) {
      if (ugi == null) {
        return null;
      }
      
      Set<Principal> principals =       // Number of principals = username + #groups 
        new HashSet<Principal>(ugi.getGroupNames().length+1);
      User userPrincipal = new User(ugi.getUserName()); 
      principals.add(userPrincipal);
      for (String group : ugi.getGroupNames()) {
        Group groupPrincipal = new Group(group);
        principals.add(groupPrincipal);
      }
      principals.add(ugi);
      Subject user = 
        new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
      
      return user;
    }
docs: Get the {@link Subject} for the user identified by <code>ugi</code>.
  @param ugi user
  @return the {@link Subject} for the user identified by <code>ugi</code>