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); |
} |
|