Source code: jsdsi/Acl.java
1 /*
2 * Copyright 2002 Massachusetts Institute of Technology
3 *
4 * Permission to use, copy, modify, and distribute this program for any
5 * purpose and without fee is hereby granted, provided that this
6 * copyright and permission notice appear on all copies and supporting
7 * documentation, the name of M.I.T. not be used in advertising or
8 * publicity pertaining to distribution of the program without specific
9 * prior permission, and notice be given in supporting documentation that
10 * copying and distribution is by permission of M.I.T. M.I.T. makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 */
14 package jsdsi;
15
16 import java.util.Iterator;
17
18 import jsdsi.sexp.*;
19
20 /**
21 * An access control list (ACL) that restricts access to an object on
22 * the local system. The ACL contains a set of ACL entries that specify
23 * which principals may access the object and how.
24 *
25 * @see AclEntry
26 *
27 * @author Sameer Ajmani
28 * @version $Revision: 1.2 $ $Date: 2003/04/22 21:37:40 $
29 */
30 public class Acl extends Obj {
31 /**
32 * The entries the Acl consists of.
33 */
34 private final AclEntry[] entries;
35
36 /**
37 * Constructs a new <code>Acl</code> from given <code>AclEntry</code>s.
38 *
39 * @param e array of <code>AclEntry</code>s to create a new
40 * <code>Acl</code> from.
41 */
42 public Acl(AclEntry[] e) {
43 assert(e != null) : "null entries";
44 entries = e;
45 }
46
47 /**
48 * Returns an array of <code>AclEntry</code>s.
49 *
50 * @see AclEntry
51 *
52 * @return an array of <code>AclEntry</code>s.
53 */
54 public AclEntry[] getEntries() {
55 return entries;
56 }
57
58 /**
59 * @see java.lang.Object#equals(Object)
60 */
61 public boolean equals(Object o) {
62 return (o instanceof Acl) && Util.equals(entries, ((Acl) o).entries);
63 }
64
65 /**
66 * @see java.lang.Object#hashCode()
67 */
68 public int hashCode() {
69 return Util.hashCode(entries);
70 }
71
72 /**
73 * Converts this <code>Acl</code> to an <code>SecpList</code>.
74 *
75 * @return an <code>SecpList</code> that represents this <code>Acl</code>.
76 */
77 public SexpList toSexp() {
78 Sexp[] ss = new Sexp[entries.length];
79 for (int i = 0; i < entries.length; i++) {
80 ss[i] = entries[i].toSexp();
81 }
82 return SexpUtil.toSexp("acl", ss);
83 }
84
85 static Acl parseAcl(SexpList l) throws SexpParseException {
86 Iterator abody = SexpUtil.getBody(l);
87 AclEntry[] entries = new AclEntry[l.size() - 1];
88 for (int i = 0; i < entries.length; i++) {
89 entries[i] =
90 AclEntry.parseAclEntry(
91 SexpUtil.getNextList(abody, "entry", "acl entry"));
92 }
93 SexpUtil.checkDone(abody, "acl");
94 return new Acl(entries);
95 }
96 }