Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
924 | dev | 1 | package ak.hostadmiral.core.model; |
919 | dev | 2 | |
924 | dev | 3 | import ak.hostadmiral.util.Digest; |
4 | import ak.hostadmiral.util.ModelException; |
||
5 | import ak.hostadmiral.util.ModelSecurityException; |
||
919 | dev | 6 | |
7 | /** |
||
8 | * |
||
9 | * @hibernate.class table="mailboxes" |
||
10 | */ |
||
11 | public class Mailbox |
||
12 | extends GeneralModelObject |
||
13 | { |
||
14 | private String login; |
||
15 | private String password; |
||
16 | private InetDomain domain; |
||
17 | private User owner; |
||
18 | private Boolean virusCheck; |
||
19 | private Boolean spamCheck; |
||
20 | private SystemUser systemUser; |
||
21 | |||
22 | protected Mailbox() |
||
23 | { |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * |
||
28 | * @hibernate.property |
||
29 | */ |
||
30 | public String getLogin() |
||
31 | { |
||
32 | return login; |
||
33 | } |
||
34 | |||
921 | dev | 35 | protected void setLogin(String login) |
919 | dev | 36 | { |
37 | this.login = login; |
||
38 | } |
||
39 | |||
921 | dev | 40 | public void setLogin(User editor, String login) |
41 | throws ModelException |
||
42 | { |
||
43 | if(!editableBy(editor)) |
||
44 | throw new ModelSecurityException(); |
||
45 | |||
46 | this.login = login; |
||
47 | } |
||
48 | |||
919 | dev | 49 | /** |
50 | * |
||
51 | * @hibernate.property |
||
52 | */ |
||
921 | dev | 53 | protected String getPassword() |
919 | dev | 54 | { |
55 | return password; |
||
56 | } |
||
57 | |||
921 | dev | 58 | protected void setPassword(String password) |
919 | dev | 59 | { |
60 | this.password = password; |
||
61 | } |
||
62 | |||
921 | dev | 63 | public void setPassword(User editor, String password) |
64 | throws ModelException |
||
919 | dev | 65 | { |
66 | if(password == null) |
||
67 | throw new NullPointerException("Null password"); |
||
68 | |||
899 | dev | 69 | this.password = Digest.encode(password); |
919 | dev | 70 | } |
71 | |||
72 | /** |
||
73 | * |
||
74 | * @hibernate.many-to-one |
||
75 | */ |
||
76 | public InetDomain getDomain() |
||
77 | { |
||
78 | return domain; |
||
79 | } |
||
80 | |||
921 | dev | 81 | protected void setDomain(InetDomain domain) |
919 | dev | 82 | { |
83 | this.domain = domain; |
||
84 | } |
||
85 | |||
921 | dev | 86 | public void setDomain(User editor, InetDomain domain) |
87 | throws ModelException |
||
88 | { |
||
89 | if(!editableBy(editor)) |
||
90 | throw new ModelSecurityException(); |
||
91 | |||
92 | this.domain = domain; |
||
93 | } |
||
94 | |||
919 | dev | 95 | /** |
96 | * |
||
97 | * @hibernate.many-to-one |
||
98 | */ |
||
99 | public User getOwner() |
||
100 | { |
||
101 | return owner; |
||
102 | } |
||
103 | |||
921 | dev | 104 | protected void setOwner(User owner) |
919 | dev | 105 | { |
106 | this.owner = owner; |
||
107 | } |
||
108 | |||
921 | dev | 109 | public void setOwner(User editor, User owner) |
110 | throws ModelException |
||
111 | { |
||
112 | if(!editableBy(editor)) |
||
113 | throw new ModelSecurityException(); |
||
114 | |||
115 | this.owner = owner; |
||
116 | } |
||
117 | |||
919 | dev | 118 | /** |
119 | * |
||
120 | * @hibernate.property |
||
121 | */ |
||
122 | public Boolean getVirusCheck() |
||
123 | { |
||
124 | return virusCheck; |
||
125 | } |
||
126 | |||
921 | dev | 127 | protected void setVirusCheck(Boolean virusCheck) |
919 | dev | 128 | { |
129 | this.virusCheck = virusCheck; |
||
130 | } |
||
131 | |||
921 | dev | 132 | public void setVirusCheck(User editor, Boolean virusCheck) |
133 | throws ModelException |
||
134 | { |
||
135 | if(!editableBy(editor)) |
||
136 | throw new ModelSecurityException(); |
||
137 | |||
138 | this.virusCheck = virusCheck; |
||
139 | } |
||
140 | |||
919 | dev | 141 | /** |
142 | * |
||
143 | * @hibernate.property |
||
144 | */ |
||
145 | public Boolean getSpamCheck() |
||
146 | { |
||
147 | return spamCheck; |
||
148 | } |
||
149 | |||
921 | dev | 150 | protected void setSpamCheck(Boolean spamCheck) |
919 | dev | 151 | { |
152 | this.spamCheck = spamCheck; |
||
153 | } |
||
154 | |||
921 | dev | 155 | public void setSpamCheck(User editor, Boolean spamCheck) |
156 | throws ModelException |
||
157 | { |
||
158 | if(!editableBy(editor)) |
||
159 | throw new ModelSecurityException(); |
||
160 | |||
161 | this.spamCheck = spamCheck; |
||
162 | } |
||
163 | |||
919 | dev | 164 | /** |
165 | * |
||
166 | * @hibernate.many-to-one |
||
167 | */ |
||
168 | public SystemUser getSystemUser() |
||
169 | { |
||
170 | return systemUser; |
||
171 | } |
||
172 | |||
921 | dev | 173 | protected void setSystemUser(SystemUser systemUser) |
919 | dev | 174 | { |
175 | this.systemUser = systemUser; |
||
176 | } |
||
177 | |||
921 | dev | 178 | public void setSystemUser(User editor, SystemUser systemUser) |
179 | throws ModelException |
||
180 | { |
||
181 | if(!editableBy(editor)) |
||
182 | throw new ModelSecurityException(); |
||
183 | |||
184 | this.systemUser = systemUser; |
||
185 | } |
||
186 | |||
919 | dev | 187 | public String getTypeKey() |
188 | { |
||
924 | dev | 189 | return ak.hostadmiral.core.CoreResources.TYPE_MAILBOX; |
919 | dev | 190 | } |
191 | |||
192 | public String getIdentKey() |
||
193 | { |
||
924 | dev | 194 | return ak.hostadmiral.core.CoreResources.IDENT_MAILBOX; |
919 | dev | 195 | } |
196 | |||
197 | public Object[] getIdentParams() |
||
198 | { |
||
199 | return new Object[] { getLogin(), getDomain().getName() }; |
||
200 | } |
||
201 | |||
202 | public boolean viewableBy(User user) |
||
203 | { |
||
204 | return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner); |
||
205 | } |
||
206 | |||
207 | public boolean editableBy(User user) |
||
208 | { |
||
209 | return user.isSuperuser() || user.equals(domain.getOwner()); |
||
210 | } |
||
211 | |||
212 | public boolean deleteableBy(User user) |
||
213 | { |
||
214 | return user.isSuperuser() || user.equals(domain.getOwner()); |
||
215 | } |
||
921 | dev | 216 | |
217 | protected static boolean allowedToCreate(MailboxManager manager, User editor) |
||
218 | throws ModelException |
||
219 | { |
||
220 | return editor.isSuperuser() |
||
221 | || InetDomainManager.getInstance().areInetDomainsAvailable(editor); |
||
222 | } |
||
949 | dev | 223 | |
224 | protected static Mailbox createLimitedCopy(Mailbox origin) |
||
225 | { |
||
226 | Mailbox u = new Mailbox(); |
||
227 | u.setLogin(origin.getLogin()); |
||
228 | u.setDomain(origin.getDomain()); |
||
229 | return u; |
||
230 | } |
||
919 | dev | 231 | } |