/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasDestinationManager.java |
---|
74,7 → 74,7 |
if(!mailAliasDestination.editableBy(editor)) |
throw new ModelSecurityException(); |
mailAliasDestination.setModUser(editor); |
//mailAliasDestination.setModUser(editor); // FIXME |
// FIXME: the mod_user is not set when changing a destination as element of collection |
try { |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/TransactionController.java |
---|
0,0 → 1,34 |
package ak.hostadmiral.core.model; |
import java.util.Map; |
import java.util.HashMap; |
import ak.hostadmiral.util.ModelException; |
// FIXME: implement it |
public class TransactionController |
{ |
private static TransactionController transactionController = null; |
public static TransactionController getInstance() |
{ |
return transactionController; |
} |
private Map listeners = new HashMap(); |
public void beginTransaction(Object transaction) |
{ |
} |
public void commitTransaction(Object transaction) |
{ |
} |
public void rollbackTransaction(Object transaction) |
{ |
} |
public void addObject(Object transaction, Object object) |
{ |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/Mailbox.java |
---|
206,7 → 206,9 |
public boolean editableBy(User user) |
{ |
return user.isSuperuser() || user.equals(domain.getOwner()); |
return user.isSuperuser() |
|| (domain == null) // just created |
|| user.equals(domain.getOwner()); |
} |
public boolean deleteableBy(User user) |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/TransactionListener.java |
---|
0,0 → 1,43 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
/** |
* One could implement this interface to receive transaction start, commit and |
* rollback events. |
* An object will be informed about this events if it actualy interacts with the |
* transaction, e.g. if it is registered as listener for object modifications. |
*/ |
public interface TransactionListener |
{ |
/** |
* called when this object first time interacts with given transaction, |
* before any other callbacks of this object in the transaction |
* |
* @param id some transaction identifier, the same for all transaction* methods |
* @throws ModelException if transaction must be aborted immediately |
*/ |
public void transactionBegin(Object id) |
throws ModelException; |
/** |
* called when transaction is commited |
* |
* @param id some transaction identifier, the same as in corresponding transactionBegin |
* method call |
* @throws ModelException logged, but ignored |
*/ |
public void transactionCommited(Object id) |
throws ModelException; |
/** |
* called when transaction is rolled back |
* |
* @param id some transaction identifier, the same as in corresponding transactionBegin |
* method call |
* @throws ModelException logged, but ignored |
*/ |
public void transactionRolledBack(Object id) |
throws ModelException; |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAlias.java |
---|
145,7 → 145,9 |
public boolean editableBy(User user) |
{ |
return user.isSuperuser() || user.equals(domain.getOwner()); |
return user.isSuperuser() |
|| (domain == null) // just created |
|| user.equals(domain.getOwner()); |
} |
public boolean mayChangeDestinations(User user) |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserManager.java |
---|
25,11 → 25,12 |
registered = true; |
try { |
/* |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/User.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/UserLogin.hbm.xml"); |
*/ |
userManager = new UserManager(); |
} |
catch(Exception ex) { |
43,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 Map loggedinUsers = new WeakHashMap(); |
private UserManager() |
56,9 → 60,15 |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
return new User(); |
User user = new User(); |
if(!user.mayChangeBoss(editor)) { // ordinal user can create only own "subusers" |
user.setBoss(editor); |
} |
return user; |
} |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
73,8 → 83,7 |
try { |
user = (User)HibernateUtil.currentSession().load(User.class, id); |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
100,8 → 109,7 |
new Type[] { Hibernate.STRING, Hibernate.entity(User.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
} |
120,8 → 128,7 |
else |
return (User)list.get(0); |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
} |
135,13 → 142,15 |
throw new ModelSecurityException(); |
} |
user.setModUser(editor); |
boolean isNew = user.isNew(); |
//user.setModUser(editor); // FIXME: disabled because hb throws exception |
// if user edits itself |
try { |
HibernateUtil.currentSession().saveOrUpdate(user); |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
151,8 → 160,44 |
if(u.equals(user)) |
u.update(user); |
} |
// inform listeners |
if(isNew) { |
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) { |
UserCreatedListener listener = (UserCreatedListener)i.next(); |
listener.userCreated(editor, user); |
} |
} |
else { |
User oldUser = user.getOrigin(); |
if(oldUser == null) oldUser = user; |
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) { |
UserModifiedListener listener = (UserModifiedListener)i.next(); |
listener.userModified(editor, user, oldUser); |
} |
} |
} |
public void addCreatedListener(UserCreatedListener listener) |
{ |
createdListeners.add(listener); |
} |
public void removeCreatedListener(UserCreatedListener listener) |
{ |
createdListeners.remove(listener); |
} |
public void addModifiedListener(UserModifiedListener listener) |
{ |
modifiedListeners.add(listener); |
} |
public void removeModifiedListener(UserModifiedListener listener) |
{ |
modifiedListeners.remove(listener); |
} |
public void addBeforeDeleteListener(UserBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.add(listener); |
163,6 → 208,16 |
beforeDeleteListeners.remove(listener); |
} |
public void addDeletedListener(UserDeletedListener listener) |
{ |
deletedListeners.add(listener); |
} |
public void removeDeletedListener(UserDeletedListener listener) |
{ |
deletedListeners.remove(listener); |
} |
public Collection beforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
181,17 → 236,27 |
public void delete(User editor, User user) |
throws ModelException |
{ |
// chech rights |
if(!user.deleteableBy(editor)) |
throw new ModelSecurityException(); |
// backup copy |
User oldUser = new User(user); |
// delete it |
try { |
HibernateUtil.currentSession().delete(user); |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
// inform listeners |
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) { |
UserDeletedListener listener = (UserDeletedListener)i.next(); |
listener.userDeleted(editor, oldUser); |
} |
} |
public Collection listUsers(User editor) |
throws ModelException |
207,8 → 272,7 |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } ); |
} |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
} |
228,8 → 292,7 |
.next()).intValue() > 0; |
} |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
} |
245,12 → 308,12 |
try { |
HibernateUtil.currentSession().saveOrUpdate(userLogin); |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
if(success) { |
user = new User(user); // unbind the user from hibernate |
loggedinUsers.put(user, Boolean.TRUE); |
return user; |
} |
272,8 → 335,7 |
"from UserLogin where success = ?", |
Boolean.FALSE, Hibernate.BOOLEAN); |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
} |
288,8 → 350,7 |
"from User where boss = ?", |
user, Hibernate.entity(User.class) ); |
} |
catch(HibernateException ex) |
{ |
catch(HibernateException ex) { |
throw new ModelException(ex); |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserDeletedListener.java |
---|
0,0 → 1,20 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
public interface UserDeletedListener |
{ |
/** |
* called if some user is just deleted. |
* |
* @param editor who is doing the operation |
* @param user the 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 UserDeletedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void userDeleted(User editor, User user) |
throws ModelException; |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserCreatedListener.java |
---|
0,0 → 1,20 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
public interface UserCreatedListener |
{ |
/** |
* called if new user is just created. |
* |
* @param editor who is doing the operation |
* @param user the new 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 UserCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void userCreated(User editor, User user) |
throws ModelException; |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/User.java |
---|
2,6 → 2,7 |
import java.util.Collection; |
import java.util.Collections; |
import java.util.HashSet; |
import java.util.Locale; |
import java.util.StringTokenizer; |
22,11 → 23,37 |
private Boolean superuser; |
private Locale locale = Locale.getDefault(); |
private Collection loginHistory; |
private User origin; // save original object state before any changes |
protected User() |
{ |
} |
protected User(User origin) |
{ |
super(origin); |
this.login = origin.login; |
this.password = origin.password; |
this.boss = origin.boss; |
this.superuser = origin.superuser; |
this.locale = origin.locale; |
if(origin.loginHistory == null) |
this.loginHistory = null; |
else |
this.loginHistory = new HashSet(origin.loginHistory); |
} |
protected User getOrigin() |
{ |
return origin; |
} |
protected void backupMe() |
{ |
if(origin == null) |
origin = new User(this); |
} |
/** |
* |
* @hibernate.property |
47,6 → 74,10 |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
// FIXME: domain owner is allowed to change user login |
// with some patern only, e.g. user@domain.com |
backupMe(); |
this.login = login; |
} |
73,6 → 104,7 |
if(password == null) |
throw new NullPointerException("Null password"); |
backupMe(); |
this.password = Digest.encode(password); |
} |
106,9 → 138,10 |
public void setBoss(User editor, User boss) |
throws ModelException |
{ |
if(!editableBy(editor)) |
if(!mayChangeBoss(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.boss = boss; |
} |
137,6 → 170,7 |
if(!mayChangeSuperuser(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.superuser = superuser; |
} |
174,6 → 208,7 |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
setLocaleName(localeName); |
} |
188,6 → 223,7 |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.locale = locale; |
} |
272,6 → 308,11 |
return user.isSuperuser() || user.equals(boss) || user.equals(this); |
} |
public boolean mayChangeBoss(User user) |
{ |
return user.isSuperuser(); |
} |
public boolean mayChangeSuperuser(User user) |
{ |
return user.isSuperuser() && !user.equals(this); |
285,7 → 326,9 |
protected static boolean allowedToCreate(UserManager manager, User editor) |
throws ModelException |
{ |
return editor.isSuperuser(); |
return editor.isSuperuser() |
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor); |
// FIXME: or allow any user to create "subusers"? |
} |
protected static User createLimitedCopy(User origin) |
294,4 → 337,9 |
u.setLogin(origin.getLogin()); |
return u; |
} |
public String toString() |
{ |
return getClass().getName() + " [" + getId() + "] [" + getLogin() + "]"; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/SystemUserManager.java |
---|
167,7 → 167,7 |
if(!systemUser.editableBy(editor)) |
throw new ModelSecurityException(); |
systemUser.setModUser(editor); |
//systemUser.setModUser(editor); // FIXME |
try { |
HibernateUtil.currentSession().saveOrUpdate(systemUser); |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/InetDomainManager.java |
---|
128,7 → 128,7 |
if(!domain.editableBy(editor)) |
throw new ModelSecurityException(); |
domain.setModUser(editor); |
//domain.setModUser(editor); // FIXME |
try { |
HibernateUtil.currentSession().saveOrUpdate(domain); |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserModifiedListener.java |
---|
0,0 → 1,21 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
public interface UserModifiedListener |
{ |
/** |
* called if some user is just changed. |
* |
* @param editor who is doing the operation |
* @param user the user in its new state |
* @param oldUser copy of 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 UserCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void userModified(User editor, User user, User oldUser) |
throws ModelException; |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/GeneralModelObject.java |
---|
13,7 → 13,28 |
private Date modStamp; |
private User modUser; |
protected GeneralModelObject() |
{ |
} |
protected GeneralModelObject(GeneralModelObject origin) |
{ |
this.id = origin.id; |
this.enabled = origin.enabled; |
this.comment = origin.comment; |
this.modStamp = origin.modStamp; |
this.modUser = origin.modUser; |
} |
/** |
* @return true if the object is not yet saved in DB |
*/ |
public boolean isNew() |
{ |
return (id == null); |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxManager.java |
---|
137,7 → 137,7 |
if(!mailbox.editableBy(editor)) |
throw new ModelSecurityException(); |
mailbox.setModUser(editor); |
//mailbox.setModUser(editor); // FIXME |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailbox); |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasManager.java |
---|
121,7 → 121,7 |
if(!mailAlias.editableBy(editor)) |
throw new ModelSecurityException(); |
mailAlias.setModUser(editor); |
//mailAlias.setModUser(editor); // FIXME |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAlias); |