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