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.credential;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  
22  import org.opensaml.xml.security.CriteriaSet;
23  import org.opensaml.xml.security.SecurityException;
24  import org.opensaml.xml.security.credential.criteria.EvaluableCredentialCriteria;
25  import org.opensaml.xml.security.credential.criteria.EvaluableCredentialCriteriaRegistry;
26  
27  /**
28   * An implementation of {@link CredentialResolver} which uses a {@link Collection} as the
29   * underlying credential source.
30   * 
31   * <p>
32   * The credentials returned are filtered based on any
33   * {@link EvaluableCredentialCriteria} which may have been present in the specified criteria set, or
34   * which are resolved by lookup in the {@link EvaluableCredentialCriteriaRegistry}.
35   * </p>
36   */
37  public class CollectionCredentialResolver extends AbstractCriteriaFilteringCredentialResolver {
38      
39      /** The collection of credentials which is the underlying store for the resolver. */
40      private Collection<Credential> collection;
41      
42      /**
43       * Constructor.
44       * 
45       * An {@link ArrayList} is used as the underlying collection implementation.
46       *
47       */
48      public CollectionCredentialResolver() {
49          super();
50          collection = new ArrayList<Credential>();
51      }
52      
53      /**
54       * Constructor.
55       *
56       * @param credentials the credential collection which is the backing store for the resolver
57       */
58      public CollectionCredentialResolver(Collection<Credential> credentials) {
59          super();
60          collection = credentials;
61      }
62      
63      /**
64       * Get the (modifiable) credential collection which is the backing store for the resolver.
65       * 
66       * @return the credential collection backing store
67       */
68      public Collection<Credential> getCollection() {
69          return collection;
70      }
71  
72      /** {@inheritDoc} */
73      protected Iterable<Credential> resolveFromSource(CriteriaSet criteriaSet) throws SecurityException {
74          return collection;
75      }
76  
77  }