浏览代码

Patch by Matt Raible which returns null if Authentication is anonymous.

Ben Alex 20 年之前
父节点
当前提交
c5fe428400

+ 13 - 2
core/src/main/java/org/acegisecurity/wrapper/ContextHolderAwareRequestWrapper.java

@@ -16,10 +16,13 @@
 package net.sf.acegisecurity.wrapper;
 
 import net.sf.acegisecurity.Authentication;
+import net.sf.acegisecurity.AuthenticationTrustResolver;
+import net.sf.acegisecurity.AuthenticationTrustResolverImpl;
 import net.sf.acegisecurity.GrantedAuthority;
 import net.sf.acegisecurity.UserDetails;
 import net.sf.acegisecurity.context.ContextHolder;
 import net.sf.acegisecurity.context.security.SecureContext;
+import net.sf.acegisecurity.context.security.SecureContextUtils;
 
 import java.security.Principal;
 
@@ -39,6 +42,10 @@ import javax.servlet.http.HttpServletRequestWrapper;
  * @version $Id$
  */
 public class ContextHolderAwareRequestWrapper extends HttpServletRequestWrapper {
+    //~ Instance fields ========================================================
+
+    private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl();
+
     //~ Constructors ===========================================================
 
     public ContextHolderAwareRequestWrapper(HttpServletRequest request) {
@@ -109,8 +116,12 @@ public class ContextHolderAwareRequestWrapper extends HttpServletRequestWrapper
     private Authentication getAuthentication() {
         if ((ContextHolder.getContext() != null)
             && ContextHolder.getContext() instanceof SecureContext) {
-            return ((SecureContext) ContextHolder.getContext())
-            .getAuthentication();
+            Authentication auth = SecureContextUtils.getSecureContext()
+                                                    .getAuthentication();
+
+            if (!authenticationTrustResolver.isAnonymous(auth)) {
+                return auth;
+            }
         }
 
         return null;

+ 1 - 0
doc/xdocs/changes.xml

@@ -27,6 +27,7 @@
   <body>
     <release version="0.8.1" date="In CVS">
       <action dev="benalex" type="fix">SecurityEnforcementFilter caused NullPointerException when anonymous authentication used with BasicProcessingFilterEntryPoint</action>
+      <action dev="benalex" type="update">ContextHolderAwareRequestWrapper methods returns null if user is anonymous</action>
     </release>
     <release version="0.8.0" date="2005-03-03">
       <action dev="benalex" type="add">Added Digest Authentication support (RFC 2617 and RFC 2069)</action>