Dear Wiki user, You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for change notification.
The following page has been changed by ErikVullings: http://wiki.apache.org/tapestry/AcegiSpringJava5Part2 ------------------------------------------------------------------------------ import org.acegisecurity.Authentication; import org.acegisecurity.context.SecurityContextHolder; - import org.acegisecurity.userdetails.UserDetails; public abstract class UserPage extends org.apache.tapestry.html.BasePage { + public String getUserName() { - String userName = null; + // getContext() will never return null so we do not have to check that. + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + if( auth != null ) { + return auth.getName(); + } + return ""; + } - if( SecurityContextHolder.getContext() != null ) { - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - if( auth != null ) { - Object principal = auth.getPrincipal(); - if( principal != null ) { - if( principal instanceof UserDetails ) { - userName = ((UserDetails)principal).getUsername(); - } else { - userName = principal.toString(); - } - } - } - } - - if( userName == null ) { - userName = ""; - } - return userName; - } } }}} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
