Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1010 → Rev 1011

/hostadmiral/trunk/src/ak/hostadmiral/core/model/InetDomainModifiedListener.java
0,0 → 1,21
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface InetDomainModifiedListener
{
/**
* called if some domain is just changed.
*
* @param editor who is doing the operation
* @param domain the domain in its new state
* @param oldDomain copy of domain as it was before the operation
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other InetDomainCreatedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void inetDomainModified(User editor, InetDomain domain, InetDomain oldDomain)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserManager.java
236,7 → 236,7
public void delete(User editor, User user)
throws ModelException
{
// chech rights
// check rights
if(!user.deleteableBy(editor))
throw new ModelSecurityException();
 
/hostadmiral/trunk/src/ak/hostadmiral/core/model/SystemUserDeletedListener.java
0,0 → 1,20
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface SystemUserDeletedListener
{
/**
* called if some system user is just deleted.
*
* @param editor who is doing the operation
* @param systemUser the system user deleted
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other SystemUserDeletedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void systemUserDeleted(User editor, SystemUser systemUser)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/SystemUserCreatedListener.java
0,0 → 1,20
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface SystemUserCreatedListener
{
/**
* called if new system user is just created.
*
* @param editor who is doing the operation
* @param systemUser the new system user
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other SystemUserCreatedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void systemUserCreated(User editor, SystemUser systemUser)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/InetDomainManager.java
41,7 → 41,10
register();
}
 
private Collection createdListeners = new ArrayList();
private Collection modifiedListeners = new ArrayList();
private Collection beforeDeleteListeners = new ArrayList();
private Collection deletedListeners = new ArrayList();
 
private InetDomainManager()
{
128,6 → 131,8
if(!domain.editableBy(editor))
throw new ModelSecurityException();
 
boolean isNew = domain.isNew();
 
//domain.setModUser(editor); // FIXME
 
try {
137,18 → 142,64
{
throw new ModelException(ex);
}
 
// inform listeners
if(isNew) {
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) {
InetDomainCreatedListener listener = (InetDomainCreatedListener)i.next();
listener.inetDomainCreated(editor, domain);
}
}
else {
InetDomain oldDomain = domain.getOrigin();
if(oldDomain == null) oldDomain = domain;
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) {
InetDomainModifiedListener listener = (InetDomainModifiedListener)i.next();
listener.inetDomainModified(editor, domain, oldDomain);
}
}
}
 
public void addBeforeDeleteListener(SystemUserBeforeDeleteListener listener)
public void addCreatedListener(InetDomainCreatedListener listener)
{
createdListeners.add(listener);
}
 
public void removeCreatedListener(InetDomainCreatedListener listener)
{
createdListeners.remove(listener);
}
 
public void addModifiedListener(InetDomainModifiedListener listener)
{
modifiedListeners.add(listener);
}
 
public void removeModifiedListener(InetDomainModifiedListener listener)
{
modifiedListeners.remove(listener);
}
 
public void addBeforeDeleteListener(InetDomainBeforeDeleteListener listener)
{
beforeDeleteListeners.add(listener);
}
 
public void removeBeforeDeleteListener(SystemUserBeforeDeleteListener listener)
public void removeBeforeDeleteListener(InetDomainBeforeDeleteListener listener)
{
beforeDeleteListeners.remove(listener);
}
 
public void addDeletedListener(InetDomainDeletedListener listener)
{
deletedListeners.add(listener);
}
 
public void removeDeletedListener(InetDomainDeletedListener listener)
{
deletedListeners.remove(listener);
}
 
public Collection beforeDelete(User editor, InetDomain domain, Collection known)
throws ModelException
{
167,9 → 218,14
public void delete(User editor, InetDomain domain)
throws ModelException
{
// check rights
if(!domain.deleteableBy(editor))
throw new ModelSecurityException();
 
// backup copy
InetDomain oldDomain = new InetDomain(domain);
 
// delete it
try {
 
HibernateUtil.currentSession().delete(domain);
178,6 → 234,12
{
throw new ModelException(ex);
}
 
// inform listeners
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) {
InetDomainDeletedListener listener = (InetDomainDeletedListener)i.next();
listener.inetDomainDeleted(editor, oldDomain);
}
}
 
public Collection listInetDomains(User editor)
/hostadmiral/trunk/src/ak/hostadmiral/core/model/InetDomain.java
10,13 → 10,32
public class InetDomain
extends GeneralModelObject
{
private String name;
private User owner;
private String name;
private User owner;
private InetDomain origin; // save original object state before any changes
 
protected InetDomain()
{
}
 
protected InetDomain(InetDomain origin)
{
super(origin);
this.name = origin.name;
this.owner = origin.owner;
}
 
protected InetDomain getOrigin()
{
return origin;
}
 
protected void backupMe()
{
if(origin == null)
origin = new InetDomain(this);
}
 
/**
*
* @hibernate.property
37,6 → 56,7
if(!editableBy(editor))
throw new ModelSecurityException();
 
backupMe();
this.name = name;
}
 
60,6 → 80,7
if(!editableBy(editor))
throw new ModelSecurityException();
 
backupMe();
this.owner = owner;
}
 
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasManager.java
8,8 → 8,19
import ak.hostadmiral.util.ModelSecurityException;
 
public class MailAliasManager
implements UserBeforeDeleteListener
{
private static MailAliasManager mailAliasManager = null;
private static boolean registered = false;
 
public static MailAliasManager getInstance()
{
if(mailAliasManager == null)
mailAliasManager = new MailAliasManager();
 
return mailAliasManager;
}
 
protected static void register()
{
synchronized(MailAliasManager.class) {
31,8 → 42,14
register();
}
 
private Collection createdListeners = new ArrayList();
private Collection modifiedListeners = new ArrayList();
private Collection beforeDeleteListeners = new ArrayList();
private Collection deletedListeners = new ArrayList();
 
private MailAliasManager()
{
UserManager.getInstance().addBeforeDeleteListener(this);
}
 
public MailAlias create(User editor)
121,6 → 138,8
if(!mailAlias.editableBy(editor))
throw new ModelSecurityException();
 
boolean isNew = mailAlias.isNew();
 
//mailAlias.setModUser(editor); // FIXME
 
try {
130,14 → 149,90
{
throw new ModelException(ex);
}
 
// inform listeners
if(isNew) {
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) {
MailAliasCreatedListener listener = (MailAliasCreatedListener)i.next();
listener.mailAliasCreated(editor, mailAlias);
}
}
else {
MailAlias oldMailAlias = mailAlias.getOrigin();
if(oldMailAlias == null) oldMailAlias = mailAlias;
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) {
MailAliasModifiedListener listener = (MailAliasModifiedListener)i.next();
listener.mailAliasModified(editor, mailAlias, oldMailAlias);
}
}
}
 
public void addCreatedListener(MailAliasCreatedListener listener)
{
createdListeners.add(listener);
}
 
public void removeCreatedListener(MailAliasCreatedListener listener)
{
createdListeners.remove(listener);
}
 
public void addModifiedListener(MailAliasModifiedListener listener)
{
modifiedListeners.add(listener);
}
 
public void removeModifiedListener(MailAliasModifiedListener listener)
{
modifiedListeners.remove(listener);
}
 
public void addBeforeDeleteListener(MailAliasBeforeDeleteListener listener)
{
beforeDeleteListeners.add(listener);
}
 
public void removeBeforeDeleteListener(MailAliasBeforeDeleteListener listener)
{
beforeDeleteListeners.remove(listener);
}
 
public void addDeletedListener(MailAliasDeletedListener listener)
{
deletedListeners.add(listener);
}
 
public void removeDeletedListener(MailAliasDeletedListener listener)
{
deletedListeners.remove(listener);
}
 
public Collection beforeDelete(User editor, MailAlias mailAlias, Collection known)
throws ModelException
{
Collection cascade = new ArrayList();
 
for(Iterator i = beforeDeleteListeners.iterator(); i.hasNext(); ) {
MailAliasBeforeDeleteListener listener = (MailAliasBeforeDeleteListener)i.next();
Collection subcascade = listener.mailAliasBeforeDelete(editor, mailAlias, known);
if(subcascade != null)
cascade.addAll(subcascade);
}
 
return cascade;
}
 
public void delete(User editor, MailAlias mailAlias)
throws ModelException
{
// check rights
if(!mailAlias.deleteableBy(editor))
throw new ModelSecurityException();
 
// backup copy
MailAlias oldMailAlias = new MailAlias(mailAlias);
 
// delete it
try {
HibernateUtil.currentSession().delete(mailAlias);
}
145,6 → 240,12
{
throw new ModelException(ex);
}
 
// inform listeners
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) {
MailAliasDeletedListener listener = (MailAliasDeletedListener)i.next();
listener.mailAliasDeleted(editor, oldMailAlias);
}
}
 
public Collection listMailAliases(User editor)
190,14 → 291,45
}
}
 
private static MailAliasManager mailAliasManager = null;
public Collection userBeforeDelete(User editor, User user, Collection known)
throws ModelException
{
Collection mailAliases;
 
public static MailAliasManager getInstance()
try {
mailAliases = HibernateUtil.currentSession().find(
"from MailAlias where owner = ?",
user, Hibernate.entity(User.class) );
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
return iterateBeforeDelete(editor, mailAliases, known);
}
 
private Collection iterateBeforeDelete(User editor, Collection mailAliases, Collection known)
throws ModelException
{
if(mailAliasManager == null)
mailAliasManager = new MailAliasManager();
Collection cascade = new ArrayList();
for(Iterator i = mailAliases.iterator(); i.hasNext(); ) {
MailAlias mailAlias = (MailAlias)i.next();
if(mailAlias.viewableBy(editor)) {
if(mailAlias.deleteableBy(editor))
cascade.add(new CascadeDeleteElement(mailAlias, CascadeDeleteElement.DELETE,
this.beforeDelete(editor, mailAlias, known)));
else
cascade.add(new CascadeDeleteElement(mailAlias, CascadeDeleteElement.FORBIDDEN,
null));
}
else {
cascade.add(new CascadeDeleteElement(MailAlias.createLimitedCopy(mailAlias),
CascadeDeleteElement.FORBIDDEN, null));
}
}
 
return mailAliasManager;
return cascade;
}
 
public static final Comparator ADDRESS_COMPARATOR = new AddressComparator();
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxDeletedListener.java
0,0 → 1,20
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface MailboxDeletedListener
{
/**
* called if some mailbox is just deleted.
*
* @param editor who is doing the operation
* @param mailbox the mailbox deleted
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other MailboxDeletedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void mailboxDeleted(User editor, Mailbox mailbox)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxCreatedListener.java
0,0 → 1,20
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface MailboxCreatedListener
{
/**
* called if new mailbox is just created.
*
* @param editor who is doing the operation
* @param mailbox the new mailbox
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other MailboxCreatedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void mailboxCreated(User editor, Mailbox mailbox)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/SystemUserModifiedListener.java
0,0 → 1,21
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface SystemUserModifiedListener
{
/**
* called if some system user is just changed.
*
* @param editor who is doing the operation
* @param systemUser the system user in its new state
* @param oldSystemUser copy of system user as it was before the operation
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other SystemUserCreatedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void systemUserModified(User editor, SystemUser systemUser, SystemUser oldSystemUser)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxModifiedListener.java
0,0 → 1,21
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface MailboxModifiedListener
{
/**
* called if some mailbox is just changed.
*
* @param editor who is doing the operation
* @param mailbox the mailbox in its new state
* @param oldMailbox copy of mailbox as it was before the operation
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other MailboxCreatedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void mailboxModified(User editor, Mailbox mailbox, Mailbox oldMailbox)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasModifiedListener.java
0,0 → 1,21
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface MailAliasModifiedListener
{
/**
* called if some mail alias is just changed.
*
* @param editor who is doing the operation
* @param mailAlias the mail alias in its new state
* @param oldMailAlias copy of mail alias as it was before the operation
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other MailAliasCreatedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void mailAliasModified(User editor, MailAlias mailAlias, MailAlias oldMailAlias)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/SystemUserManager.java
41,7 → 41,10
register();
}
 
private Collection createdListeners = new ArrayList();
private Collection modifiedListeners = new ArrayList();
private Collection beforeDeleteListeners = new ArrayList();
private Collection deletedListeners = new ArrayList();
 
private SystemUserManager()
{
167,6 → 170,8
if(!systemUser.editableBy(editor))
throw new ModelSecurityException();
 
boolean isNew = systemUser.isNew();
 
//systemUser.setModUser(editor); // FIXME
 
try {
176,8 → 181,44
{
throw new ModelException(ex);
}
 
// inform listeners
if(isNew) {
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) {
SystemUserCreatedListener listener = (SystemUserCreatedListener)i.next();
listener.systemUserCreated(editor, systemUser);
}
}
else {
SystemUser oldSystemUser = systemUser.getOrigin();
if(oldSystemUser == null) oldSystemUser = systemUser;
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) {
SystemUserModifiedListener listener = (SystemUserModifiedListener)i.next();
listener.systemUserModified(editor, systemUser, oldSystemUser);
}
}
}
 
public void addCreatedListener(SystemUserCreatedListener listener)
{
createdListeners.add(listener);
}
 
public void removeCreatedListener(SystemUserCreatedListener listener)
{
createdListeners.remove(listener);
}
 
public void addModifiedListener(SystemUserModifiedListener listener)
{
modifiedListeners.add(listener);
}
 
public void removeModifiedListener(SystemUserModifiedListener listener)
{
modifiedListeners.remove(listener);
}
 
public void addBeforeDeleteListener(SystemUserBeforeDeleteListener listener)
{
beforeDeleteListeners.add(listener);
188,6 → 229,16
beforeDeleteListeners.remove(listener);
}
 
public void addDeletedListener(SystemUserDeletedListener listener)
{
deletedListeners.add(listener);
}
 
public void removeDeletedListener(SystemUserDeletedListener listener)
{
deletedListeners.remove(listener);
}
 
public Collection beforeDelete(User editor, SystemUser user, Collection known)
throws ModelException
{
206,9 → 257,14
public void delete(User editor, SystemUser systemUser)
throws ModelException
{
// check rights
if(!systemUser.deleteableBy(editor))
throw new ModelSecurityException();
 
// backup copy
SystemUser oldSystemUser = new SystemUser(systemUser);
 
// delete it
try {
HibernateUtil.currentSession().delete(systemUser);
}
216,6 → 272,12
{
throw new ModelException(ex);
}
 
// inform listeners
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) {
SystemUserDeletedListener listener = (SystemUserDeletedListener)i.next();
listener.systemUserDeleted(editor, oldSystemUser);
}
}
 
public Collection listSystemUsers(User editor)
/hostadmiral/trunk/src/ak/hostadmiral/core/model/User.java
23,7 → 23,7
private Boolean superuser;
private Locale locale = Locale.getDefault();
private Collection loginHistory;
private User origin; // save original object state before any changes
private User origin; // save original object state before any changes
 
protected User()
{
/hostadmiral/trunk/src/ak/hostadmiral/core/model/SystemUser.java
11,14 → 11,34
extends GeneralModelObject
{
/** user id in the OS */
private Integer uid;
private String name;
private User owner;
private Integer uid;
private String name;
private User owner;
private SystemUser origin; // save original object state before any changes
 
protected SystemUser()
{
}
 
protected SystemUser(SystemUser origin)
{
super(origin);
this.uid = origin.uid;
this.name = origin.name;
this.owner = origin.owner;
}
 
protected SystemUser getOrigin()
{
return origin;
}
 
protected void backupMe()
{
if(origin == null)
origin = new SystemUser(this);
}
 
/**
*
* @hibernate.property
/hostadmiral/trunk/src/ak/hostadmiral/core/model/InetDomainDeletedListener.java
0,0 → 1,20
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface InetDomainDeletedListener
{
/**
* called if some domain is just deleted.
*
* @param editor who is doing the operation
* @param domain the domain deleted
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other InetDomainDeletedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void inetDomainDeleted(User editor, InetDomain domain)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/InetDomainCreatedListener.java
0,0 → 1,20
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface InetDomainCreatedListener
{
/**
* called if new domain is just created.
*
* @param editor who is doing the operation
* @param domain the new domain
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other InetDomainCreatedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void inetDomainCreated(User editor, InetDomain domain)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxManager.java
44,7 → 44,10
register();
}
 
private Collection createdListeners = new ArrayList();
private Collection modifiedListeners = new ArrayList();
private Collection beforeDeleteListeners = new ArrayList();
private Collection deletedListeners = new ArrayList();
 
private MailboxManager()
{
137,6 → 140,8
if(!mailbox.editableBy(editor))
throw new ModelSecurityException();
 
boolean isNew = mailbox.isNew();
 
//mailbox.setModUser(editor); // FIXME
 
try {
146,8 → 151,44
{
throw new ModelException(ex);
}
 
// inform listeners
if(isNew) {
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) {
MailboxCreatedListener listener = (MailboxCreatedListener)i.next();
listener.mailboxCreated(editor, mailbox);
}
}
else {
Mailbox oldMailbox = mailbox.getOrigin();
if(oldMailbox == null) oldMailbox = mailbox;
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) {
MailboxModifiedListener listener = (MailboxModifiedListener)i.next();
listener.mailboxModified(editor, mailbox, oldMailbox);
}
}
}
 
public void addCreatedListener(MailboxCreatedListener listener)
{
createdListeners.add(listener);
}
 
public void removeCreatedListener(MailboxCreatedListener listener)
{
createdListeners.remove(listener);
}
 
public void addModifiedListener(MailboxModifiedListener listener)
{
modifiedListeners.add(listener);
}
 
public void removeModifiedListener(MailboxModifiedListener listener)
{
modifiedListeners.remove(listener);
}
 
public void addBeforeDeleteListener(MailboxBeforeDeleteListener listener)
{
beforeDeleteListeners.add(listener);
158,6 → 199,16
beforeDeleteListeners.remove(listener);
}
 
public void addDeletedListener(MailboxDeletedListener listener)
{
deletedListeners.add(listener);
}
 
public void removeDeletedListener(MailboxDeletedListener listener)
{
deletedListeners.remove(listener);
}
 
public Collection beforeDelete(User editor, Mailbox mailbox, Collection known)
throws ModelException
{
176,9 → 227,14
public void delete(User editor, Mailbox mailbox)
throws ModelException
{
// check rights
if(!mailbox.deleteableBy(editor))
throw new ModelSecurityException();
 
// backup copy
Mailbox oldMailbox = new Mailbox(mailbox);
 
// delete it
try {
HibernateUtil.currentSession().delete(mailbox);
}
186,6 → 242,12
{
throw new ModelException(ex);
}
 
// inform listeners
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) {
MailboxDeletedListener listener = (MailboxDeletedListener)i.next();
listener.mailboxDeleted(editor, oldMailbox);
}
}
 
public Collection listMailboxes(User editor)
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasDestinationManager.java
8,6 → 8,9
 
public class MailAliasDestinationManager
{
// FIXME create, delete and modify listeners are not implemented, bacause
// all operations are done via MailAliasManager. Do we need them?
 
private static boolean registered = false;
protected static void register()
{
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasDeletedListener.java
0,0 → 1,20
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface MailAliasDeletedListener
{
/**
* called if some mail alias is just deleted.
*
* @param editor who is doing the operation
* @param mailAlias the mail alias deleted
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other MailAliasDeletedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void mailAliasDeleted(User editor, MailAlias mailAlias)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasCreatedListener.java
0,0 → 1,20
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
 
public interface MailAliasCreatedListener
{
/**
* called if new mail alias is just created.
*
* @param editor who is doing the operation
* @param mailAlias the new mail alias
* @throws ModelException in case of any *fatal* errors,
* Note: throw it on fatal errors only, because database transaction
* will be rolled back but any other MailAliasCreatedListeners might be already called
* and (possible) they will not restore their original state.
*/
public void mailAliasCreated(User editor, MailAlias mailAlias)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/Mailbox.java
18,11 → 18,35
private Boolean virusCheck;
private Boolean spamCheck;
private SystemUser systemUser;
private Mailbox origin; // save original object state before any changes
 
protected Mailbox()
{
}
 
protected Mailbox(Mailbox origin)
{
super(origin);
this.login = origin.login;
this.password = origin.password;
this.domain = origin.domain;
this.owner = origin.owner;
this.virusCheck = origin.virusCheck;
this.spamCheck = origin.spamCheck;
this.systemUser = origin.systemUser;
}
 
protected Mailbox getOrigin()
{
return origin;
}
 
protected void backupMe()
{
if(origin == null)
origin = new Mailbox(this);
}
 
/**
*
* @hibernate.property
43,6 → 67,7
if(!editableBy(editor))
throw new ModelSecurityException();
 
backupMe();
this.login = login;
}
 
66,6 → 91,7
if(password == null)
throw new NullPointerException("Null password");
 
backupMe();
this.password = Digest.encode(password);
}
 
89,6 → 115,7
if(!editableBy(editor))
throw new ModelSecurityException();
 
backupMe();
this.domain = domain;
}
 
112,6 → 139,7
if(!editableBy(editor))
throw new ModelSecurityException();
 
backupMe();
this.owner = owner;
}
 
135,6 → 163,7
if(!editableBy(editor))
throw new ModelSecurityException();
 
backupMe();
this.virusCheck = virusCheck;
}
 
158,6 → 187,7
if(!editableBy(editor))
throw new ModelSecurityException();
 
backupMe();
this.spamCheck = spamCheck;
}
 
181,6 → 211,7
if(!editableBy(editor))
throw new ModelSecurityException();
 
backupMe();
this.systemUser = systemUser;
}
 
225,9 → 256,10
 
protected static Mailbox createLimitedCopy(Mailbox origin)
{
Mailbox u = new Mailbox();
u.setLogin(origin.getLogin());
u.setDomain(origin.getDomain());
return u;
Mailbox m = new Mailbox();
m.setLogin(origin.getLogin());
m.setDomain(origin.getDomain());
m.setOwner(origin.getOwner());
return m;
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAlias.java
15,11 → 15,32
private InetDomain domain;
private User owner;
private Collection destinations; // Collection(MailAliasDestintion)
private MailAlias origin; // save original object state before any changes
 
protected MailAlias()
{
}
 
protected MailAlias(MailAlias origin)
{
super(origin);
this.address = origin.address;
this.domain = origin.domain;
this.owner = origin.owner;
this.destinations = origin.destinations; // FIXME: or make a copy?
}
 
protected MailAlias getOrigin()
{
return origin;
}
 
protected void backupMe()
{
if(origin == null)
origin = new MailAlias(this);
}
 
/**
*
* @hibernate.property
166,4 → 187,13
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
 
protected static MailAlias createLimitedCopy(MailAlias origin)
{
MailAlias m = new MailAlias();
m.setAddress(origin.getAddress());
m.setDomain(origin.getDomain());
m.setOwner(origin.getOwner());
return m;
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/file/UserDeletedFileListener.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/file/UserModifiedFileListener.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/file/UserCreatedFileListener.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/file/InterfaceFile.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/file/ConfigServlet.java
16,7 → 16,7
public void init()
throws ServletException
{
InterfaceFile.setFileName(getInitParameter("fileName"));
FileListener.setFileName(getInitParameter("fileName"));
}
 
public void service(ServletRequest req, ServletResponse res)
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/file/FileListener.java
0,0 → 1,240
package ak.hostadmiral.core.listener.file;
 
import java.util.Collection;
import java.util.Iterator;
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.FileWriter;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.core.model.*;
 
import org.apache.log4j.Logger;
 
public class FileListener
implements
UserCreatedListener,
UserModifiedListener,
UserDeletedListener
{
private static final Logger logger = Logger.getLogger(FileListener.class);
 
private static String fileName;
protected static Object lock = new Object();
 
public static final String PROTOCOL_NAME = "HostAdmiral_FileListener";
public static final String PROTOCOL_VERSION = "0.1";
 
public static String getFileName()
{
return fileName;
}
 
public static void setFileName(String fileName_)
{
fileName = fileName_;
}
 
protected static String escape(String s)
{
// FIXME: any other problem characters? optimize it?
s = s.replaceAll("\0", "\\\\0");
s = s.replaceAll("\\\\", "\\\\\\\\");
s = s.replaceAll("\t", "\\\\t");
s = s.replaceAll("\n", "\\\\n");
return s;
}
 
protected static void send(String message)
throws ModelException
{
synchronized(lock) {
try {
Writer out = new BufferedWriter(new FileWriter(fileName));
if(PROTOCOL_NAME != null) {
out.write(PROTOCOL_NAME);
out.write(" ");
}
if(PROTOCOL_VERSION != null) {
out.write(PROTOCOL_VERSION);
out.write("\n");
}
out.write(message);
out.write("\n\n");
out.close();
}
catch(Exception ex) {
logger.error("Cannot save message to file", ex);
throw new ModelException("Cannot save message to file:" + ex.getMessage());
// FIMXE: or just throw "internal server error" message?
}
}
}
 
//=== user ====================================================================================
 
public void userCreated(User editor, User user)
throws ModelException
{
send("user\tcreate\t" + escape(user.getLogin()) + "\t"
+ escape(/* FIXME user.getPassword() */ "") + "\t"
+ user.getEnabled() + "\t"
+ escape(user.getComment()));
}
 
