24
24
import org .apache .shiro .util .Nameable ;
25
25
import org .apache .shiro .util .StringUtils ;
26
26
import org .apache .shiro .web .config .IniFilterChainResolverFactory ;
27
+ import org .apache .shiro .web .config .ShiroFilterConfiguration ;
27
28
import org .apache .shiro .web .filter .AccessControlFilter ;
28
29
import org .apache .shiro .web .filter .InvalidRequestFilter ;
29
30
import org .apache .shiro .web .filter .authc .AuthenticationFilter ;
35
36
import org .apache .shiro .web .filter .mgt .PathMatchingFilterChainResolver ;
36
37
import org .apache .shiro .web .mgt .WebSecurityManager ;
37
38
import org .apache .shiro .web .servlet .AbstractShiroFilter ;
39
+ import org .apache .shiro .web .servlet .OncePerRequestFilter ;
38
40
import org .slf4j .Logger ;
39
41
import org .slf4j .LoggerFactory ;
40
42
import org .springframework .beans .BeansException ;
@@ -135,15 +137,18 @@ public class ShiroFilterFactoryBean implements FactoryBean<AbstractShiroFilter>,
135
137
136
138
private AbstractShiroFilter instance ;
137
139
140
+ private ShiroFilterConfiguration filterConfiguration ;
141
+
138
142
public ShiroFilterFactoryBean () {
139
143
this .filters = new LinkedHashMap <String , Filter >();
140
144
this .globalFilters = new ArrayList <>();
141
145
this .globalFilters .add (DefaultFilter .invalidRequest .name ());
142
146
this .filterChainDefinitionMap = new LinkedHashMap <String , String >(); //order matters!
147
+ this .filterConfiguration = new ShiroFilterConfiguration ();
143
148
}
144
149
145
150
/**
146
- * Sets the application {@code SecurityManager} instance to be used by the constructed Shiro Filter. This is a
151
+ * Gets the application {@code SecurityManager} instance to be used by the constructed Shiro Filter. This is a
147
152
* required property - failure to set it will throw an initialization exception.
148
153
*
149
154
* @return the application {@code SecurityManager} instance to be used by the constructed Shiro Filter.
@@ -162,6 +167,24 @@ public void setSecurityManager(SecurityManager securityManager) {
162
167
this .securityManager = securityManager ;
163
168
}
164
169
170
+ /**
171
+ * Gets the application {@code ShiroFilterConfiguration} instance to be used by the constructed Shiro Filter.
172
+ *
173
+ * @return the application {@code ShiroFilterConfiguration} instance to be used by the constructed Shiro Filter.
174
+ */
175
+ public ShiroFilterConfiguration getShiroFilterConfiguration () {
176
+ return filterConfiguration ;
177
+ }
178
+
179
+ /**
180
+ * Sets the application {@code ShiroFilterConfiguration} instance to be used by the constructed Shiro Filter.
181
+ *
182
+ * @param filterConfiguration the application {@code SecurityManager} instance to be used by the constructed Shiro Filter.
183
+ */
184
+ public void setShiroFilterConfiguration (ShiroFilterConfiguration filterConfiguration ) {
185
+ this .filterConfiguration = filterConfiguration ;
186
+ }
187
+
165
188
/**
166
189
* Returns the application's login URL to be assigned to all acquired Filters that subclass
167
190
* {@link AccessControlFilter} or {@code null} if no value should be assigned globally. The default value
@@ -468,7 +491,7 @@ protected AbstractShiroFilter createInstance() throws Exception {
468
491
//FilterChainResolver. It doesn't matter that the instance is an anonymous inner class
469
492
//here - we're just using it because it is a concrete AbstractShiroFilter instance that accepts
470
493
//injection of the SecurityManager and FilterChainResolver:
471
- return new SpringShiroFilter ((WebSecurityManager ) securityManager , chainResolver );
494
+ return new SpringShiroFilter ((WebSecurityManager ) securityManager , chainResolver , getShiroFilterConfiguration () );
472
495
}
473
496
474
497
private void applyLoginUrlIfNecessary (Filter filter ) {
@@ -511,6 +534,10 @@ private void applyGlobalPropertiesIfNecessary(Filter filter) {
511
534
applyLoginUrlIfNecessary (filter );
512
535
applySuccessUrlIfNecessary (filter );
513
536
applyUnauthorizedUrlIfNecessary (filter );
537
+
538
+ if (filter instanceof OncePerRequestFilter ) {
539
+ ((OncePerRequestFilter ) filter ).setFilterOncePerRequest (filterConfiguration .isFilterOncePerRequest ());
540
+ }
514
541
}
515
542
516
543
/**
@@ -549,12 +576,13 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
549
576
*/
550
577
private static final class SpringShiroFilter extends AbstractShiroFilter {
551
578
552
- protected SpringShiroFilter (WebSecurityManager webSecurityManager , FilterChainResolver resolver ) {
579
+ protected SpringShiroFilter (WebSecurityManager webSecurityManager , FilterChainResolver resolver , ShiroFilterConfiguration filterConfiguration ) {
553
580
super ();
554
581
if (webSecurityManager == null ) {
555
582
throw new IllegalArgumentException ("WebSecurityManager property cannot be null." );
556
583
}
557
584
setSecurityManager (webSecurityManager );
585
+ setShiroFilterConfiguration (filterConfiguration );
558
586
559
587
if (resolver != null ) {
560
588
setFilterChainResolver (resolver );
0 commit comments