View Javadoc

1   /*
2    * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.xml.security.x509;
18  
19  import java.util.ArrayList;
20  import java.util.HashSet;
21  import java.util.List;
22  import java.util.Set;
23  
24  import org.opensaml.xml.security.CriteriaSet;
25  import org.opensaml.xml.security.SecurityException;
26  
27  /**
28   * An implementation of {@link PKIXValidationInformationResolver} which always returns a 
29   * static, fixed set of information.
30   */
31  public class StaticPKIXValidationInformationResolver implements PKIXValidationInformationResolver {
32      
33      /** The PKIX validation information to return. */
34      private List<PKIXValidationInformation> pkixInfo;
35      
36      /** The set of trusted names to return. */
37      private Set<String> trustedNames;
38      
39      /**
40       * Constructor.
41       *
42       * @param info list of PKIX validation information to return
43       * @param names set of trusted names to return
44       */
45      public StaticPKIXValidationInformationResolver(List<PKIXValidationInformation> info, Set<String> names) {
46          pkixInfo = new ArrayList<PKIXValidationInformation>();
47          pkixInfo.addAll(info);
48          
49          trustedNames = new HashSet<String>();
50          trustedNames.addAll(names);
51      }
52  
53      /** {@inheritDoc} */
54      public Set<String> resolveTrustedNames(CriteriaSet criteriaSet) throws SecurityException,
55              UnsupportedOperationException {
56          
57          return trustedNames;
58      }
59  
60      /** {@inheritDoc} */
61      public boolean supportsTrustedNameResolution() {
62          return true;
63      }
64  
65      /** {@inheritDoc} */
66      public Iterable<PKIXValidationInformation> resolve(CriteriaSet criteria) throws SecurityException {
67          return pkixInfo;
68      }
69  
70      /** {@inheritDoc} */
71      public PKIXValidationInformation resolveSingle(CriteriaSet criteria) throws SecurityException {
72          if (! pkixInfo.isEmpty()) {
73              return pkixInfo.get(0);
74          }
75          return null;
76      }
77  
78  }