/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserValidator.java |
---|
0,0 → 1,9 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface UserValidator |
{ |
public void validateUser(User editor, User user) |
throws ModelException; |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserValidatorAtDomain.java |
---|
0,0 → 1,26 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import java.util.Iterator; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelUserException; |
public class UserValidatorAtDomain |
implements UserValidator |
{ |
public void validateUser(User editor, User user) |
throws ModelException |
{ |
if(editor.isSuperuser()) return; |
Collection domains = InetDomainManager.getInstance().listInetDomains(editor); |
for(Iterator i = domains.iterator(); i.hasNext(); ) { |
InetDomain domain = (InetDomain)i.next(); |
if(user.getLogin().endsWith("@" + domain.getName())) |
return; |
} |
throw new ModelUserException("ak.hostadmiral.core.uservalidator.atdomain.login.wrong"); |
} |
} |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserManager.java |
---|
20,7 → 20,8 |
UserBeforeDeleteListener, |
UserDeletingListener |
{ |
private UserStore store; |
private UserStore store; |
private UserValidator userValidator; |
private Collection createdListeners = new ArrayList(); |
private Collection modifiedListeners = new ArrayList(); |
99,6 → 100,9 |
throw new ModelSecurityException(); |
} |
if(userValidator != null) |
userValidator.validateUser(editor, user); |
boolean isNew = user.isNew(); |
//user.setModUser(editor); // FIXME: disabled because hb throws exception |
375,6 → 379,12 |
Class c = Class.forName((String)params.get("store")); |
store = (UserStore)c.newInstance(); |
String userValidatorName = (String)params.get("userValidator"); |
if(userValidatorName != null) { |
Class c2 = Class.forName(userValidatorName); |
userValidator = (UserValidator)c2.newInstance(); |
} |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/store/hibernate/MailboxHibernate.java |
---|
193,12 → 193,18 |
throws ModelStoreException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Mailbox mb left join mb.domain as d" |
+ " where d.owner=? or mb.owner=?", |
new Object[] { user, user }, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) }) |
.next()).intValue(); |
List countlist = HibernateUtil.sqlQuery( |
"select count(*) from (" |
+ " select mb.id from mailboxes mb" |
+ " where mb.owner=?" |
+ " union" |
+ " select mb.id from mailboxes mb" |
+ " left join domains as d on mb.domain = d.id" |
+ " where d.owner=?" |
+ ") as count_table", |
new Object[] { user.getId(), user.getId() }); |
return ((Long)countlist.get(0)).intValue(); |
} |
catch(HibernateException ex) |
{ |
/hostadmiral/trunk/src/ak/hostadmiral/core/model/store/hibernate/MailAliasHibernate.java |
---|
178,12 → 178,18 |
throws ModelStoreException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from MailAlias a left join a.domain as d" |
+ " where d.owner=? or a.owner=?", |
new Object[] { user, user }, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) }) |
.next()).intValue(); |
List countlist = HibernateUtil.sqlQuery( |
"select count(*) from (" |
+ " select a.id from mailaliases a" |
+ " where a.owner=?" |
+ " union" |
+ " select a.id from mailaliases a" |
+ " left join domains as d on a.domain = d.id" |
+ " where d.owner=?" |
+ ") as count_table", |
new Object[] { user.getId(), user.getId() }); |
return ((Long)countlist.get(0)).intValue(); |
} |
catch(HibernateException ex) |
{ |