1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.shiro.guice.web; |
20 | |
|
21 | |
import com.google.common.collect.ImmutableSet; |
22 | |
import com.google.inject.Inject; |
23 | |
import com.google.inject.Injector; |
24 | |
import com.google.inject.Key; |
25 | |
import com.google.inject.Singleton; |
26 | |
import com.google.inject.spi.Dependency; |
27 | |
import com.google.inject.spi.ProviderWithDependencies; |
28 | |
import org.apache.shiro.util.AntPathMatcher; |
29 | |
import org.apache.shiro.util.PatternMatcher; |
30 | |
import org.apache.shiro.web.filter.mgt.FilterChainResolver; |
31 | |
|
32 | |
import javax.servlet.Filter; |
33 | |
import java.util.Map; |
34 | |
import java.util.Set; |
35 | |
|
36 | 11 | @Singleton |
37 | |
class FilterChainResolverProvider implements ProviderWithDependencies<FilterChainResolver> { |
38 | |
@Inject |
39 | |
Injector injector; |
40 | |
|
41 | |
private final Map<String, Key<? extends Filter>[]> chains; |
42 | |
|
43 | |
private final Set<Dependency<?>> dependencies; |
44 | |
|
45 | 7 | private PatternMatcher patternMatcher = new AntPathMatcher(); |
46 | |
|
47 | 7 | public FilterChainResolverProvider(Map<String, Key<? extends Filter>[]> chains) { |
48 | 7 | this.chains = chains; |
49 | 7 | ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder(); |
50 | 7 | for (String chain : chains.keySet()) { |
51 | 20 | for (Key<? extends Filter> filterKey : chains.get(chain)) { |
52 | 12 | dependenciesBuilder.add(Dependency.get(filterKey)); |
53 | |
} |
54 | |
} |
55 | 7 | this.dependencies = dependenciesBuilder.build(); |
56 | 7 | } |
57 | |
|
58 | |
@Inject(optional = true) |
59 | |
public void setPatternMatcher(PatternMatcher patternMatcher) { |
60 | 1 | this.patternMatcher = patternMatcher; |
61 | 1 | } |
62 | |
|
63 | |
public Set<Dependency<?>> getDependencies() { |
64 | 1 | return dependencies; |
65 | |
} |
66 | |
|
67 | |
public FilterChainResolver get() { |
68 | 12 | return new SimpleFilterChainResolver(chains, injector, patternMatcher); |
69 | |
} |
70 | |
|
71 | |
} |