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.Collections;
21  import java.util.HashSet;
22  import java.util.List;
23  import java.util.Set;
24  
25  import org.opensaml.xml.security.CriteriaSet;
26  import org.opensaml.xml.security.SecurityException;
27  
28  /**
29   * An implementation of {@link PKIXValidationInformationResolver} which always returns a static, fixed set of
30   * information.
31   */
32  public class StaticPKIXValidationInformationResolver implements PKIXValidationInformationResolver {
33  
34      /** The PKIX validation information to return. */
35      private List<PKIXValidationInformation> pkixInfo;
36  
37      /** The set of trusted names to return. */
38      private Set<String> trustedNames;
39  
40      /**
41       * Constructor.
42       * 
43       * @param info list of PKIX validation information to return
44       * @param names set of trusted names to return
45       */
46      public StaticPKIXValidationInformationResolver(List<PKIXValidationInformation> info, Set<String> names) {
47          if (info != null) {
48              pkixInfo = new ArrayList<PKIXValidationInformation>(info);
49          } else {
50              pkixInfo = Collections.EMPTY_LIST;
51          }
52  
53          if (names != null) {
54              trustedNames = new HashSet<String>(names);
55          } else {
56              trustedNames = Collections.EMPTY_SET;
57          }
58      }
59  
60      /** {@inheritDoc} */
61      public Set<String> resolveTrustedNames(CriteriaSet criteriaSet) throws SecurityException,
62              UnsupportedOperationException {
63  
64          return trustedNames;
65      }
66  
67      /** {@inheritDoc} */
68      public boolean supportsTrustedNameResolution() {
69          return true;
70      }
71  
72      /** {@inheritDoc} */
73      public Iterable<PKIXValidationInformation> resolve(CriteriaSet criteria) throws SecurityException {
74          return pkixInfo;
75      }
76  
77      /** {@inheritDoc} */
78      public PKIXValidationInformation resolveSingle(CriteriaSet criteria) throws SecurityException {
79          if (!pkixInfo.isEmpty()) {
80              return pkixInfo.get(0);
81          }
82          return null;
83      }
84  
85  }