How about replacing this if/else with:
getEffectiveUserPrincipal().getName() ?