Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 913 → Rev 914

/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/test/Test.java
File deleted
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailboxManager.java
2,8 → 2,10
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class MailboxManager
{
33,24 → 35,41
{
}
 
public Mailbox create()
public Mailbox create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new Mailbox();
}
 
public Mailbox get(Long id)
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
 
public Mailbox get(User editor, Long id)
throws ModelException
{
Mailbox mailbox;
 
try {
return (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id);
mailbox = (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!mailbox.viewableBy(editor))
throw new ModelSecurityException();
 
return mailbox;
}
 
public Mailbox findForLogin(String login)
protected Mailbox findForLogin(String login)
throws ModelException
{
try {
68,9 → 87,12
}
}
 
public void save(Mailbox mailbox)
public void save(User editor, Mailbox mailbox)
throws ModelException
{
if(!mailbox.editableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailbox);
}
80,9 → 102,12
}
}
 
public void delete(Mailbox mailbox)
public void delete(User editor, Mailbox mailbox)
throws ModelException
{
if(!mailbox.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailbox);
}
92,11 → 117,18
}
}
 
public Collection listMailboxes()
public Collection listMailboxes(User editor)
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from Mailbox");
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from Mailbox");
else
return HibernateUtil.currentSession().find(
"select mb from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
catch(HibernateException ex)
{
104,12 → 136,23
}
}
 