public void userModified(User editor, User user, User oldUser)
throws ModelException
{
send("user\tmodify\t" + escape(oldUser.getLogin()) + "\t"
+ escape(user.getLogin()) + "\t"
+ escape(/* FIXME user.getPassword() */ "") + "\t"
+ user.getEnabled() + "\t"
+ escape(user.getComment()));
}
 
public void userDeleted(User editor, User user)
throws ModelException
{
send("user\tdelete\t" + escape(user.getLogin()));
}
 
//=== inet domain =============================================================================
 
public void inetDomainCreated(User editor, InetDomain domain)
throws ModelException
{
send("inetDomain\tcreate\t" + escape(domain.getName()) + "\t"
+ domain.getEnabled() + "\t"
+ escape(domain.getComment()));
}
 
public void inetDomainModified(User editor, InetDomain domain, InetDomain oldDomain)
throws ModelException
{
send("inetDomain\tmodify\t" + escape(oldDomain.getName()) + "\t"
+ escape(domain.getName()) + "\t"
+ domain.getEnabled() + "\t"
+ escape(domain.getComment()));
}
 
public void inetDomainDeleted(User editor, InetDomain domain)
throws ModelException
{
send("inetDomain\tdelete\t" + escape(domain.getName()));
}
 
//=== system user =============================================================================
 
