|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.acl.basic; |
|
17 |
| |
|
18 |
| import org.acegisecurity.Authentication; |
|
19 |
| import org.acegisecurity.GrantedAuthority; |
|
20 |
| import org.acegisecurity.acl.AclEntry; |
|
21 |
| import org.acegisecurity.userdetails.UserDetails; |
|
22 |
| |
|
23 |
| import org.apache.commons.logging.Log; |
|
24 |
| import org.apache.commons.logging.LogFactory; |
|
25 |
| |
|
26 |
| import java.util.List; |
|
27 |
| import java.util.Vector; |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| public class GrantedAuthorityEffectiveAclsResolver |
|
61 |
| implements EffectiveAclsResolver { |
|
62 |
| |
|
63 |
| |
|
64 |
| private static final Log logger = LogFactory.getLog(GrantedAuthorityEffectiveAclsResolver.class); |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
16
| public AclEntry[] resolveEffectiveAcls(AclEntry[] allAcls,
|
|
69 |
| Authentication filteredBy) { |
|
70 |
16
| if ((allAcls == null) || (allAcls.length == 0)) {
|
|
71 |
1
| return null;
|
|
72 |
| } |
|
73 |
| |
|
74 |
15
| List list = new Vector();
|
|
75 |
| |
|
76 |
15
| if (logger.isDebugEnabled()) {
|
|
77 |
0
| logger.debug("Locating AclEntry[]s (from set of "
|
|
78 |
0
| + ((allAcls == null) ? 0 : allAcls.length)
|
|
79 |
| + ") that apply to Authentication: " + filteredBy); |
|
80 |
| } |
|
81 |
| |
|
82 |
15
| for (int i = 0; i < allAcls.length; i++) {
|
|
83 |
73
| if (!(allAcls[i] instanceof BasicAclEntry)) {
|
|
84 |
1
| continue;
|
|
85 |
| } |
|
86 |
| |
|
87 |
72
| Object recipient = ((BasicAclEntry) allAcls[i])
|
|
88 |
| .getRecipient(); |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
72
| if (filteredBy.getPrincipal().equals(recipient)) {
|
|
94 |
10
| if (logger.isDebugEnabled()) {
|
|
95 |
0
| logger.debug("Principal matches AclEntry recipient: "
|
|
96 |
| + recipient); |
|
97 |
| } |
|
98 |
| |
|
99 |
10
| list.add(allAcls[i]);
|
|
100 |
62
| } else if (filteredBy.getPrincipal() instanceof UserDetails
|
|
101 |
| && ((UserDetails) filteredBy.getPrincipal()).getUsername() |
|
102 |
| .equals(recipient)) { |
|
103 |
4
| if (logger.isDebugEnabled()) {
|
|
104 |
0
| logger.debug(
|
|
105 |
| "Principal (from UserDetails) matches AclEntry recipient: " |
|
106 |
| + recipient); |
|
107 |
| } |
|
108 |
| |
|
109 |
4
| list.add(allAcls[i]);
|
|
110 |
| } else { |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
58
| GrantedAuthority[] authorities = filteredBy.getAuthorities();
|
|
116 |
| |
|
117 |
58
| if ((authorities == null) || (authorities.length == 0)) {
|
|
118 |
6
| if (logger.isDebugEnabled()) {
|
|
119 |
0
| logger.debug(
|
|
120 |
| "Did not match principal and there are no granted authorities, so cannot compare with recipient: " |
|
121 |
| + recipient); |
|
122 |
| } |
|
123 |
| |
|
124 |
6
| continue;
|
|
125 |
| } |
|
126 |
| |
|
127 |
52
| for (int k = 0; k < authorities.length; k++) {
|
|
128 |
104
| if (authorities[k].equals(recipient)) {
|
|
129 |
26
| if (logger.isDebugEnabled()) {
|
|
130 |
0
| logger.debug("GrantedAuthority: " + authorities[k]
|
|
131 |
| + " matches recipient: " + recipient); |
|
132 |
| } |
|
133 |
| |
|
134 |
26
| list.add(allAcls[i]);
|
|
135 |
| } |
|
136 |
| } |
|
137 |
| } |
|
138 |
| } |
|
139 |
| |
|
140 |
| |
|
141 |
15
| if (list.size() > 0) {
|
|
142 |
14
| if (logger.isDebugEnabled()) {
|
|
143 |
0
| logger.debug("Returning effective AclEntry array with "
|
|
144 |
| + list.size() + " elements"); |
|
145 |
| } |
|
146 |
| |
|
147 |
14
| return (BasicAclEntry[]) list.toArray(new BasicAclEntry[] {});
|
|
148 |
| } else { |
|
149 |
1
| if (logger.isDebugEnabled()) {
|
|
150 |
0
| logger.debug(
|
|
151 |
| "Returning null AclEntry array as zero effective AclEntrys found"); |
|
152 |
| } |
|
153 |
| |
|
154 |
1
| return null;
|
|
155 |
| } |
|
156 |
| } |
|
157 |
| } |