code: public static String getUserNameFromSubject(Subject subject) {
          Iterator<Principal> it = subject.getPrincipals().iterator();
          String username = it.next().getName();
          return username;
      }
docs: The sujbect has to be non-null