Kaynağa Gözat

FilterSecurityInterceptor now has an observeOncePerRequest boolean property, allowing multiple fragments of the HTTP request to be individually authorized (see http://opensource.atlassian.com/projects/spring/browse/SEC-14).

Ben Alex 20 yıl önce
ebeveyn
işleme
3e4a29eae9

+ 26 - 2
core/src/main/java/org/acegisecurity/intercept/web/FilterSecurityInterceptor.java

@@ -51,6 +51,7 @@ public class FilterSecurityInterceptor extends AbstractSecurityInterceptor {
     //~ Instance fields ========================================================
 
     private FilterInvocationDefinitionSource objectDefinitionSource;
+    private boolean observeOncePerRequest = true;
 
     //~ Methods ================================================================
 
@@ -63,14 +64,37 @@ public class FilterSecurityInterceptor extends AbstractSecurityInterceptor {
         return this.objectDefinitionSource;
     }
 
+    public void setObserveOncePerRequest(boolean observeOncePerRequest) {
+        this.observeOncePerRequest = observeOncePerRequest;
+    }
+
+    /**
+     * Indicates whether once-per-request handling will be observed. By default
+     * this is <code>true</code>, meaning the
+     * <code>FilterSecurityInterceptor</code> will only execute
+     * once-per-request. Sometimes users may wish it to execute more than once
+     * per request, such as when JSP forwards are being used and filter
+     * security is desired on each included fragment of the HTTP request.
+     *
+     * @return <code>true</code> (the default) if once-per-request is honoured,
+     *         otherwise <code>false</code> if
+     *         <code>FilterSecurityInterceptor</code> will enforce
+     *         authorizations for each and every fragment of the HTTP request.
+     */
+    public boolean isObserveOncePerRequest() {
+        return observeOncePerRequest;
+    }
+
     public Class getSecureObjectClass() {
         return FilterInvocation.class;
     }
 
     public void invoke(FilterInvocation fi) throws Throwable {
         if ((fi.getRequest() != null)
-            && (fi.getRequest().getAttribute(FILTER_APPLIED) != null)) {
-            // filter already applied to this request, so don't re-do security checking
+            && (fi.getRequest().getAttribute(FILTER_APPLIED) != null)
+            && observeOncePerRequest) {
+            // filter already applied to this request and user wants us to observce
+            // once-per-request handling, so don't re-do security checking
             fi.getChain().doFilter(fi.getRequest(), fi.getResponse());
         } else {
             // first time this request being called, so perform security checking

+ 1 - 0
doc/xdocs/changes.xml

@@ -44,6 +44,7 @@
       <action dev="benalex" type="fix">JBoss container adapter to use getName() instead to toString() (see http://opensource.atlassian.com/projects/spring/browse/SEC-22)</action>
       <action dev="benalex" type="fix">HttpSessionContextIntegrationFilter elegantly handles IOExceptions and ServletExceptions within filter chain (see http://opensource.atlassian.com/projects/spring/browse/SEC-20)</action>
       <action dev="benalex" type="update">Form, CAS, X509 and Remember-Me authentication mechanisms now publish an InteractiveAuthenticationSuccessEvent (see http://opensource.atlassian.com/projects/spring/browse/SEC-5)</action>
+      <action dev="benalex" type="update">FilterSecurityInterceptor now has an observeOncePerRequest boolean property, allowing multiple fragments of the HTTP request to be individually authorized (see http://opensource.atlassian.com/projects/spring/browse/SEC-14)</action>
     </release>
     <release version="0.8.2" date="2005-04-20">
       <action dev="benalex" type="fix">Correct location of AuthenticationSimpleHttpInvokerRequestExecutor in clientContext.xml</action>