Coverage Report - org.apache.shiro.guice.web.FilterChainResolverProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
FilterChainResolverProvider
100%
15/15
100%
4/4
1.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 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  22
 @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  14
     private PatternMatcher patternMatcher = new AntPathMatcher();
 49  
 
 50  14
     public FilterChainResolverProvider(Map<String, Key<? extends Filter>[]> chains) {
 51  14
         this.chains = chains;
 52  14
         Set<Dependency<?>> dependenciesBuilder = new HashSet<Dependency<?>>();
 53  14
         for (String chain : chains.keySet()) {
 54  40
             for (Key<? extends Filter> filterKey : chains.get(chain)) {
 55  24
                 dependenciesBuilder.add(Dependency.get(filterKey));
 56  
             }
 57  16
         }
 58  14
         this.dependencies = Collections.unmodifiableSet(dependenciesBuilder);
 59  14
     }
 60  
 
 61  
     @Inject(optional = true)
 62  
     public void setPatternMatcher(PatternMatcher patternMatcher) {
 63  2
         this.patternMatcher = patternMatcher;
 64  2
     }
 65  
 
 66  
     public Set<Dependency<?>> getDependencies() {
 67  2
         return dependencies;
 68  
     }
 69  
 
 70  
     public FilterChainResolver get() {
 71  24
         return new SimpleFilterChainResolver(chains, injector, patternMatcher);
 72  
     }
 73  
 
 74  
 }