public Collection listMailboxes(User owner)
public boolean areMailboxesAvailable(User editor)
throws ModelException
{
try {
return HibernateUtil.currentSession().find(
"from Mailbox where owner=?", owner, Hibernate.entity(User.class));
if(editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor))
{
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/InetDomain.java
88,4 → 88,19
{
return new Object[] { getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser();
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasManager.java
2,8 → 2,10
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class MailAliasManager
{
33,26 → 35,43
{
}
 
public MailAlias create()
public MailAlias create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
MailAlias alias = new MailAlias();
alias.setDestinations(new ArrayList());
return alias;
}
 
public MailAlias get(Long id)
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
 
public MailAlias get(User editor, Long id)
throws ModelException
{
MailAlias alias;
 
try {
return (MailAlias)HibernateUtil.currentSession().load(MailAlias.class, id);
alias = (MailAlias)HibernateUtil.currentSession().load(MailAlias.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!alias.viewableBy(editor))
throw new ModelSecurityException();
 
return alias;
}
 
public MailAlias findForName(String name)
protected MailAlias findForName(String name)
throws ModelException
{
try {
70,9 → 89,12
}
}
 
public void save(MailAlias mailAlias)
public void save(User editor, MailAlias mailAlias)
throws ModelException
{
if(!mailAlias.editableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailAlias);
}
82,9 → 104,12
}
}
 
public void delete(MailAlias mailAlias)
public void delete(User editor, MailAlias mailAlias)
throws ModelException
{
if(!mailAlias.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailAlias);
}
94,11 → 119,18
}
}
 
public Collection listMailAliases()
public Collection listMailAliases(User editor)
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from MailAlias");
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from MailAlias");
else
return HibernateUtil.currentSession().find(
"select a from MailAlias a left join a.domain as d"
+ " where d.owner=? or a.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
catch(HibernateException ex)
{
106,12 → 138,23
}
}
 
public Collection listMailAliases(User owner)
public boolean areMailAliasesAvailable(User editor)
throws ModelException
{
try {
return HibernateUtil.currentSession().find(
"from MailAlias where owner=?", owner, Hibernate.entity(User.class));
if(editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor))
{
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from MailAlias a left join a.domain as d"
+ " where d.owner=? or a.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/ModelObject.java
7,4 → 7,10
public String getIdentKey();
 
public Object[] getIdentParams();
 
public boolean viewableBy(User user);
 
public boolean editableBy(User user);
 
public boolean deleteableBy(User user);
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/Mailbox.java
172,4 → 172,19
{
return new Object[] { getLogin(), getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAlias.java
125,4 → 125,19
{
return new Object[] { getAddress(), getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasDestination.java
109,4 → 109,19
else
return new Object[] { getMailbox().getLogin(), getMailbox().getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return alias.viewableBy(user);
}
 
public boolean editableBy(User user)
{
return alias.editableBy(user);
}
 
public boolean deleteableBy(User user)
{
return alias.deleteableBy(user);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/SystemUserManager.java
4,6 → 4,7
import net.sf.hibernate.*;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class SystemUserManager
{
33,24 → 34,40
{
}
 
public SystemUser create()
public SystemUser create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new SystemUser();
}
 
public SystemUser get(Long id)
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser();
}
 
public SystemUser get(User editor, Long id)
throws ModelException
{
SystemUser user;
 
try {
return (SystemUser)HibernateUtil.currentSession().load(SystemUser.class, id);
user = (SystemUser)HibernateUtil.currentSession().load(SystemUser.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!user.viewableBy(editor))
throw new ModelSecurityException();
 
return user;
}
 
public SystemUser findForName(String name)
protected SystemUser findForName(String name)
throws ModelException
{
try {
68,7 → 85,7
}
}
 
public SystemUser findForUid(Integer uid)
protected SystemUser findForUid(Integer uid)
throws ModelException
{
try {
86,9 → 103,12
}
}
 
public void save(SystemUser systemUser)
public void save(User editor, SystemUser systemUser)
throws ModelException
{
if(!systemUser.editableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().saveOrUpdate(systemUser);
}
98,9 → 118,12
}
}
 
public void delete(SystemUser systemUser)
public void delete(User editor, SystemUser systemUser)
throws ModelException
{
if(!systemUser.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(systemUser);
}
110,11 → 133,16
}
}
 
public Collection listSystemUsers()
public Collection listSystemUsers(User editor)
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from SystemUser");
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from SystemUser");
else
return HibernateUtil.currentSession().find(
"select u from SystemUser u left join u.owner o where o is null or o=?",
editor, Hibernate.entity(User.class));
}
catch(HibernateException ex)
{
122,6 → 150,23
}
}
 
public boolean areSystemUsersAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return true;
else
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from SystemUser u left join u.owner o where o is null or o=?",
editor, Hibernate.entity(User.class)).next()).intValue() > 0;
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static SystemUserManager systemUserManager = null;
 
public static SystemUserManager getInstance()
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/User.java
107,6 → 107,11
return superuser;
}
 
public boolean isSuperuser()
{
return (superuser != null) && superuser.booleanValue();
}
 
public void setSuperuser(Boolean superuser)
{
this.superuser = superuser;
156,4 → 161,19
{
return new Object[] { getLogin() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(boss);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser();
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/InetDomainManager.java
4,6 → 4,7
import net.sf.hibernate.*;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class InetDomainManager
{
33,24 → 34,41
{
}
 
public InetDomain create()
public InetDomain create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new InetDomain();
}
 
public InetDomain get(Long id)
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser();
}
 
public InetDomain get(User editor, Long id)
throws ModelException
{
InetDomain domain;
 
try {
return (InetDomain)HibernateUtil.currentSession().load(InetDomain.class, id);
domain = (InetDomain)HibernateUtil.currentSession().load(
InetDomain.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!domain.viewableBy(editor))
throw new ModelSecurityException();
 
return domain;
}
 
public InetDomain findForName(String name)
protected InetDomain findForName(String name)
throws ModelException
{
try {
68,9 → 86,12
}
}
 
public void save(InetDomain inetDomain)
public void save(User editor, InetDomain inetDomain)
throws ModelException
{
if(!inetDomain.editableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().saveOrUpdate(inetDomain);
}
80,10 → 101,14
}
}
 
public void delete(InetDomain inetDomain)
public void delete(User editor, InetDomain inetDomain)
throws ModelException
{
if(!inetDomain.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
 
HibernateUtil.currentSession().delete(inetDomain);
}
catch(HibernateException ex)
92,11 → 117,15
}
}
 
public Collection listInetDomains()
public Collection listInetDomains(User editor)
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from InetDomain");
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from InetDomain");
else
return HibernateUtil.currentSession().find(
"from InetDomain where owner=?", editor, Hibernate.entity(User.class));
}
catch(HibernateException ex)
{
104,6 → 133,23
}
}
 
public boolean areInetDomainsAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return true;
else
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from InetDomain where owner=?",
editor, Hibernate.entity(User.class)).next()).intValue() > 0;
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static InetDomainManager inetDomainManager = null;
 
public static InetDomainManager getInstance()
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/SystemUser.java
105,4 → 105,19
{
return new Object[] { getName(), getUid() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || (owner == null) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser();
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser();
}
}