public void systemUserCreated(User editor, SystemUser systemUser)
throws ModelException
{
send("systemUser\tcreate\t" + systemUser.getUid() + "\t"
+ escape(systemUser.getName()) + "\t"
+ systemUser.getEnabled() + "\t"
+ escape(systemUser.getComment()));
}
 
public void systemUserModified(User editor, SystemUser systemUser, SystemUser oldSystemUser)
throws ModelException
{
send("systemUser\tmodify\t" + oldSystemUser.getUid() + "\t"
+ escape(oldSystemUser.getName()) + "\t"
+ systemUser.getUid() + "\t"
+ escape(systemUser.getName()) + "\t"
+ systemUser.getEnabled() + "\t"
+ escape(systemUser.getComment()));
}
 
public void systemUserDeleted(User editor, SystemUser systemUser)
throws ModelException
{
send("systemUser\tdelete\t" + systemUser.getUid() + "\t" + escape(systemUser.getName()));
}
 
//=== mailbox =================================================================================
 
public void mailboxCreated(User editor, Mailbox mailbox)
throws ModelException
{
send("mailbox\tcreate\t" + escape(mailbox.getLogin()) + "\t"
+ escape(/* FIXME user.getPassword() */ "") + "\t"
+ escape(mailbox.getDomain().getName()) + "\t"
+ mailbox.getVirusCheck() + "\t"
+ mailbox.getSpamCheck() + "\t"
+ mailbox.getSystemUser().getUid() + "\t"
+ mailbox.getEnabled() + "\t"
+ escape(mailbox.getComment()));
}
 
