File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\security\SparseACL.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.security;
25
26 import org.acegisecurity.Authentication;
27 import org.acegisecurity.acls.sid.Sid;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.logging.Logger;
32 import static java.util.logging.Level.FINE;
33
34 /**
35 * Access control list.
36 *
37 * @author Kohsuke Kawaguchi
38 */
39 public class SparseACL extends SidACL {
40 public static final class Entry {
41 // Sid has value-equality semantics
42 public final Sid sid;
43 public final Permission permission;
44 public final boolean allowed;
45
46 public Entry(Sid sid, Permission permission, boolean allowed) {
47 this.sid = sid;
48 this.permission = permission;
49 this.allowed = allowed;
50 }
51 }
52
53 private final List<Entry> entries = new ArrayList<Entry>();
54 /**
55 * Parent to delegate to. Can be null.
56 */
57 private ACL parent;
58
59 public SparseACL(ACL parent) {
60 this.parent = parent;
61 }
62
63 public void add(Entry e) {
64 entries.add(e);
65 }
66
67 public void add(Sid sid, Permission permission, boolean allowed) {
68 add(new Entry(sid,permission,allowed));
69 }
70
71 @Override
72 public boolean hasPermission(Authentication a, Permission permission) {
73 if(a==SYSTEM) return true;
74 Boolean b = _hasPermission(a,permission);
75 if(b!=null) return b;
76
77 if(parent!=null) {
78 if(LOGGER.isLoggable(FINE))
79 LOGGER.fine("hasPermission("+a+","+permission+") is delegating to parent ACL: "+parent);
80 return parent.hasPermission(a,permission);
81 }
82
83 // the ultimate default is to reject everything
84 return false;
85 }
86
87 @Override
88 protected Boolean hasPermission(Sid p, Permission permission) {
89 for( ; permission!=null; permission=permission.impliedBy ) {
90 for (Entry e : entries) {
91 if(e.permission==permission && e.sid.equals(p))
92 return e.allowed;
93 }
94 }
95 return null;
96 }
97
98 private static final Logger LOGGER = Logger.getLogger(SparseACL.class.getName());
99 }
100