rename MailboxTree -> MailTree
[org.ibex.mail.git] / src / org / ibex / mail / Acl.java
1 // Copyright 2007 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.mail;
6 import org.ibex.util.*;
7 import org.ibex.mail.*;
8 import org.ibex.js.*;
9 import java.io.*;
10 import java.net.*;
11 import java.util.*;
12 import java.text.*;
13
14 /** an Access Control List */
15 public class Acl {
16
17     public static class PermissionDenied extends RuntimeException {
18         public PermissionDenied() { super(); }
19     }
20
21     /** an entry on an Acl; indicates permissions for a particular principal */
22     public static class Entry {
23         public final boolean read;
24         public final boolean list;
25         public final boolean write;
26         public final boolean delete;
27         public final boolean insert;
28         public final boolean lock;
29         public final boolean admin;
30         public final boolean post;
31         public final boolean flags;
32         public final boolean mkdir;
33         private String toString = null;
34
35         public Entry(boolean read,
36                      boolean list,
37                      boolean insert,
38                      boolean delete,
39                      boolean write,
40                      boolean lock,
41                      boolean admin,
42                      boolean post,
43                      boolean flags,
44                      boolean mkdir) {
45             this.read = read;
46             this.list = list;
47             this.write = write;
48             this.delete = delete;
49             this.insert = insert;
50             this.lock = lock;
51             this.admin = admin;
52             this.post = post;
53             this.flags = flags;
54             this.mkdir = mkdir;        
55         }
56
57         public Entry(String asString) {
58             this.toString = asString;
59             if (asString == null) asString = "";
60             if (asString.equals("read")) asString = "rl";
61             if (asString.equals("post")) asString = "rlp";
62             if (asString.equals("write")) asString = "rlidwkpfm";
63             this.read = asString.indexOf('r') != -1;
64             this.list = asString.indexOf('l') != -1;
65             this.insert = asString.indexOf('i') != -1;
66             this.delete = asString.indexOf('d') != -1;
67             this.write = asString.indexOf('w') != -1;
68             this.lock = asString.indexOf('k') != -1;
69             this.admin = asString.indexOf('a') != -1;
70             this.post = asString.indexOf('p') != -1;
71             this.flags = asString.indexOf('f') != -1;
72             this.mkdir = asString.indexOf('m') != -1;
73         }
74
75         public String toString() {
76             if (toString != null) return toString;
77             StringBuffer sb = new StringBuffer();
78             if (this.read) sb.append('r');
79             if (this.list) sb.append('l');
80             if (this.insert) sb.append('i');
81             if (this.delete) sb.append('d');
82             if (this.write) sb.append('w');
83             if (this.lock) sb.append('k');
84             if (this.admin) sb.append('a');
85             if (this.post) sb.append('p');
86             if (this.flags) sb.append('f');
87             if (this.mkdir) sb.append('m');
88             return toString = sb.toString();
89         }
90     }
91
92 }