27,6 → 27,8 |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/hostadmiral/core/model/User.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"/ak/hostadmiral/core/model/UserLogin.hbm.xml"); |
|
userManager = new UserManager(); |
} |
108,7 → 110,9 |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from User where login=? and enabled='1'", login, Hibernate.STRING); |
"from User where login = ? and enabled = ?", |
new Object[] { login, new Boolean(true) }, |
new Type[] { Hibernate.STRING, Hibernate.BOOLEAN } ); |
|
if(list.size() == 0) |
return null; |
151,7 → 155,7 |
beforeDeleteListeners.remove(listener); |
} |
|
public Collection beforeDelete(User editor, User user) |
public Collection beforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
158,7 → 162,7 |
|
for(Iterator i = beforeDeleteListeners.iterator(); i.hasNext(); ) { |
UserBeforeDeleteListener listener = (UserBeforeDeleteListener)i.next(); |
Collection subcascade = listener.userBeforeDelete(editor, user); |
Collection subcascade = listener.userBeforeDelete(editor, user, known); |
if(subcascade != null) |
cascade.addAll(subcascade); |
} |
222,24 → 226,48 |
} |
} |
|
public User loginUser(String login, String password) |
public User loginUser(String login, String password, String ip) |
throws ModelException |
{ |
if(login == null || password == null) |
return null; |
User user = (login == null || password == null) ? null : findForLogin(login); |
boolean success = (user == null) ? false : user.checkPassword(password); |
UserLogin userLogin = new UserLogin(user, login, new Date(), new Boolean(success), ip); |
|
User user = findForLogin(login); |
// save login information |
try { |
HibernateUtil.currentSession().saveOrUpdate(userLogin); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
|
if(user != null) { |
if(user.checkPassword(password)) |
if(success) |
return user; |
else |
return null; // wrong login or password |
} |
|
// wrong login or password |
return null; |
public Collection listFailedLogins(User editor) |
throws ModelException |
{ |
if(!editor.mayViewAllLogins()) |
{ |
throw new ModelSecurityException(); |
} |
|
public Collection userBeforeDelete(User editor, User user) |
try { |
return HibernateUtil.currentSession().find( |
"from UserLogin where success = ?", |
new Boolean(false), Hibernate.BOOLEAN); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
|
public Collection userBeforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection subusers; |
260,7 → 288,7 |
if(u.viewableBy(editor)) { |
if(u.deleteableBy(editor)) |
cascade.add(new CascadeDeleteElement(u, CascadeDeleteElement.DELETE, |
this.beforeDelete(editor, u))); |
this.beforeDelete(editor, u, known))); |
else |
cascade.add(new CascadeDeleteElement(u, CascadeDeleteElement.FORBIDDEN, null)); |
} |
274,6 → 302,7 |
} |
|
public static final Comparator LOGIN_COMPARATOR = new LoginComparator(); |
public static final Comparator LOGINS_TIME_COMPARATOR = new LoginsTimeComparator(); |
|
private static class LoginComparator |
implements Comparator |
301,4 → 330,31 |
return (obj instanceof LoginComparator); |
} |
} |
|
private static class LoginsTimeComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof UserLogin) || !(o2 instanceof UserLogin)) |
throw new ClassCastException("not a UserLogin"); |
|
UserLogin a1 = (UserLogin)o1; |
UserLogin a2 = (UserLogin)o2; |
|
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getLoginTime().compareTo(a2.getLoginTime()); |
} |
|
public boolean equals(Object obj) |
{ |
return (obj instanceof LoginComparator); |
} |
} |
} |