1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.acl;
17
18 import org.acegisecurity.Authentication;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import org.springframework.beans.factory.InitializingBean;
24
25 import org.springframework.util.Assert;
26
27 import java.util.Iterator;
28 import java.util.List;
29
30
31
32
33
34
35
36
37
38
39 public class AclProviderManager implements AclManager, InitializingBean {
40
41
42 private static final Log logger = LogFactory.getLog(AclProviderManager.class);
43
44
45
46 private List providers;
47
48
49
50 public void afterPropertiesSet() throws Exception {
51 checkIfValidList(this.providers);
52 }
53
54 private void checkIfValidList(List listToCheck) {
55 Assert.notEmpty(listToCheck, "A list of AclManagers is required");
56 }
57
58 public AclEntry[] getAcls(Object domainInstance) {
59 Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");
60
61 Iterator iter = providers.iterator();
62
63 while (iter.hasNext()) {
64 AclProvider provider = (AclProvider) iter.next();
65
66 if (provider.supports(domainInstance)) {
67 if (logger.isDebugEnabled()) {
68 logger.debug("ACL lookup using " + provider.getClass().getName());
69 }
70
71 return provider.getAcls(domainInstance);
72 }
73 }
74
75 if (logger.isDebugEnabled()) {
76 logger.debug("No AclProvider found for " + domainInstance.toString());
77 }
78
79 return null;
80 }
81
82 public AclEntry[] getAcls(Object domainInstance, Authentication authentication) {
83 Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");
84 Assert.notNull(authentication, "authentication is null - violating interface contract");
85
86 Iterator iter = providers.iterator();
87
88 while (iter.hasNext()) {
89 AclProvider provider = (AclProvider) iter.next();
90
91 if (provider.supports(domainInstance)) {
92 if (logger.isDebugEnabled()) {
93 logger.debug("ACL lookup using " + provider.getClass().getName());
94 }
95
96 return provider.getAcls(domainInstance, authentication);
97 } else {
98 if (logger.isDebugEnabled()) {
99 logger.debug("Provider " + provider.toString() + " does not support " + domainInstance);
100 }
101 }
102 }
103
104 if (logger.isDebugEnabled()) {
105 logger.debug("No AclProvider found for " + domainInstance.toString());
106 }
107
108 return null;
109 }
110
111 public List getProviders() {
112 return this.providers;
113 }
114
115
116
117
118
119
120
121
122 public void setProviders(List newList) {
123 checkIfValidList(newList);
124
125 Iterator iter = newList.iterator();
126
127 while (iter.hasNext()) {
128 Object currentObject = null;
129
130 try {
131 currentObject = iter.next();
132
133 AclProvider attemptToCast = (AclProvider) currentObject;
134 } catch (ClassCastException cce) {
135 throw new IllegalArgumentException("AclProvider " + currentObject.getClass().getName()
136 + " must implement AclProvider");
137 }
138 }
139
140 this.providers = newList;
141 }
142 }