/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/IndexAction.java |
---|
7,22 → 7,31 |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionForward; |
import ak.strutsx.ErrorHandlerX; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.SystemUserManager; |
import ak.hostcaptain.core.model.InetDomainManager; |
import ak.hostcaptain.core.model.MailboxManager; |
import ak.hostcaptain.core.model.MailAliasManager; |
public final class IndexAction |
extends Action |
implements ErrorHandlerX |
{ |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
User user = (User)request.getSession().getAttribute("user"); |
request.setAttribute("showSystemUsers", |
new Boolean(SystemUserManager.getInstance().areSystemUsersAvailable(user))); |
request.setAttribute("showInetDomains", |
new Boolean(InetDomainManager.getInstance().areInetDomainsAvailable(user))); |
request.setAttribute("showMailboxes", |
new Boolean(MailboxManager.getInstance().areMailboxesAvailable(user))); |
request.setAttribute("showMailAliases", |
new Boolean(MailAliasManager.getInstance().areMailAliasesAvailable(user))); |
return mapping.findForward("success"); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/InetDomainAction.java |
---|
46,9 → 46,11 |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(InetDomainManager.getInstance().listInetDomains()); |
List list = new ArrayList(InetDomainManager.getInstance().listInetDomains(user)); |
Collections.sort(list, InetDomainManager.NAME_COMPARATOR); |
request.setAttribute("domains", list); |
request.setAttribute("allowedToCreate", |
new Boolean(InetDomainManager.getInstance().allowedToCreate(user))); |
return mapping.findForward("default"); |
} |
62,7 → 64,7 |
showForm.set("enabled", new Boolean(true)); |
} |
else { |
InetDomain domain = InetDomainManager.getInstance().get(domainId); |
InetDomain domain = InetDomainManager.getInstance().get(user, domainId); |
showForm.set("name", domain.getName()); |
if(domain.getOwner() != null) |
showForm.set("owner", StringConverter.toString(domain.getOwner().getId())); |
76,9 → 78,9 |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long domainId = StringConverter.parseLong(theForm.get("id")); |
InetDomain domain = InetDomainManager.getInstance().get(domainId); |
InetDomain domain = InetDomainManager.getInstance().get(user, domainId); |
InetDomainManager.getInstance().delete(domain); |
InetDomainManager.getInstance().delete(user, domain); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
88,10 → 90,10 |
InetDomain domain; |
if(domainId == null) { |
domain = InetDomainManager.getInstance().create(); |
domain = InetDomainManager.getInstance().create(user); |
} |
else { |
domain = InetDomainManager.getInstance().get(domainId); |
domain = InetDomainManager.getInstance().get(user, domainId); |
} |
domain.setName((String)theForm.get("name")); |
101,7 → 103,7 |
domain.setEnabled((Boolean)theForm.get("enabled")); |
domain.setComment((String)theForm.get("comment")); |
InetDomainManager.getInstance().save(domain); |
InetDomainManager.getInstance().save(user, domain); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/MailboxAction.java |
---|
37,7 → 37,8 |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
initLists(request); |
User user = (User)request.getSession().getAttribute("user"); |
initLists(request, user); |
} |
} |
47,9 → 48,11 |
{ |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(MailboxManager.getInstance().listMailboxes()); |
List list = new ArrayList(MailboxManager.getInstance().listMailboxes(user)); |
Collections.sort(list, MailboxManager.LOGIN_COMPARATOR); |
request.setAttribute("mailboxes", list); |
request.setAttribute("allowedToCreate", |
new Boolean(MailboxManager.getInstance().allowedToCreate(user))); |
return mapping.findForward("default"); |
} |
63,7 → 66,7 |
showForm.set("enabled", new Boolean(true)); |
} |
else { |
Mailbox mailbox = MailboxManager.getInstance().get(boxId); |
Mailbox mailbox = MailboxManager.getInstance().get(user, boxId); |
showForm.set("login", mailbox.getLogin()); |
if(mailbox.getDomain() != null) |
showForm.set("domain", StringConverter.toString(mailbox.getDomain().getId())); |
77,15 → 80,15 |
showForm.set("comment", mailbox.getComment()); |
} |
initLists(request); |
initLists(request, user); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long boxId = StringConverter.parseLong(theForm.get("id")); |
Mailbox mailbox = MailboxManager.getInstance().get(boxId); |
Mailbox mailbox = MailboxManager.getInstance().get(user, boxId); |
MailboxManager.getInstance().delete(mailbox); |
MailboxManager.getInstance().delete(user, mailbox); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
99,16 → 102,16 |
if(password == null || password.equals("")) |
throw new Exception("empty password"); // FIXME: exception type and message? |
mailbox = MailboxManager.getInstance().create(); |
mailbox = MailboxManager.getInstance().create(user); |
// FIXME: create an user as owner of the new mailbox here |
} |
else { |
mailbox = MailboxManager.getInstance().get(boxId); |
mailbox = MailboxManager.getInstance().get(user, boxId); |
} |
mailbox.setLogin((String)theForm.get("login")); |
mailbox.setDomain(InetDomainManager.getInstance().get( |
mailbox.setDomain(InetDomainManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("domain")))); |
mailbox.setOwner(UserManager.getInstance().get( |
StringConverter.parseLong(theForm.get("owner")))); |
120,7 → 123,7 |
mailbox.setSystemUser(null); |
} |
else { |
mailbox.setSystemUser(SystemUserManager.getInstance().get(systemUserId)); |
mailbox.setSystemUser(SystemUserManager.getInstance().get(user, systemUserId)); |
} |
if(password != null && !password.equals("")) |
129,7 → 132,7 |
mailbox.setEnabled((Boolean)theForm.get("enabled")); |
mailbox.setComment((String)theForm.get("comment")); |
MailboxManager.getInstance().save(mailbox); |
MailboxManager.getInstance().save(user, mailbox); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
138,7 → 141,7 |
} |
} |
private void initLists(HttpServletRequest request) |
private void initLists(HttpServletRequest request, User user) |
throws Exception |
{ |
List users = new ArrayList(UserManager.getInstance().listUsers()); |
145,11 → 148,11 |
Collections.sort(users, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", users); |
List systemUsers = new ArrayList(SystemUserManager.getInstance().listSystemUsers()); |
List systemUsers = new ArrayList(SystemUserManager.getInstance().listSystemUsers(user)); |
Collections.sort(systemUsers, SystemUserManager.UID_COMPARATOR); |
request.setAttribute("systemusers", systemUsers); |
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains()); |
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains(user)); |
Collections.sort(domains, InetDomainManager.NAME_COMPARATOR); |
request.setAttribute("domains", domains); |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/MailAliasAction.java |
---|
55,9 → 55,11 |
{ |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(MailAliasManager.getInstance().listMailAliases()); |
List list = new ArrayList(MailAliasManager.getInstance().listMailAliases(user)); |
Collections.sort(list, MailAliasManager.ADDRESS_COMPARATOR); |
request.setAttribute("aliases", list); |
request.setAttribute("allowedToCreate", |
new Boolean(MailAliasManager.getInstance().allowedToCreate(user))); |
return mapping.findForward("default"); |
} |
72,9 → 74,9 |
showForm.set("enabled", new Boolean(true)); |
} |
else { |
MailAlias alias = MailAliasManager.getInstance().get(aliasId); |
MailAlias alias = MailAliasManager.getInstance().get(user, aliasId); |
List dests = new ArrayList(MailAliasDestinationManager.getInstance() |
.listMailAliasesDestination(alias)); |
.listMailAliasesDestination(alias)); |
MailAliasDestBean[] d = new MailAliasDestBean[dests.size()]; |
// FIXME: sort dests here |
99,9 → 101,9 |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
MailAlias alias = MailAliasManager.getInstance().get(aliasId); |
MailAlias alias = MailAliasManager.getInstance().get(user, aliasId); |
MailAliasManager.getInstance().delete(alias); |
MailAliasManager.getInstance().delete(user, alias); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
109,13 → 111,13 |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
MailAlias alias = (aliasId == null) ? null |
: MailAliasManager.getInstance().get(aliasId); |
: MailAliasManager.getInstance().get(user, aliasId); |
MailAliasDestBean[] dests = (MailAliasDestBean[])theForm.get("dests"); |
// submit |
if(request.getParameter("submit") != null) { |
if(alias == null) |
alias = MailAliasManager.getInstance().create(); |
alias = MailAliasManager.getInstance().create(user); |
alias.getDestinations().clear(); |
for(int i = 0; i < dests.length; i++) { |
137,7 → 139,7 |
// set mailbox or email |
if(mailboxId != null) { |
dest.setMailbox(MailboxManager.getInstance().get(mailboxId)); |
dest.setMailbox(MailboxManager.getInstance().get(user, mailboxId)); |
dest.setEmail(null); |
} |
else if(dests[i].getEmail() != null && !dests[i].getEmail().equals("")) { |
151,7 → 153,7 |
} |
alias.setAddress((String)theForm.get("address")); |
alias.setDomain(InetDomainManager.getInstance().get( |
alias.setDomain(InetDomainManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("domain")))); |
alias.setOwner(UserManager.getInstance().get( |
StringConverter.parseLong(theForm.get("owner")))); |
159,7 → 161,7 |
alias.setComment((String)theForm.get("comment")); |
// update alias |
MailAliasManager.getInstance().save(alias); |
MailAliasManager.getInstance().save(user, alias); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
233,7 → 235,7 |
Collections.sort(users, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", users); |
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains()); |
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains(user)); |
Collections.sort(domains, InetDomainManager.NAME_COMPARATOR); |
request.setAttribute("domains", domains); |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/SystemUserAction.java |
---|
46,9 → 46,11 |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(SystemUserManager.getInstance().listSystemUsers()); |
List list = new ArrayList(SystemUserManager.getInstance().listSystemUsers(user)); |
Collections.sort(list, SystemUserManager.NAME_COMPARATOR); |
request.setAttribute("users", list); |
request.setAttribute("allowedToCreate", |
new Boolean(SystemUserManager.getInstance().allowedToCreate(user))); |
return mapping.findForward("default"); |
} |
62,7 → 64,7 |
showForm.set("enabled", new Boolean(true)); |
} |
else { |
SystemUser u = SystemUserManager.getInstance().get(userId); |
SystemUser u = SystemUserManager.getInstance().get(user, userId); |
showForm.set("uid", StringConverter.toString(u.getUid())); |
showForm.set("name", u.getName()); |
if(u.getOwner() != null) |
77,9 → 79,9 |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
SystemUser u = SystemUserManager.getInstance().get(userId); |
SystemUser u = SystemUserManager.getInstance().get(user, userId); |
SystemUserManager.getInstance().delete(u); |
SystemUserManager.getInstance().delete(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
89,10 → 91,10 |
SystemUser u; |
if(userId == null) { |
u = SystemUserManager.getInstance().create(); |
u = SystemUserManager.getInstance().create(user); |
} |
else { |
u = SystemUserManager.getInstance().get(userId); |
u = SystemUserManager.getInstance().get(user, userId); |
} |
u.setUid(StringConverter.parseInteger(theForm.get("uid"))); |
107,7 → 109,7 |
u.setEnabled((Boolean)theForm.get("enabled")); |
u.setComment((String)theForm.get("comment")); |
SystemUserManager.getInstance().save(u); |
SystemUserManager.getInstance().save(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/CoreResources.properties |
---|
13,6 → 13,7 |
ak.hostcaptain.core.ident.mailAliasDestination.external={0} |
ak.hostcaptain.core.ident.mailAliasDestination.internal={0}@{1} |
ak.hostcaptain.core.access.denied=Access to the object denied |
ak.hostcaptain.core.login.failed=Wrong login or password or the user is disabled |
ak.hostcaptain.core.login.required=You have to enter the login |
ak.hostcaptain.core.password.required=You have to enter the password |
92,6 → 93,7 |
ak.hostcaptain.page.user.list.enabled=Enabled |
ak.hostcaptain.page.user.list.delete=delete |
ak.hostcaptain.page.user.list.edit=edit |
ak.hostcaptain.page.user.list.view=view |
ak.hostcaptain.page.user.list.add=add new user |
ak.hostcaptain.page.user.list.back=back |
114,6 → 116,7 |
ak.hostcaptain.page.user.system.list.enabled=Enabled |
ak.hostcaptain.page.user.system.list.delete=delete |
ak.hostcaptain.page.user.system.list.edit=edit |
ak.hostcaptain.page.user.system.list.view=view |
ak.hostcaptain.page.user.system.list.add=add new user |
ak.hostcaptain.page.user.system.list.back=back |
132,6 → 135,7 |
ak.hostcaptain.page.domain.list.owner=Owner |
ak.hostcaptain.page.domain.list.enabled=Enabled |
ak.hostcaptain.page.domain.list.delete=delete |
ak.hostcaptain.page.domain.list.view=view |
ak.hostcaptain.page.domain.list.edit=edit |
ak.hostcaptain.page.domain.list.add=add new domain |
ak.hostcaptain.page.domain.list.back=back |
147,8 → 151,11 |
ak.hostcaptain.page.mail.alias.list.title=hostcaptain - mail aliases - list |
ak.hostcaptain.page.mail.alias.list.alias=Alias |
ak.hostcaptain.page.mail.alias.list.domain=Domain |
ak.hostcaptain.page.mail.alias.list.owner=Owner |
ak.hostcaptain.page.mail.alias.list.enabled=Enabled |
ak.hostcaptain.page.mail.alias.list.edit=edit |
ak.hostcaptain.page.mail.alias.list.view=view |
ak.hostcaptain.page.mail.alias.list.delete=delete |
ak.hostcaptain.page.mail.alias.list.back=back |
ak.hostcaptain.page.mail.alias.list.add=add new mail alias |
175,6 → 182,7 |
ak.hostcaptain.page.mail.box.list.owner=Owner |
ak.hostcaptain.page.mail.box.list.enabled=Enabled |
ak.hostcaptain.page.mail.box.list.edit=edit |
ak.hostcaptain.page.mail.box.list.view=view |
ak.hostcaptain.page.mail.box.list.delete=delete |
ak.hostcaptain.page.mail.box.list.add=add new mail box |
ak.hostcaptain.page.mail.box.list.back=back |
/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(); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/ViewableTag.java |
---|
0,0 → 1,18 |
package ak.hostcaptain.core.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.InetDomain; |
public class ViewableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return object.viewableBy(user); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/NotViewableTag.java |
---|
0,0 → 1,18 |
package ak.hostcaptain.core.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.InetDomain; |
public class NotViewableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return !object.viewableBy(user); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/DeleteableTag.java |
---|
0,0 → 1,18 |
package ak.hostcaptain.core.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.InetDomain; |
public class DeleteableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return object.deleteableBy(user); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/NotDeleteableTag.java |
---|
0,0 → 1,18 |
package ak.hostcaptain.core.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.InetDomain; |
public class NotDeleteableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return !object.deleteableBy(user); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/RightTagBase.java |
---|
0,0 → 1,62 |
package ak.hostcaptain.core.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import org.apache.struts.util.RequestUtils; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.ModelObject; |
public abstract class RightTagBase |
extends TagSupport |
{ |
protected User user; |
protected ModelObject object; |
protected String name; |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
public void release() |
{ |
super.release(); |
name = null; |
user = null; |
} |
public int doStartTag() |
throws JspException |
{ |
user = (User)RequestUtils.lookup(pageContext, "user", "session"); |
Object obj = RequestUtils.lookup(pageContext, name, null); |
if(!(obj instanceof ModelObject)) |
throw new JspException("Must be a ModelObject"); |
object = (ModelObject)obj; |
if(condition()) |
return EVAL_BODY_INCLUDE; |
else |
return SKIP_BODY; |
} |
public int doEndTag() |
throws JspException |
{ |
return EVAL_PAGE; |
} |
protected abstract boolean condition() |
throws JspException; |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/EditableTag.java |
---|
0,0 → 1,18 |
package ak.hostcaptain.core.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.InetDomain; |
public class EditableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return object.editableBy(user); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/NotEditableTag.java |
---|
0,0 → 1,18 |
package ak.hostcaptain.core.taglib; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.InetDomain; |
public class NotEditableTag |
extends RightTagBase |
{ |
protected boolean condition() |
throws JspException |
{ |
return !object.editableBy(user); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/util/ModelSecurityException.java |
---|
0,0 → 1,10 |
package ak.hostcaptain.util; |
public class ModelSecurityException |
extends ModelException |
{ |
public ModelSecurityException() |
{ |
super("ak.hostcaptain.core.access.denied"); |
} |
} |