You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Apache Wiki <wi...@apache.org> on 2007/02/06 18:30:57 UTC
[Tapestry Wiki] Update of "AcegiSpringJava5Part2" by JimRoycroft
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 JimRoycroft:
http://wiki.apache.org/tapestry/AcegiSpringJava5Part2
The comment on the change is:
See "Feedback for the AcegiSpringJava5FormBased wiki page" posting on Tapestry-U
------------------------------------------------------------------------------
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: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org