01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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: package org.kuali.rice.security.credentials;
17:
18: import java.util.HashMap;
19: import java.util.List;
20: import java.util.Map;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.kuali.rice.security.credentials.CredentialsSource.CredentialsType;
25: import org.springframework.beans.factory.InitializingBean;
26:
27: /**
28: * CredentialsSourceFactory constructs or returns an existing instance of a
29: * CredentialsSource based on the type of Credentials requested.
30: * <p>
31: * It will return null if it cannot find or create an instance of the required
32: * type.
33: *
34: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
35: * @version $Revision: 1.2.16.1.6.1 $ $Date: 2007/10/17 20:32:06 $
36: * @since 0.9
37: *
38: */
39: public final class CredentialsSourceFactory implements InitializingBean {
40:
41: private final Log log = LogFactory.getLog(this .getClass());
42:
43: private List<CredentialsSource> credentialsSources;
44:
45: private Map<CredentialsType, CredentialsSource> credentialsSourcesByType = new HashMap<CredentialsType, CredentialsSource>();
46:
47: public CredentialsSource getCredentialsForType(
48: final CredentialsType credentialsType) {
49: return credentialsSourcesByType.get(credentialsType);
50: }
51:
52: public void afterPropertiesSet() throws Exception {
53: if (credentialsSources != null) {
54: for (final CredentialsSource credentialsSource : this .credentialsSources) {
55: this .credentialsSourcesByType.put(credentialsSource
56: .getSupportedCredentialsType(),
57: credentialsSource);
58: }
59: } else {
60: log
61: .warn("No CredentialsSources set. No security will be provided on the bus.");
62: }
63: }
64:
65: public void setCredentialsSources(
66: final List<CredentialsSource> credentialsSources) {
67: this.credentialsSources = credentialsSources;
68: }
69: }
|