add mailbox acls, further separate Mailbox and MailboxTree
[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             this.read = asString.indexOf('r') != -1;
60             this.list = asString.indexOf('l') != -1;
61             this.insert = asString.indexOf('i') != -1;
62             this.delete = asString.indexOf('d') != -1;
63             this.write = asString.indexOf('w') != -1;
64             this.lock = asString.indexOf('k') != -1;
65             this.admin = asString.indexOf('a') != -1;
66             this.post = asString.indexOf('p') != -1;
67             this.flags = asString.indexOf('f') != -1;
68             this.mkdir = asString.indexOf('m') != -1;
69         }
70
71         public String toString() {
72             if (toString != null) return toString;
73             StringBuffer sb = new StringBuffer();
74             if (this.read) sb.append('r');
75             if (this.list) sb.append('l');
76             if (this.insert) sb.append('i');
77             if (this.delete) sb.append('d');
78             if (this.write) sb.append('w');
79             if (this.lock) sb.append('k');
80             if (this.admin) sb.append('a');
81             if (this.post) sb.append('p');
82             if (this.flags) sb.append('f');
83             if (this.mkdir) sb.append('m');
84             return toString = sb.toString();
85         }
86     }
87
88 }