public static String getUserName ( ) throws Exception { Subject subject = getRunAsSubjectInternal ( ) ; if ( subject == null ) { return null ; } Set < Principal > principals = subject . getPrincipals ( ) ; Iterator < Principal > principalsIterator = principals . iterator ( ) ; if ( principalsIterator . hasNext ( ) ) { Principal principal = principalsIterator . next ( ) ; return principal . getName ( ) ; } return null ; }
Gets the username from the principal of the subject .