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.List;
21
22 import org.opensaml.xml.security.CriteriaSet;
23 import org.opensaml.xml.security.SecurityException;
24
25 /**
26 * Simple implementation of {@link CredentialResolver} which just stores and returns a static set of credentials.
27 *
28 * <p>
29 * Note: no filtering or other evaluation of the credentials is performed. Any Criteria
30 * specified are ignored. For a similar Collection-based CredentialResolver implementation which does support
31 * evaluation and filtering based on supplied evaluable criteria, see {@link CollectionCredentialResolver}.
32 * </p>
33 */
34 public class StaticCredentialResolver extends AbstractCredentialResolver {
35
36 /** List of credentials held by this resolver. */
37 private List<Credential> creds;
38
39 /**
40 * Constructor.
41 *
42 * @param credentials collection of credentials to be held by this resolver
43 */
44 public StaticCredentialResolver(List<Credential> credentials) {
45 creds = new ArrayList<Credential>();
46 creds.addAll(credentials);
47 }
48
49 /**
50 * Constructor.
51 *
52 * @param credential a single credential to be held by this resolver
53 */
54 public StaticCredentialResolver(Credential credential) {
55 creds = new ArrayList<Credential>();
56 creds.add(credential);
57 }
58
59 /** {@inheritDoc} */
60 public Iterable<Credential> resolve(CriteriaSet criteria) throws SecurityException {
61 return creds;
62 }
63
64 }