Subversion Repositories general

Rev

Rev 1010 | Rev 1015 | Go to most recent revision | Details | Compare with Previous | 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;
1011 dev 21
	private Mailbox    origin;  // save original object state before any changes
919 dev 22
 
23
	protected Mailbox()
24
	{
25
	}
26
 
1011 dev 27
	protected Mailbox(Mailbox origin)
28
	{
29
		super(origin);
30
		this.login      = origin.login;
31
		this.password   = origin.password;
32
		this.domain     = origin.domain;
33
		this.owner      = origin.owner;
34
		this.virusCheck = origin.virusCheck;
35
		this.spamCheck  = origin.spamCheck;
36
		this.systemUser = origin.systemUser;
37
	}
38
 
39
    protected Mailbox getOrigin()
40
    {
41
        return origin;
42
    }
43
 
44
    protected void backupMe()
45
    {
46
        if(origin == null)
47
            origin = new Mailbox(this);
48
    }
49
 
919 dev 50
	/**
51
	 *
52
	 * @hibernate.property
53
	 */
54
	public String getLogin()
55
	{
56
		return login;
57
	}
58
 
921 dev 59
	protected void setLogin(String login)
919 dev 60
	{
61
		this.login = login;
62
	}
63
 
921 dev 64
	public void setLogin(User editor, String login)
65
		throws ModelException
66
	{
67
		if(!editableBy(editor))
68
			throw new ModelSecurityException();
69
 
1011 dev 70
        backupMe();
921 dev 71
		this.login = login;
72
	}
73
 
919 dev 74
	/**
75
	 *
76
	 * @hibernate.property
77
	 */
921 dev 78
	protected String getPassword()
919 dev 79
	{
80
		return password;
81
	}
82
 
921 dev 83
	protected void setPassword(String password)
919 dev 84
	{
85
		this.password = password;
86
	}
87
 
921 dev 88
	public void setPassword(User editor, String password)
89
		throws ModelException
919 dev 90
	{
91
		if(password == null)
92
			throw new NullPointerException("Null password");
93
 
1011 dev 94
        backupMe();
899 dev 95
		this.password = Digest.encode(password);
919 dev 96
	}
97
 
98
	/**
99
	 *
100
	 * @hibernate.many-to-one
101
	 */
102
	public InetDomain getDomain()
103
	{
104
		return domain;
105
	}
106
 
921 dev 107
	protected void setDomain(InetDomain domain)
919 dev 108
	{
109
		this.domain = domain;
110
	}
111
 
921 dev 112
	public void setDomain(User editor, InetDomain domain)
113
		throws ModelException
114
	{
115
		if(!editableBy(editor))
116
			throw new ModelSecurityException();
117
 
1011 dev 118
        backupMe();
921 dev 119
		this.domain = domain;
120
	}
121
 
919 dev 122
	/**
123
	 *
124
	 * @hibernate.many-to-one
125
	 */
126
	public User getOwner()
127
	{
128
		return owner;
129
	}
130
 
921 dev 131
	protected void setOwner(User owner)
919 dev 132
	{
133
		this.owner = owner;
134
	}
135
 
921 dev 136
	public void setOwner(User editor, User owner)
137
		throws ModelException
138
	{
139
		if(!editableBy(editor))
140
			throw new ModelSecurityException();
141
 
1011 dev 142
        backupMe();
921 dev 143
		this.owner = owner;
144
	}
145
 
919 dev 146
	/**
147
	 *
148
	 * @hibernate.property
149
	 */
150
	public Boolean getVirusCheck()
151
	{
152
		return virusCheck;
153
	}
154
 
921 dev 155
	protected void setVirusCheck(Boolean virusCheck)
919 dev 156
	{
157
		this.virusCheck = virusCheck;
158
	}
159
 
921 dev 160
	public void setVirusCheck(User editor, Boolean virusCheck)
161
		throws ModelException
162
	{
163
		if(!editableBy(editor))
164
			throw new ModelSecurityException();
165
 
1011 dev 166
        backupMe();
921 dev 167
		this.virusCheck = virusCheck;
168
	}
169
 
919 dev 170
	/**
171
	 *
172
	 * @hibernate.property
173
	 */
174
	public Boolean getSpamCheck()
175
	{
176
		return spamCheck;
177
	}
178
 
921 dev 179
	protected void setSpamCheck(Boolean spamCheck)
919 dev 180
	{
181
		this.spamCheck = spamCheck;
182
	}
183
 
921 dev 184
	public void setSpamCheck(User editor, Boolean spamCheck)
185
		throws ModelException
186
	{
187
		if(!editableBy(editor))
188
			throw new ModelSecurityException();
189
 
1011 dev 190
        backupMe();
921 dev 191
		this.spamCheck = spamCheck;
192
	}
193
 
919 dev 194
	/**
195
	 *
196
	 * @hibernate.many-to-one
197
	 */
198
	public SystemUser getSystemUser()
199
	{
200
		return systemUser;
201
	}
202
 
921 dev 203
	protected void setSystemUser(SystemUser systemUser)
919 dev 204
	{
205
		this.systemUser = systemUser;
206
	}
207
 
921 dev 208
	public void setSystemUser(User editor, SystemUser systemUser)
209
		throws ModelException
210
	{
211
		if(!editableBy(editor))
212
			throw new ModelSecurityException();
213
 
1011 dev 214
        backupMe();
921 dev 215
		this.systemUser = systemUser;
216
	}
217
 
919 dev 218
	public String getTypeKey()
219
	{
924 dev 220
		return ak.hostadmiral.core.CoreResources.TYPE_MAILBOX;
919 dev 221
	}
222
 
223
	public String getIdentKey()
224
	{
924 dev 225
		return ak.hostadmiral.core.CoreResources.IDENT_MAILBOX;
919 dev 226
	}
227
 
228
	public Object[] getIdentParams()
229
	{
230
		return new Object[] { getLogin(), getDomain().getName() };
231
	}
232
 
233
	public boolean viewableBy(User user)
234
	{
235
		return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
236
	}
237
 
238
	public boolean editableBy(User user)
239
	{
1010 dev 240
		return user.isSuperuser()
241
			|| (domain == null) // just created
242
			|| user.equals(domain.getOwner());
919 dev 243
	}
244
 
245
	public boolean deleteableBy(User user)
246
	{
247
		return user.isSuperuser() || user.equals(domain.getOwner());
248
	}
921 dev 249
 
250
	protected static boolean allowedToCreate(MailboxManager manager, User editor)
251
		throws ModelException
252
	{
253
		return editor.isSuperuser()
254
			|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
255
	}
949 dev 256
 
257
	protected static Mailbox createLimitedCopy(Mailbox origin)
258
	{
1011 dev 259
		Mailbox m = new Mailbox();
260
		m.setLogin(origin.getLogin());
261
		m.setDomain(origin.getDomain());
262
		m.setOwner(origin.getOwner());
263
		return m;
949 dev 264
	}
919 dev 265
}