Seth Ladd wrote:
Hello,
I'd like to propose we add getUserPrincipal to
ContextHolderAwareRequestWrapper. We can return the Authentication,
which itself is a Principal.
The Simple patch for this has been attached.
Thanks!
Seth
--
<a href="http://www.picklematrix.net/foaf.rdf">Seth Ladd's FOAF</a>
<a href="http://www.foaf-project.org/">What is FOAF?</a>
Index: ContextHolderAwareRequestWrapper.java
===================================================================
RCS file:
/cvsroot/acegisecurity/acegisecurity/core/src/main/java/net/sf/acegisecurity/ui/wrapper/ContextHolderAwareRequestWrapper.java,v
retrieving revision 1.1
diff -u -r1.1 ContextHolderAwareRequestWrapper.java
--- ContextHolderAwareRequestWrapper.java 5 Dec 2004 06:10:30 -0000
1.1
+++ ContextHolderAwareRequestWrapper.java 4 Feb 2005 18:34:22 -0000
@@ -15,6 +15,8 @@
package net.sf.acegisecurity.ui.wrapper;
+import java.security.Principal;
+
import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.GrantedAuthority;
import net.sf.acegisecurity.UserDetails;
@@ -37,6 +39,7 @@
* @version $Id: ContextHolderAwareRequestWrapper.java,v 1.1 2004/12/05
06:10:30 benalex Exp $
*/
public class ContextHolderAwareRequestWrapper extends
HttpServletRequestWrapper {
+
//~ Constructors
===========================================================
public ContextHolderAwareRequestWrapper(HttpServletRequest request) {
@@ -46,6 +49,24 @@
//~ Methods
================================================================
/**
+ * Returns the current <code>Authentication</code> as it is a
+ * <code>Principal</code>.
+ *
+ * @return the current <code>Authentication</code>, or <code>null</code>
+ * if none available
+ * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
+ */
+ public Principal getUserPrincipal() {
+ Authentication auth = getAuthentication();
+
+ if (auth == null) {
+ return null;
+ }
+
+ return auth;
+ }
+
+ /**
* Returns the principal's name, as obtained from the
* <code>ContextHolder</code>. Properly handles both
* <code>String</code>-based and <code>UserDetails</code>-based