code: public static String subjectToString(final Subject subject) {
  
          final String result;
  
          if (subject == null) {
  
              result = "null";
  
          } else {
  
              StringBuffer buffer = new StringBuffer("[");
              buffer.append(subject.getClass().getName());
              buffer.append("@");
              buffer
                              .append(Integer.toHexString(System
                                              .identityHashCode(subject)));
              buffer.append(" <principals=");
              buffer.append(subject.getPrincipals());
              buffer.append(">]");
              result = buffer.toString();
  
          }
  
          return result;
  
      }
docs: Converts a subject to a printable form taking care not access the private
  credentials which requires additional permissions.
  
  @param subject
  the subject (may be <code>null</code>)
  @return a printable from