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 java.util.Collections; |
22 | |
import java.util.HashSet; |
23 | |
import java.util.Map; |
24 | |
import java.util.Set; |
25 | |
|
26 | |
import javax.servlet.Filter; |
27 | |
|
28 | |
import com.google.inject.Inject; |
29 | |
import com.google.inject.Injector; |
30 | |
import com.google.inject.Key; |
31 | |
import com.google.inject.Singleton; |
32 | |
import com.google.inject.spi.Dependency; |
33 | |
import com.google.inject.spi.ProviderWithDependencies; |
34 | |
|
35 | |
import org.apache.shiro.util.AntPathMatcher; |
36 | |
import org.apache.shiro.util.PatternMatcher; |
37 | |
import org.apache.shiro.web.filter.mgt.FilterChainResolver; |
38 | |
|
39 | 11 | @Singleton |
40 | |
class FilterChainResolverProvider implements ProviderWithDependencies<FilterChainResolver> { |
41 | |
@Inject |
42 | |
Injector injector; |
43 | |
|
44 | |
private final Map<String, Key<? extends Filter>[]> chains; |
45 | |
|
46 | |
private final Set<Dependency<?>> dependencies; |
47 | |
|
48 | 7 | private PatternMatcher patternMatcher = new AntPathMatcher(); |
49 | |
|
50 | 7 | public FilterChainResolverProvider(Map<String, Key<? extends Filter>[]> chains) { |
51 | 7 | this.chains = chains; |
52 | 7 | Set<Dependency<?>> dependenciesBuilder = new HashSet<Dependency<?>>(); |
53 | 7 | for (String chain : chains.keySet()) { |
54 | 20 | for (Key<? extends Filter> filterKey : chains.get(chain)) { |
55 | 12 | dependenciesBuilder.add(Dependency.get(filterKey)); |
56 | |
} |
57 | 8 | } |
58 | 7 | this.dependencies = Collections.unmodifiableSet(dependenciesBuilder); |
59 | 7 | } |
60 | |
|
61 | |
@Inject(optional = true) |
62 | |
public void setPatternMatcher(PatternMatcher patternMatcher) { |
63 | 1 | this.patternMatcher = patternMatcher; |
64 | 1 | } |
65 | |
|
66 | |
public Set<Dependency<?>> getDependencies() { |
67 | 1 | return dependencies; |
68 | |
} |
69 | |
|
70 | |
public FilterChainResolver get() { |
71 | 12 | return new SimpleFilterChainResolver(chains, injector, patternMatcher); |
72 | |
} |
73 | |
|
74 | |
} |