/sun/hostcaptain/trunk/src/ak/hostcaptain/core/form/MailAliasDestBean.java |
---|
5,9 → 5,11 |
public final class MailAliasDestBean |
{ |
private String id; |
private String mailbox; |
private String email; |
private String id; |
private String mailbox; |
private String email; |
private Boolean enabled; |
private String comment; |
public MailAliasDestBean() |
{ |
19,6 → 21,8 |
this.mailbox = (dest.getMailbox() == null) |
? null : StringConverter.toString(dest.getMailbox().getId()); |
this.email = dest.getEmail(); |
this.enabled = dest.getEnabled(); |
this.comment = dest.getComment(); |
} |
public String getId() |
50,4 → 54,24 |
{ |
this.email = email; |
} |
public Boolean getEnabled() |
{ |
return enabled; |
} |
public void setEnabled(Boolean enabled) |
{ |
this.enabled = enabled; |
} |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/InetDomainAction.java |
---|
35,7 → 35,8 |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
initUserList(request); |
User user = (User)request.getSession().getAttribute("user"); |
initUserList(request, user); |
} |
} |
72,7 → 73,7 |
showForm.set("comment", domain.getComment()); |
} |
initUserList(request); |
initUserList(request, user); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
97,7 → 98,7 |
} |
domain.setName((String)theForm.get("name")); |
domain.setOwner(UserManager.getInstance().get( |
domain.setOwner(UserManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("owner")))); |
domain.setEnabled((Boolean)theForm.get("enabled")); |
112,10 → 113,10 |
} |
} |
private void initUserList(HttpServletRequest request) |
private void initUserList(HttpServletRequest request, User user) |
throws Exception |
{ |
List list = new ArrayList(UserManager.getInstance().listUsers()); |
List list = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/ChangePasswordAction.java |
---|
35,7 → 35,7 |
if(user.checkPassword((String)theForm.get("oldpassword"))) { |
user.setNewPassword((String)theForm.get("password")); |
UserManager.getInstance().save(user); |
UserManager.getInstance().save(user, user); // FIXME: allow user to change own password |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/MailboxAction.java |
---|
21,6 → 21,8 |
import ak.backpath.BackPath; |
import ak.hostcaptain.util.StringConverter; |
import ak.hostcaptain.util.UserException; |
import ak.hostcaptain.core.CoreResources; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.UserManager; |
import ak.hostcaptain.core.model.Mailbox; |
63,7 → 65,9 |
this, request, "ak.hostcaptain.core.form.MailboxEditForm"); |
if(boxId == null) { |
showForm.set("enabled", new Boolean(true)); |
showForm.set("enabled", new Boolean(true)); |
showForm.set("viruscheck", new Boolean(true)); |
showForm.set("spamcheck", new Boolean(true)); |
} |
else { |
Mailbox mailbox = MailboxManager.getInstance().get(user, boxId); |
100,7 → 104,7 |
if(boxId == null) { |
if(password == null || password.equals("")) |
throw new Exception("empty password"); // FIXME: exception type and message? |
throw new UserException(CoreResources.PASSWORD_REQUIRED); |
mailbox = MailboxManager.getInstance().create(user); |
113,7 → 117,7 |
mailbox.setLogin((String)theForm.get("login")); |
mailbox.setDomain(InetDomainManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("domain")))); |
mailbox.setOwner(UserManager.getInstance().get( |
mailbox.setOwner(UserManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("owner")))); |
mailbox.setVirusCheck((Boolean)theForm.get("viruscheck")); |
mailbox.setSpamCheck((Boolean)theForm.get("spamcheck")); |
144,7 → 148,7 |
private void initLists(HttpServletRequest request, User user) |
throws Exception |
{ |
List users = new ArrayList(UserManager.getInstance().listUsers()); |
List users = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(users, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", users); |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/MailAliasAction.java |
---|
24,6 → 24,7 |
import ak.backpath.BackPath; |
import ak.hostcaptain.util.StringConverter; |
import ak.hostcaptain.util.UserException; |
import ak.hostcaptain.core.model.User; |
import ak.hostcaptain.core.model.UserManager; |
import ak.hostcaptain.core.model.Mailbox; |
75,11 → 76,11 |
} |
else { |
MailAlias alias = MailAliasManager.getInstance().get(user, aliasId); |
List dests = new ArrayList(MailAliasDestinationManager.getInstance() |
.listMailAliasesDestination(alias)); |
List dests = new ArrayList(MailAliasDestinationManager.getInstance() |
.listMailAliasesDestination(alias)); |
MailAliasDestBean[] d = new MailAliasDestBean[dests.size()]; |
// FIXME: sort dests here |
// FIXME: sort dests here |
for(int i = 0; i < dests.size(); i++) { |
d[i] = new MailAliasDestBean((MailAliasDestination)dests.get(i)); |
86,11 → 87,11 |
} |
showForm.set("dests", d); |
showForm.set("address", alias.getAddress()); |
if(alias.getDomain() != null) |
showForm.set("domain", StringConverter.toString(alias.getDomain().getId())); |
if(alias.getOwner() != null) |
showForm.set("owner", StringConverter.toString(alias.getOwner().getId())); |
showForm.set("address", alias.getAddress()); |
if(alias.getDomain() != null) |
showForm.set("domain", StringConverter.toString(alias.getDomain().getId())); |
if(alias.getOwner() != null) |
showForm.set("owner", StringConverter.toString(alias.getOwner().getId())); |
showForm.set("enabled", alias.getEnabled()); |
showForm.set("comment", alias.getComment()); |
} |
111,11 → 112,22 |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
MailAlias alias = (aliasId == null) ? null |
: MailAliasManager.getInstance().get(user, aliasId); |
: MailAliasManager.getInstance().get(user, aliasId); |
MailAliasDestBean[] dests = (MailAliasDestBean[])theForm.get("dests"); |
// submit |
// submit |
if(request.getParameter("submit") != null) { |
// FIXME: if empty element of select box is active, it will be changed |
// by submit |
// validate required fields, because it cannot be done in general case |
if(StringConverter.isEmpty(theForm.get("address"))) |
throw new UserException("ak.hostcaptain.core.mail.alias.edit.address.empty"); |
if(StringConverter.isEmpty(theForm.get("domain"))) |
throw new UserException("ak.hostcaptain.core.mail.alias.edit.domain.wrong"); |
if(StringConverter.isEmpty(theForm.get("owner"))) |
throw new UserException("ak.hostcaptain.core.mail.alias.edit.owner.wrong"); |
if(alias == null) |
alias = MailAliasManager.getInstance().create(user); |
128,35 → 140,38 |
&& (dests[i].getEmail() == null || dests[i].getEmail().equals(""))) |
continue; |
// get bean |
Long destId = StringConverter.parseLong(dests[i].getId()); |
Long mailboxId = StringConverter.parseLong(dests[i].getMailbox()); |
// get bean |
Long destId = StringConverter.parseLong(dests[i].getId()); |
Long mailboxId = StringConverter.parseLong(dests[i].getMailbox()); |
MailAliasDestination dest; |
if(destId == null) |
dest = MailAliasDestinationManager.getInstance().create(); |
else |
dest = MailAliasDestinationManager.getInstance().get(destId); |
dest = MailAliasDestinationManager.getInstance().create(user); |
else |
dest = MailAliasDestinationManager.getInstance().get(user, destId); |
// set mailbox or email |
// set mailbox or email |
if(mailboxId != null) { |
dest.setMailbox(MailboxManager.getInstance().get(user, mailboxId)); |
dest.setEmail(null); |
} |
else if(dests[i].getEmail() != null && !dests[i].getEmail().equals("")) { |
else if(dests[i].getEmail() != null && !dests[i].getEmail().equals("")) { |
dest.setMailbox(null); |
dest.setEmail(dests[i].getEmail()); |
} |
// connect |
dest.setAlias(alias); |
dest.setEnabled(dests[i].getEnabled()); |
dest.setComment(dests[i].getComment()); |
// connect |
dest.setAlias(alias); |
alias.getDestinations().add(dest); |
} |
alias.setAddress((String)theForm.get("address")); |
alias.setDomain(InetDomainManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("domain")))); |
alias.setOwner(UserManager.getInstance().get( |
StringConverter.parseLong(theForm.get("owner")))); |
alias.setAddress((String)theForm.get("address")); |
alias.setDomain(InetDomainManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("domain")))); |
alias.setOwner(UserManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("owner")))); |
alias.setEnabled((Boolean)theForm.get("enabled")); |
alias.setComment((String)theForm.get("comment")); |
169,9 → 184,13 |
// add |
else if(request.getParameter("add") != null) { |
// FIXME: if called when no entries defined two rows are created |
MailAliasDestBean[] newDests = new MailAliasDestBean[dests.length+1]; |
System.arraycopy(dests, 0, newDests, 0, dests.length); |
if(dests.length > 0) |
System.arraycopy(dests, 0, newDests, 0, dests.length); |
newDests[dests.length] = new MailAliasDestBean(); |
newDests[dests.length].setEnabled(new Boolean(true)); |
theForm.set("dests", newDests); |
initLists(request, user); |
192,20 → 211,13 |
if(n < 0 || n >= dests.length) break; |
MailAliasDestBean[] newDests; |
if(dests.length <= 1) { |
newDests = new MailAliasDestBean[1]; |
newDests[0] = new MailAliasDestBean(); |
} |
else { |
newDests = new MailAliasDestBean[dests.length-1]; |
if(n > 0) |
System.arraycopy(dests, 0, newDests, 0, n); |
if(n < dests.length-1) |
System.arraycopy(dests, n+1, newDests, |
n, dests.length-n-1); |
} |
newDests = new MailAliasDestBean[dests.length-1]; |
if(n > 0) |
System.arraycopy(dests, 0, newDests, 0, n); |
if(n < dests.length-1) |
System.arraycopy(dests, n+1, newDests, |
n, dests.length-n-1); |
theForm.set("dests", newDests); |
break; |
} |
catch(NumberFormatException ex) { |
226,12 → 238,12 |
private void initLists(HttpServletRequest request, User user) |
throws Exception |
{ |
// list of mailboxes to redirect to |
// list of mailboxes to redirect to |
List mailboxes = new ArrayList(MailboxManager.getInstance().listMailboxes(user)); |
Collections.sort(mailboxes, MailboxManager.LOGIN_COMPARATOR); |
request.setAttribute("mailboxes", mailboxes); |
List users = new ArrayList(UserManager.getInstance().listUsers()); |
List users = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(users, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", users); |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/UserAction.java |
---|
35,7 → 35,8 |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
initUserList(request); |
User user = (User)request.getSession().getAttribute("user"); |
initUserList(request, user); |
} |
} |
46,7 → 47,7 |
User user = (User)request.getSession().getAttribute("user"); |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(UserManager.getInstance().listUsers()); |
List list = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
62,7 → 63,7 |
showForm.set("enabled", new Boolean(true)); |
} |
else { |
User u = UserManager.getInstance().get(userId); |
User u = UserManager.getInstance().get(user, userId); |
showForm.set("login", u.getLogin()); |
if(u.getBoss() != null) |
showForm.set("boss", StringConverter.toString(u.getBoss().getId())); |
71,13 → 72,13 |
showForm.set("comment", u.getComment()); |
} |
initUserList(request); |
initUserList(request, user); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u = UserManager.getInstance().get(userId); |
User u = UserManager.getInstance().get(user, userId); |
if(u.equals(user)) |
throw new UserException(CoreResources.DELETE_ME_SELF); |
85,7 → 86,7 |
// FIXME: invalidate session of deleted user if it is logged in |
// FIXME: if two admins delete each other at the same time |
UserManager.getInstance().delete(u); |
UserManager.getInstance().delete(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
99,10 → 100,10 |
if(password == null || password.equals("")) |
throw new UserException(CoreResources.PASSWORD_REQUIRED); |
u = UserManager.getInstance().create(); |
u = UserManager.getInstance().create(user); |
} |
else { |
u = UserManager.getInstance().get(userId); |
u = UserManager.getInstance().get(user, userId); |
} |
u.setLogin((String)theForm.get("login")); |
111,7 → 112,7 |
if(bossId == null) |
u.setBoss(null); |
else |
u.setBoss(UserManager.getInstance().get(bossId)); |
u.setBoss(UserManager.getInstance().get(user, bossId)); |
if(!user.equals(u)) // do not allow user to change own superuser status |
u.setSuperuser((Boolean)theForm.get("superuser")); |
122,7 → 123,7 |
u.setEnabled((Boolean)theForm.get("enabled")); |
u.setComment((String)theForm.get("comment")); |
UserManager.getInstance().save(u); |
UserManager.getInstance().save(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
131,10 → 132,10 |
} |
} |
private void initUserList(HttpServletRequest request) |
private void initUserList(HttpServletRequest request, User user) |
throws Exception |
{ |
List list = new ArrayList(UserManager.getInstance().listUsers()); |
List list = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/SystemUserAction.java |
---|
35,7 → 35,8 |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
initUserList(request); |
User user = (User)request.getSession().getAttribute("user"); |
initUserList(request, user); |
} |
} |
73,7 → 74,7 |
showForm.set("comment", u.getComment()); |
} |
initUserList(request); |
initUserList(request, user); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
104,7 → 105,7 |
if(ownerId == null) |
u.setOwner(null); |
else |
u.setOwner(UserManager.getInstance().get(ownerId)); |
u.setOwner(UserManager.getInstance().get(user, ownerId)); |
u.setEnabled((Boolean)theForm.get("enabled")); |
u.setComment((String)theForm.get("comment")); |
118,10 → 119,10 |
} |
} |
private void initUserList(HttpServletRequest request) |
private void initUserList(HttpServletRequest request, User user) |
throws Exception |
{ |
List list = new ArrayList(UserManager.getInstance().listUsers()); |
List list = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/CoreResources.properties |
---|
83,8 → 83,8 |
ak.hostcaptain.page.user.password.change.old_password=Old password |
ak.hostcaptain.page.user.password.change.new_password=New password |
ak.hostcaptain.page.user.password.change.new_password_again=New password again |
ak.hostcaptain.page.user.password.change.submit=Change |
ak.hostcaptain.page.user.password.change.cancel=Cancel |
ak.hostcaptain.page.user.password.change.submit=submit |
ak.hostcaptain.page.user.password.change.back=back |
ak.hostcaptain.page.user.list.title=hostcaptain - users - list |
ak.hostcaptain.page.user.list.login=Login |
149,33 → 149,6 |
ak.hostcaptain.page.domain.edit.submit=submit |
ak.hostcaptain.page.domain.edit.back=back |
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 |
ak.hostcaptain.page.mail.alias.edit.title=hostcaptain - mail alias - edit |
ak.hostcaptain.page.mail.alias.edit.address=Address |
ak.hostcaptain.page.mail.alias.edit.domain=Domain |
ak.hostcaptain.page.mail.alias.edit.domain.empty=-- please select -- |
ak.hostcaptain.page.mail.alias.edit.owner=Owner |
ak.hostcaptain.page.mail.alias.edit.owner.empty=-- please select -- |
ak.hostcaptain.page.mail.alias.edit.enabled=Enabled |
ak.hostcaptain.page.mail.alias.edit.comment=Comment |
ak.hostcaptain.page.mail.alias.edit.header.tomailbox=To mailbox |
ak.hostcaptain.page.mail.alias.edit.header.toexternal=or to external email |
ak.hostcaptain.page.mail.alias.edit.external=external redirect |
ak.hostcaptain.page.mail.alias.edit.add=add new destination |
ak.hostcaptain.page.mail.alias.edit.delete=delete |
ak.hostcaptain.page.mail.alias.edit.submit=submit |
ak.hostcaptain.page.mail.alias.edit.cancel=cancel |
ak.hostcaptain.page.mail.box.list.title=hostcaptain - mail boxes - list |
ak.hostcaptain.page.mail.box.list.login=Box |
ak.hostcaptain.page.mail.box.list.domain=Domain |
194,7 → 167,7 |
ak.hostcaptain.page.mail.box.edit.domain=Domain |
ak.hostcaptain.page.mail.box.edit.domain.empty=-- please select -- |
ak.hostcaptain.page.mail.box.edit.owner=Owner |
ak.hostcaptain.page.mail.box.edit.owner.empty=-- please select -- |
ak.hostcaptain.page.mail.box.edit.owner.empty=-- create an user -- |
ak.hostcaptain.page.mail.box.edit.systemuser=System user |
ak.hostcaptain.page.mail.box.edit.systemuser.empty=-- please select -- |
ak.hostcaptain.page.mail.box.edit.viruscheck=check mails for viruses |
203,3 → 176,32 |
ak.hostcaptain.page.mail.box.edit.comment=Comment |
ak.hostcaptain.page.mail.box.edit.submit=submit |
ak.hostcaptain.page.mail.box.edit.back=back |
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 |
ak.hostcaptain.page.mail.alias.edit.title=hostcaptain - mail alias - edit |
ak.hostcaptain.page.mail.alias.edit.address=Address |
ak.hostcaptain.page.mail.alias.edit.domain=Domain |
ak.hostcaptain.page.mail.alias.edit.domain.empty=-- please select -- |
ak.hostcaptain.page.mail.alias.edit.owner=Owner |
ak.hostcaptain.page.mail.alias.edit.owner.empty=-- please select -- |
ak.hostcaptain.page.mail.alias.edit.enabled=Enabled |
ak.hostcaptain.page.mail.alias.edit.comment=Comment |
ak.hostcaptain.page.mail.alias.edit.header.tomailbox=To mailbox |
ak.hostcaptain.page.mail.alias.edit.header.toexternal=or to external email |
ak.hostcaptain.page.mail.alias.edit.header.enabled=Enabled |
ak.hostcaptain.page.mail.alias.edit.header.comment=Comment |
ak.hostcaptain.page.mail.alias.edit.external=external redirect |
ak.hostcaptain.page.mail.alias.edit.add=add new destination |
ak.hostcaptain.page.mail.alias.edit.delete=delete |
ak.hostcaptain.page.mail.alias.edit.submit=submit |
ak.hostcaptain.page.mail.alias.edit.back=back |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/SystemUserManager.java |
---|
137,12 → 137,14 |
throws ModelException |
{ |
try { |
if(editor.isSuperuser()) |
if(editor.isSuperuser()) { |
return HibernateUtil.currentSession().find("from SystemUser"); |
else |
} |
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) |
{ |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/User.java |
---|
164,12 → 164,12 |
public boolean viewableBy(User user) |
{ |
return user.isSuperuser() || user.equals(boss); |
return user.isSuperuser() || user.equals(boss) || user.equals(this); |
} |
public boolean editableBy(User user) |
{ |
return user.isSuperuser(); |
return user.isSuperuser() || user.equals(boss); |
} |
public boolean deleteableBy(User user) |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasDestinationManager.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 MailAliasDestinationManager |
{ |
33,16 → 34,27 |
{ |
} |
public MailAliasDestination create() |
public MailAliasDestination create(User editor) |
throws ModelException |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
return new MailAliasDestination(); |
} |
public MailAliasDestination get(Long id) |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
return true; |
} |
public MailAliasDestination get(User editor, Long id) |
throws ModelException |
{ |
MailAliasDestination dest; |
try { |
return (MailAliasDestination)HibernateUtil.currentSession() |
dest = (MailAliasDestination)HibernateUtil.currentSession() |
.load(MailAliasDestination.class, id); |
} |
catch(HibernateException ex) |
49,11 → 61,19 |
{ |
throw new ModelException(ex); |
} |
if(!dest.viewableBy(editor)) |
throw new ModelSecurityException(); |
return dest; |
} |
public void save(MailAliasDestination mailAliasDestination) |
public void save(User editor, MailAliasDestination mailAliasDestination) |
throws ModelException |
{ |
if(!mailAliasDestination.editableBy(editor)) |
throw new ModelSecurityException(); |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAliasDestination); |
} |
63,9 → 83,12 |
} |
} |
public void delete(MailAliasDestination mailAliasDestination) |
public void delete(User editor, MailAliasDestination mailAliasDestination) |
throws ModelException |
{ |
if(!mailAliasDestination.deleteableBy(editor)) |
throw new ModelSecurityException(); |
try { |
HibernateUtil.currentSession().delete(mailAliasDestination); |
} |
75,11 → 98,6 |
} |
} |
public Collection listMailAliasesDestination() |
{ |
return null; |
} |
public Collection listMailAliasesDestination(MailAlias alias) |
throws ModelException |
{ |
94,6 → 112,12 |
} |
} |
public boolean areMailAliasesDestinationsAvailable(User editor) |
throws ModelException |
{ |
return true; |
} |
private static MailAliasDestinationManager mailAliasDestinationManager = null; |
public static MailAliasDestinationManager getInstance() |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/UserManager.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 UserManager |
{ |
33,21 → 35,37 |
{ |
} |
public User create() |
public User create(User editor) |
throws ModelException |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
return new User(); |
} |
public User get(Long id) |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
return editor.isSuperuser(); |
} |
public User get(User editor, Long id) |
throws ModelException |
{ |
User user; |
try { |
return (User)HibernateUtil.currentSession().load(User.class, id); |
user = (User)HibernateUtil.currentSession().load(User.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
if(!user.viewableBy(editor)) |
throw new ModelSecurityException(); |
return user; |
} |
public User findForLogin(String login) |
68,9 → 86,12 |
} |
} |
public void save(User user) |
public void save(User editor, User user) |
throws ModelException |
{ |
if(!user.editableBy(editor)) |
throw new ModelSecurityException(); |
try { |
HibernateUtil.currentSession().saveOrUpdate(user); |
} |
80,9 → 101,12 |
} |
} |
public void delete(User user) |
public void delete(User editor, User user) |
throws ModelException |
{ |
if(!user.deleteableBy(editor)) |
throw new ModelSecurityException(); |
try { |
HibernateUtil.currentSession().delete(user); |
} |
92,11 → 116,19 |
} |
} |
public Collection listUsers() |
public Collection listUsers(User editor) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from User"); |
if(editor.isSuperuser()) { |
return HibernateUtil.currentSession().find("from User"); |
} |
else { |
return HibernateUtil.currentSession().find( |
"from User u where u = ? or u.boss = ?", |
new Object[] { editor, editor}, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } ); |
} |
} |
catch(HibernateException ex) |
{ |
104,6 → 136,27 |
} |
} |
public boolean areSystemUsersAvailable(User editor) |
throws ModelException |
{ |
try { |
if(editor.isSuperuser()) { |
return true; |
} |
else { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"from User u where u = ? or u.boss = ?", |
new Object[] { editor, editor}, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } ) |
.next()).intValue() > 0; |
} |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public User loginUser(String login, String password) |
throws ModelException |
{ |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/WriteTag.java |
---|
0,0 → 1,50 |
// based on struts write tag |
package ak.hostcaptain.core.taglib; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.util.ResponseUtils; |
public class WriteTag |
extends org.apache.struts.taglib.bean.WriteTag |
{ |
protected String defValue; |
public String getDefault() |
{ |
return defValue; |
} |
public void setDefault(String defValue) |
{ |
this.defValue = defValue; |
} |
public int doStartTag() |
throws JspException |
{ |
Object value; |
if(ignore && RequestUtils.lookup(pageContext, name, scope) == null) |
value = null; |
else |
value = RequestUtils.lookup(pageContext, name, property, scope); |
if(value == null) value = defValue; |
if(value != null) { |
if(filter) |
ResponseUtils.write(pageContext, ResponseUtils.filter(formatValue(value))); |
else |
ResponseUtils.write(pageContext, formatValue(value)); |
} |
return SKIP_BODY; |
} |
public void release() |
{ |
super.release(); |
defValue = null; |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/util/StringConverter.java |
---|
2,6 → 2,16 |
public abstract class StringConverter |
{ |
public static boolean isEmpty(Object o) |
{ |
if(o == null) |
return true; |
else if((o instanceof String) && ((String)o).equals("")) |
return true; |
else |
return false; |
} |
public static Long parseLong(Object o) |
throws NumberFormatException |
{ |