public void mailboxModified(User editor, Mailbox mailbox, Mailbox oldMailbox)
throws ModelException
{
send("mailbox\tmodify\t" + escape(oldMailbox.getLogin()) + "\t"
+ escape(oldMailbox.getDomain().getName()) + "\t"
+ escape(mailbox.getLogin()) + "\t"
+ escape(/* FIXME user.getPassword() */ "") + "\t"
+ escape(mailbox.getDomain().getName()) + "\t"
+ mailbox.getVirusCheck() + "\t"
+ mailbox.getSpamCheck() + "\t"
+ mailbox.getSystemUser().getUid() + "\t"
+ mailbox.getEnabled() + "\t"
+ escape(mailbox.getComment()));
}
 
public void mailboxDeleted(User editor, Mailbox mailbox)
throws ModelException
{
send("mailbox\tdelete\t" + escape(mailbox.getLogin()) + "\t"
+ escape(mailbox.getDomain().getName()));
}
 
//=== mail alias ==============================================================================
 
private String formMailAliasDestinations(User editor, MailAlias mailAlias)
throws ModelException
{
StringBuffer b = new StringBuffer();
 
Collection dests = mailAlias.getDestinations(editor);
if(dests != null) {
for(Iterator i = dests.iterator(); i.hasNext(); ) {
MailAliasDestination d = (MailAliasDestination)i.next();
b.append("\n\t");
if(d.getMailbox() != null)
b.append(escape(d.getMailbox().getLogin())).append("@").append(escape(d.getMailbox().getDomain().getName()));
else
b.append(escape(d.getEmail()));
}
}
 
return b.toString();
}
 
