/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserCreatedListener.java |
---|
File deleted |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/TransactionController.java |
---|
File deleted |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserDeletedListener.java |
---|
File deleted |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/TransactionListener.java |
---|
File deleted |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserModifiedListener.java |
---|
File deleted |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserManager.java |
---|
25,12 → 25,11 |
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) { |
44,10 → 43,7 |
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() |
60,13 → 56,7 |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
User user = new User(); |
if(!user.mayChangeBoss(editor)) { // ordinal user can create only own "subusers" |
user.setBoss(editor); |
} |
return user; |
return new User(); |
} |
public boolean allowedToCreate(User editor) |
83,7 → 73,8 |
try { |
user = (User)HibernateUtil.currentSession().load(User.class, id); |
} |
catch(HibernateException ex) { |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
109,7 → 100,8 |
new Type[] { Hibernate.STRING, Hibernate.entity(User.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) { |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
128,7 → 120,8 |
else |
return (User)list.get(0); |
} |
catch(HibernateException ex) { |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
142,15 → 135,13 |
throw new ModelSecurityException(); |
} |
boolean isNew = user.isNew(); |
user.setModUser(editor); |
//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); |
} |
160,44 → 151,8 |
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); |
208,16 → 163,6 |
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 |
{ |
236,26 → 181,16 |
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) |
272,7 → 207,8 |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } ); |
} |
} |
catch(HibernateException ex) { |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
292,7 → 228,8 |
.next()).intValue() > 0; |
} |
} |
catch(HibernateException ex) { |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
308,12 → 245,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; |
} |
335,8 → 272,9 |
"from UserLogin where success = ?", |
Boolean.FALSE, Hibernate.BOOLEAN); |
} |
catch(HibernateException ex) { |
throw new ModelException(ex); |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
350,7 → 288,8 |
"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/InetDomainManager.java |
---|
128,7 → 128,7 |
if(!domain.editableBy(editor)) |
throw new ModelSecurityException(); |
//domain.setModUser(editor); // FIXME |
domain.setModUser(editor); |
try { |
HibernateUtil.currentSession().saveOrUpdate(domain); |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailboxManager.java |
---|
137,7 → 137,7 |
if(!mailbox.editableBy(editor)) |
throw new ModelSecurityException(); |
//mailbox.setModUser(editor); // FIXME |
mailbox.setModUser(editor); |
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); // FIXME |
mailAlias.setModUser(editor); |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAlias); |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasDestinationManager.java |
---|
74,7 → 74,7 |
if(!mailAliasDestination.editableBy(editor)) |
throw new ModelSecurityException(); |
//mailAliasDestination.setModUser(editor); // FIXME |
mailAliasDestination.setModUser(editor); |
// FIXME: the mod_user is not set when changing a destination as element of collection |
try { |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/SystemUserManager.java |
---|
167,7 → 167,7 |
if(!systemUser.editableBy(editor)) |
throw new ModelSecurityException(); |
//systemUser.setModUser(editor); // FIXME |
systemUser.setModUser(editor); |
try { |
HibernateUtil.currentSession().saveOrUpdate(systemUser); |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/User.java |
---|
2,7 → 2,6 |
import java.util.Collection; |
import java.util.Collections; |
import java.util.HashSet; |
import java.util.Locale; |
import java.util.StringTokenizer; |
23,37 → 22,11 |
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 |
74,10 → 47,6 |
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; |
} |
104,7 → 73,6 |
if(password == null) |
throw new NullPointerException("Null password"); |
backupMe(); |
this.password = Digest.encode(password); |
} |
138,10 → 106,9 |
public void setBoss(User editor, User boss) |
throws ModelException |
{ |
if(!mayChangeBoss(editor)) |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.boss = boss; |
} |
170,7 → 137,6 |
if(!mayChangeSuperuser(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.superuser = superuser; |
} |
208,7 → 174,6 |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
setLocaleName(localeName); |
} |
223,7 → 188,6 |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.locale = locale; |
} |
308,11 → 272,6 |
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); |
326,9 → 285,7 |
protected static boolean allowedToCreate(UserManager manager, User editor) |
throws ModelException |
{ |
return editor.isSuperuser() |
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor); |
// FIXME: or allow any user to create "subusers"? |
return editor.isSuperuser(); |
} |
protected static User createLimitedCopy(User origin) |
337,9 → 294,4 |
u.setLogin(origin.getLogin()); |
return u; |
} |
public String toString() |
{ |
return getClass().getName() + " [" + getId() + "] [" + getLogin() + "]"; |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/Mailbox.java |
---|
206,9 → 206,7 |
public boolean editableBy(User user) |
{ |
return user.isSuperuser() |
|| (domain == null) // just created |
|| user.equals(domain.getOwner()); |
return user.isSuperuser() || user.equals(domain.getOwner()); |
} |
public boolean deleteableBy(User user) |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/GeneralModelObject.java |
---|
13,27 → 13,6 |
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/MailAlias.java |
---|
145,9 → 145,7 |
public boolean editableBy(User user) |
{ |
return user.isSuperuser() |
|| (domain == null) // just created |
|| user.equals(domain.getOwner()); |
return user.isSuperuser() || user.equals(domain.getOwner()); |
} |
public boolean mayChangeDestinations(User user) |