public void mailAliasCreated(User editor, MailAlias mailAlias)
throws ModelException
{
send(" mailAlias\tcreate\t" + escape(mailAlias.getAddress()) + "\t"
+ escape(mailAlias.getDomain().getName()) + "\t"
+ mailAlias.getEnabled() + "\t"
+ escape(mailAlias.getComment())
+ formMailAliasDestinations(editor, mailAlias));
}
 
public void mailAliasModified(User editor, MailAlias mailAlias, MailAlias oldMailAlias)
throws ModelException
{
send(" mailAlias\tmodify\t" + escape(oldMailAlias.getAddress()) + "\t"
+ escape(oldMailAlias.getDomain().getName()) + "\t"
+ escape(mailAlias.getAddress()) + "\t"
+ escape(mailAlias.getDomain().getName()) + "\t"
+ mailAlias.getEnabled() + "\t"
+ escape(mailAlias.getComment())
+ formMailAliasDestinations(editor, mailAlias));
}
 
public void mailAliasDeleted(User editor, MailAlias mailAlias)
throws ModelException
{
send(" mailAlias\tdelete\t" + escape(mailAlias.getAddress())+ "\t"
+ escape(mailAlias.getDomain().getName()));
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/dummy/UserCreatedDummyListener.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/dummy/UserDeletedDummyListener.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/dummy/UserModifiedDummyListener.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/listener/dummy/DummyListener.java
0,0 → 1,139
package ak.hostadmiral.core.listener.dummy;
 
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.core.model.*;
 
public class DummyListener
implements
UserCreatedListener,
UserModifiedListener,
UserDeletedListener,
InetDomainCreatedListener,
InetDomainModifiedListener,
InetDomainDeletedListener,
SystemUserCreatedListener,
SystemUserModifiedListener,
SystemUserDeletedListener,
MailboxCreatedListener,
MailboxModifiedListener,
MailboxDeletedListener,
MailAliasCreatedListener,
MailAliasModifiedListener,
MailAliasDeletedListener
{
//=== user ====================================================================================
 
public void userCreated(User editor, User user)
throws ModelException
{
System.out.println("DummyListener.userCreated: "
+ user + " by " + editor);
}
 
public void userModified(User editor, User user, User oldUser)
throws ModelException
{
System.out.println("DummyListener.userModified: from " + oldUser
+ " to " + user + " by " + editor);
}
 
public void userDeleted(User editor, User user)
throws ModelException
{
System.out.println("DummyListener.userDeleted: "
+ user + " by " + editor);
}
 
//=== inet domain =============================================================================
 
public void inetDomainCreated(User editor, InetDomain domain)
throws ModelException
{
System.out.println("DummyListener.inetDomainCreated: "
+ domain + " by " + editor);
}
 
public void inetDomainModified(User editor, InetDomain domain, InetDomain oldDomain)
throws ModelException
{
System.out.println("DummyListener.inetDomainModified: from " + oldDomain
+ " to " + domain + " by " + editor);
}
 
public void inetDomainDeleted(User editor, InetDomain domain)
throws ModelException
{
System.out.println("DummyListener.inetDomainDeleted: "
+ domain + " by " + editor);
}
 
//=== system user =============================================================================
 
public void systemUserCreated(User editor, SystemUser systemUser)
throws ModelException
{
System.out.println("DummyListener.systemUserCreated: "
+ systemUser + " by " + editor);
}
 
public void systemUserModified(User editor, SystemUser systemUser, SystemUser oldSystemUser)
throws ModelException
{
System.out.println("DummyListener.systemUserModified: from " + oldSystemUser
+ " to " + systemUser + " by " + editor);
}
 
public void systemUserDeleted(User editor, SystemUser systemUser)
throws ModelException
{
System.out.println("DummyListener.systemUserDeleted: "
+ systemUser + " by " + editor);
}
 
//=== mailbox =================================================================================
 
public void mailboxCreated(User editor, Mailbox mailbox)
throws ModelException
{
System.out.println("DummyListener.mailboxCreated: "
+ mailbox + " by " + editor);
}
 
public void mailboxModified(User editor, Mailbox mailbox, Mailbox oldMailbox)
throws ModelException
{
System.out.println("DummyListener.mailboxModified: from " + oldMailbox
+ " to " + mailbox + " by " + editor);
}
 
public void mailboxDeleted(User editor, Mailbox mailbox)
throws ModelException
{
System.out.println("DummyListener.mailboxDeleted: "
+ mailbox + " by " + editor);
}
 
//=== mail alias ==============================================================================
 
public void mailAliasCreated(User editor, MailAlias mailAlias)
throws ModelException
{
System.out.println("DummyListener.mailAliasCreated: "
+ mailAlias + " by " + editor);
}
 
public void mailAliasModified(User editor, MailAlias mailAlias, MailAlias oldMailAlias)
throws ModelException
{
System.out.println("DummyListener.mailAliasModified: from " + oldMailAlias
+ " to " + mailAlias + " by " + editor);
}
 
public void mailAliasDeleted(User editor, MailAlias mailAlias)
throws ModelException
{
System.out.println("DummyListener.mailAliasDeleted: "
+ mailAlias + " by " + editor);
}
 
}
/hostadmiral/trunk/build.xml
1,6 → 1,6
<project name="hostadmiral" default="deploy" basedir=".">
 
<property name="build.compiler" value="jikes" />
<!--property name="build.compiler" value="jikes" /-->
 
<property name="src" location="src" />
<property name="classes" location="classes" />
/hostadmiral/trunk/webapp/WEB-INF/web.xml
84,24 → 84,96
<init-param>
<param-name>UserCreatedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.UserCreatedDummyListener;
ak.hostadmiral.core.listener.file.UserCreatedFileListener;
ak.hostadmiral.core.listener.dummy.DummyListener;
ak.hostadmiral.core.listener.file.FileListener;
</param-value>
</init-param>
<init-param>
<param-name>UserModifiedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.UserModifiedDummyListener;
ak.hostadmiral.core.listener.file.UserModifiedFileListener;
ak.hostadmiral.core.listener.dummy.DummyListener;
ak.hostadmiral.core.listener.file.FileListener;
</param-value>
</init-param>
<init-param>
<param-name>UserDeletedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.UserDeletedDummyListener;
ak.hostadmiral.core.listener.file.UserDeletedFileListener;
ak.hostadmiral.core.listener.dummy.DummyListener;
ak.hostadmiral.core.listener.file.FileListener;
</param-value>
</init-param>
<init-param>
<param-name>InetDomainCreatedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>InetDomainModifiedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>InetDomainDeletedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>SystemUserCreatedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>SystemUserModifiedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>SystemUserDeletedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>MailboxCreatedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>MailboxModifiedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>MailboxDeletedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>MailAliasCreatedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>MailAliasModifiedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<init-param>
<param-name>MailAliasDeletedListener</param-name>
<param-value>
ak.hostadmiral.core.listener.dummy.DummyListener;
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>