/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/LoginAction.java |
---|
0,0 → 1,70 |
package ak.hostadmiral.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.Globals; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.backpath.BackPath; |
import ak.hostadmiral.core.resources.CoreResources; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.servlet.LoginInfo; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class LoginAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
if("show".equals(mapping.getParameter())) { |
return mapping.findForward("default"); |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
User user = UserManager.getInstance().loginUser((String)theForm.get("login"), |
(String)theForm.get("password"), request.getRemoteAddr()); |
if(user == null) { |
Thread.sleep(1000); // FIXME: make this delay configurable |
ActionErrors errors = new ActionErrors(); |
errors.add(ActionMessages.GLOBAL_MESSAGE, |
new ActionError(CoreResources.LOGIN_FAILED)); |
saveErrors(request, errors); |
return mapping.getInputForward(); |
} |
else { |
request.getSession().setAttribute(SessionKeys.USER, user); |
request.getSession().setAttribute(SessionKeys.LOGIN_INFO, |
new LoginInfo(user.getId())); |
request.getSession().setAttribute(Globals.LOCALE_KEY, user.getLocale()); |
String origin = BackPath.findBackPath(request).getBackwardUrl(); |
if(origin == null || origin.length() <= 0) { |
return mapping.findForward("default"); |
} |
else { |
response.sendRedirect(origin); |
return null; |
} |
} |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/UserUpdater.java |
---|
0,0 → 1,53 |
package ak.hostadmiral.core.action; |
import java.util.Map; |
import java.util.Iterator; |
import javax.servlet.http.HttpSession; |
import org.apache.log4j.Logger; |
import org.apache.struts.Globals; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ConfigInit; |
import ak.hostadmiral.servlet.sessioncontrol.SessionControl; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.model.UserModifiedListener; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class UserUpdater |
implements |
ConfigInit, |
UserModifiedListener |
{ |
private static final Logger logger = Logger.getLogger(UserUpdater.class); |
public UserUpdater() |
{ |
} |
public void init(Map params) |
{ |
UserManager.getInstance().addModifiedListener(this); |
logger.info("registered for user modifications"); |
} |
public void userModified(User editor, User user, User oldUser) |
throws ModelException |
{ |
logger.info("user modified: " + user); |
for(Iterator i = SessionControl.getInstance().getSessions().iterator(); i.hasNext(); ) { |
HttpSession s = (HttpSession)i.next(); |
User u = (User)s.getAttribute(SessionKeys.USER); |
if(u != null) { |
if(u.equals(oldUser)) { |
logger.info("update user"); |
s.setAttribute(SessionKeys.USER, user); |
s.setAttribute(Globals.LOCALE_KEY, user.getLocale()); |
} |
} |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/MailAliasAction.java |
---|
0,0 → 1,318 |
package ak.hostadmiral.core.action; |
import java.util.List; |
import java.util.Collection; |
import java.util.Iterator; |
import java.util.Collections; |
import java.util.ArrayList; |
import java.util.HashSet; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.commons.beanutils.BeanUtils; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.StringConverter; |
import ak.hostadmiral.util.UserException; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.core.resources.CoreResources; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.model.Mailbox; |
import ak.hostadmiral.core.model.MailboxManager; |
import ak.hostadmiral.core.model.MailAlias; |
import ak.hostadmiral.core.model.MailAliasManager; |
import ak.hostadmiral.core.model.MailAliasDestination; |
import ak.hostadmiral.core.model.MailAliasDestinationManager; |
import ak.hostadmiral.core.model.InetDomainManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
import ak.hostadmiral.core.form.MailAliasDestBean; |
public final class MailAliasAction |
extends Action |
implements ErrorHandlerX |
{ |
public static final int PAGE_SIZE = 20; |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
if("submit".equals(mapping.getParameter())) { |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
initLists(request, user); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
if("list".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long page = StringConverter.parseLong(theForm.get("pg")); |
CollectionInfo listInfo = new CollectionInfo(); |
Collection list = MailAliasManager.getInstance().listMailAliases( |
listInfo, PAGE_SIZE, (page == null) ? 0 : page.intValue(), |
new Integer[] { MailAliasManager.SORT_DOMAIN, MailAliasManager.SORT_ADDRESS }, |
user); |
request.setAttribute("aliases", list); |
request.setAttribute("listInfo", listInfo); |
request.setAttribute("allowedToCreate", |
Boolean.valueOf(MailAliasManager.getInstance().allowedToCreate(user))); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
MailAlias alias; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
List dests; |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "MailAliasEditForm"); |
if(aliasId == null) { |
alias = MailAliasManager.getInstance().create(user); |
dests = new ArrayList(); |
showForm.set("enabled", Boolean.TRUE); |
} |
else { |
alias = MailAliasManager.getInstance().get(user, aliasId); |
dests = new ArrayList(MailAliasDestinationManager.getInstance() |
.listMailAliasesDestination(alias)); |
MailAliasDestBean[] d = new MailAliasDestBean[dests.size()]; |
// FIXME: sort dests here |
for(int i = 0; i < dests.size(); i++) { |
d[i] = new MailAliasDestBean((MailAliasDestination)dests.get(i)); |
} |
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("enabled", alias.getEnabled()); |
showForm.set("comment", alias.getComment()); |
} |
initLists(request, user); |
request.setAttribute("alias", alias); |
request.setAttribute("dests", dests); |
if(alias.editableBy(user)) |
return mapping.findForward("default"); |
else if(alias.mayChangeDestinations(user)) |
return mapping.findForward("editdests"); |
else |
return mapping.findForward("view"); |
} |
else if("deleting".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
MailAlias alias = MailAliasManager.getInstance().get(user, aliasId); |
request.setAttribute("action", "/mail/alias/delete.do"); |
request.setAttribute("object", alias); |
request.setAttribute("cascade", |
MailAliasManager.getInstance().beforeDelete(user, alias, new HashSet())); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
MailAlias alias = MailAliasManager.getInstance().get(user, aliasId); |
MailAliasManager.getInstance().delete(user, alias); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long aliasId = StringConverter.parseLong(theForm.get("id")); |
MailAlias alias = (aliasId == null) |
? MailAliasManager.getInstance().create(user) |
: MailAliasManager.getInstance().get(user, aliasId); |
MailAliasDestBean[] dests = (MailAliasDestBean[])theForm.get("dests"); |
// 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"))) { |
handleErrors(mapping, form, request, response); |
throw new UserException("ak.hostadmiral.core.mail.alias.edit.address.empty"); |
} |
if(StringConverter.isEmpty(theForm.get("domain"))) { |
handleErrors(mapping, form, request, response); |
throw new UserException("ak.hostadmiral.core.mail.alias.edit.domain.wrong"); |
} |
if(StringConverter.isEmpty(theForm.get("owner"))) { |
handleErrors(mapping, form, request, response); |
throw new UserException("ak.hostadmiral.core.mail.alias.edit.owner.wrong"); |
} |
alias.setDomain(user, InetDomainManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("domain")))); |
String address = (String)theForm.get("address"); |
if(MailAliasManager.getInstance().addressExists(user, alias, address)) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.NONUNIQUE_MAIL_ALIAS_ADDRESS); |
} |
alias.setAddress(user, address); |
alias.setOwner(user, UserManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("owner")))); |
alias.setEnabled(user, (Boolean)theForm.get("enabled")); |
alias.setComment(user, (String)theForm.get("comment")); |
alias.getDestinations(user).clear(); |
for(int i = 0; i < dests.length; i++) { |
// FIXME: validate dest id, mailbox id, email |
// skip empty rows |
if((dests[i].getMailbox() == null) |
&& (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()); |
MailAliasDestination dest; |
if(destId == null) |
dest = MailAliasDestinationManager.getInstance().create(user); |
else |
dest = MailAliasDestinationManager.getInstance().get(user, destId); |
// connect |
dest.setAlias(user, alias); |
alias.getDestinations(user).add(dest); |
// set mailbox or email |
if(mailboxId != null) { |
dest.setMailbox(user, MailboxManager.getInstance().get(user, mailboxId)); |
dest.setEmail(user, null); |
} |
else if(dests[i].getEmail() != null && !dests[i].getEmail().equals("")) { |
dest.setMailbox(user, null); |
dest.setEmail(user, dests[i].getEmail()); |
} |
dest.setEnabled(user, dests[i].getEnabled()); |
dest.setComment(user, dests[i].getComment()); |
} |
// update alias |
MailAliasManager.getInstance().save(user, alias); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
// 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]; |
if(dests.length > 0) |
System.arraycopy(dests, 0, newDests, 0, dests.length); |
newDests[dests.length] = new MailAliasDestBean(); |
newDests[dests.length].setEnabled(Boolean.TRUE); |
theForm.set("dests", newDests); |
initLists(request, user); |
request.setAttribute("alias", alias); |
request.setAttribute("dests", newDests); |
if(alias.editableBy(user)) |
return mapping.findForward("default"); |
else if(alias.mayChangeDestinations(user)) |
return mapping.findForward("editdests"); |
else |
return mapping.findForward("view"); |
} |
// delete |
else { |
Iterator iter = request.getParameterMap().keySet().iterator(); |
while(iter.hasNext()) { |
String name = (String)iter.next(); |
if(name.startsWith("delete.dests[")) { |
int p = name.indexOf("]"); |
if(p > 0) { |
String index = name.substring("delete.dests[".length(), p); |
try { |
int n = Integer.parseInt(index); |
if(n < 0 || n >= dests.length) break; |
MailAliasDestBean[] newDests; |
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); |
request.setAttribute("dests", newDests); |
break; |
} |
catch(NumberFormatException ex) { |
} |
} |
} |
} |
initLists(request, user); |
request.setAttribute("alias", alias); |
if(alias.editableBy(user)) |
return mapping.findForward("default"); |
else if(alias.mayChangeDestinations(user)) |
return mapping.findForward("editdests"); |
else |
return mapping.findForward("view"); |
} |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initLists(HttpServletRequest request, User user) |
throws Exception |
{ |
// 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(user)); |
Collections.sort(users, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", users); |
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains(user)); |
Collections.sort(domains, InetDomainManager.NAME_COMPARATOR); |
request.setAttribute("domains", domains); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/UserAction.java |
---|
0,0 → 1,238 |
package ak.hostadmiral.core.action; |
import java.util.List; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.ArrayList; |
import java.util.HashSet; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.StringConverter; |
import ak.hostadmiral.util.UserException; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.core.resources.CoreResources; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class UserAction |
extends Action |
implements ErrorHandlerX |
{ |
public static final int PAGE_SIZE = 20; |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
if("submit".equals(mapping.getParameter()) || "partsubmit".equals(mapping.getParameter())) { |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
initUserList(request, user); |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId; |
User u; |
try { |
userId = StringConverter.parseLong(theForm.get("id")); |
} |
catch(NumberFormatException ex) { |
userId = null; |
} |
if(userId == null) |
u = UserManager.getInstance().create(user); |
else |
u = UserManager.getInstance().get(user, userId); |
request.setAttribute("u", u); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
if("list".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long page = StringConverter.parseLong(theForm.get("pg")); |
CollectionInfo listInfo = new CollectionInfo(); |
Collection list = UserManager.getInstance().listUsers( |
listInfo, PAGE_SIZE, (page == null) ? 0 : page.intValue(), |
new Integer[] { UserManager.SORT_LOGIN }, user); |
request.setAttribute("users", list); |
request.setAttribute("listInfo", listInfo); |
request.setAttribute("allowedToCreate", |
Boolean.valueOf(UserManager.getInstance().allowedToCreate(user))); |
request.setAttribute("mayViewAllLogins", Boolean.valueOf(user.mayViewAllLogins())); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u; |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "UserEditForm"); |
if(userId == null) { |
u = UserManager.getInstance().create(user); |
showForm.set("enabled", Boolean.TRUE); |
} |
else { |
u = UserManager.getInstance().get(user, userId); |
showForm.set("login", u.getLogin()); |
if(u.getBoss() != null) |
showForm.set("boss", StringConverter.toString(u.getBoss().getId())); |
showForm.set("superuser", u.getSuperuser()); |
showForm.set("locale", u.getLocale().toString()); |
showForm.set("enabled", u.getEnabled()); |
showForm.set("comment", u.getComment()); |
} |
initUserList(request, user); |
request.setAttribute("u", u); |
if(u.editableBy(user)) |
return mapping.findForward("default"); |
else |
return mapping.findForward("view"); |
} |
else if("partedit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u = UserManager.getInstance().get(user, userId); |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "UserPartEditForm"); |
showForm.set("locale", u.getLocale().toString()); |
initUserList(request, user); |
request.setAttribute("u", u); |
return mapping.findForward("default"); |
} |
else if("deleting".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u = UserManager.getInstance().get(user, userId); |
request.setAttribute("action", "/user/delete.do"); |
request.setAttribute("object", u); |
request.setAttribute("cascade", |
UserManager.getInstance().beforeDelete(user, u, new HashSet())); |
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(user, userId); |
request.setAttribute("u", u); |
if(u.equals(user)) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.DELETE_ME_SELF); |
} |
// 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(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u; |
String password = (String)theForm.get("password"); |
if(userId == null) { |
if(password == null || password.equals("")) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.PASSWORD_REQUIRED); |
} |
u = UserManager.getInstance().create(user); |
} |
else { |
u = UserManager.getInstance().get(user, userId); |
} |
request.setAttribute("u", u); |
String login = (String)theForm.get("login"); |
if(UserManager.getInstance().loginExists(user, u, login)) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.NONUNIQUE_USER_LOGIN); |
} |
u.setLogin(user, login); |
if(u.mayChangeBoss(user)) { |
Long bossId = StringConverter.parseLong(theForm.get("boss")); |
if(bossId == null) |
u.setBoss(user, null); |
else |
u.setBoss(user, UserManager.getInstance().get(user, bossId)); |
} |
if(u.editableBy(user)) { |
u.setLocaleName(user, (String)theForm.get("locale")); |
u.setEnabled(user, (Boolean)theForm.get("enabled")); |
u.setComment(user, (String)theForm.get("comment")); |
} |
if(u.mayChangeSuperuser(user)) |
u.setSuperuser(user, (Boolean)theForm.get("superuser")); |
if(password != null && !password.equals("") |
&& u.editableBy(user) // more strong condition, because normal |
&& u.partEditableBy(user)) // user have to enter first the old password |
{ |
u.setPassword(user, password); |
} |
UserManager.getInstance().save(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("partsubmit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u = UserManager.getInstance().get(user, userId); |
u.setLocaleName(user, (String)theForm.get("locale")); |
UserManager.getInstance().save(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initUserList(HttpServletRequest request, User user) |
throws Exception |
{ |
List list = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/FailedLoginsAction.java |
---|
0,0 → 1,38 |
package ak.hostadmiral.core.action; |
import java.util.List; |
import java.util.Collections; |
import java.util.ArrayList; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import ak.hostadmiral.util.StringConverter; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class FailedLoginsAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
List logins = new ArrayList(UserManager.getInstance().listFailedLogins(user)); |
Collections.sort(logins, UserManager.LOGINS_TIME_COMPARATOR); |
Collections.reverse(logins); |
request.setAttribute("logins", logins); |
return mapping.findForward("default"); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/SystemUserAction.java |
---|
0,0 → 1,174 |
package ak.hostadmiral.core.action; |
import java.util.List; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.ArrayList; |
import java.util.HashSet; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.StringConverter; |
import ak.hostadmiral.util.UserException; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.core.resources.CoreResources; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.model.SystemUser; |
import ak.hostadmiral.core.model.SystemUserManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class SystemUserAction |
extends Action |
implements ErrorHandlerX |
{ |
public static final int PAGE_SIZE = 20; |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
if("submit".equals(mapping.getParameter())) { |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
initUserList(request, user); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
if("list".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long page = StringConverter.parseLong(theForm.get("pg")); |
CollectionInfo listInfo = new CollectionInfo(); |
Collection list = SystemUserManager.getInstance().listSystemUsers( |
listInfo, PAGE_SIZE, (page == null) ? 0 : page.intValue(), |
new Integer[] { SystemUserManager.SORT_NAME }, user); |
request.setAttribute("users", list); |
request.setAttribute("listInfo", listInfo); |
request.setAttribute("allowedToCreate", |
Boolean.valueOf(SystemUserManager.getInstance().allowedToCreate(user))); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
SystemUser u; |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "SystemUserEditForm"); |
if(userId == null) { |
u = SystemUserManager.getInstance().create(user); |
showForm.set("enabled", Boolean.TRUE); |
} |
else { |
u = SystemUserManager.getInstance().get(user, userId); |
showForm.set("uid", StringConverter.toString(u.getUid())); |
showForm.set("name", u.getName()); |
if(u.getOwner() != null) |
showForm.set("owner", StringConverter.toString(u.getOwner().getId())); |
showForm.set("enabled", u.getEnabled()); |
showForm.set("comment", u.getComment()); |
} |
initUserList(request, user); |
request.setAttribute("u", u); |
if(u.editableBy(user)) |
return mapping.findForward("default"); |
else |
return mapping.findForward("view"); |
} |
else if("deleting".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
SystemUser u = SystemUserManager.getInstance().get(user, userId); |
request.setAttribute("action", "/user/system/delete.do"); |
request.setAttribute("object", u); |
request.setAttribute("cascade", |
SystemUserManager.getInstance().beforeDelete(user, u, new HashSet())); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
SystemUser u = SystemUserManager.getInstance().get(user, userId); |
SystemUserManager.getInstance().delete(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
SystemUser u; |
if(userId == null) { |
u = SystemUserManager.getInstance().create(user); |
} |
else { |
u = SystemUserManager.getInstance().get(user, userId); |
} |
Integer uid = StringConverter.parseInteger(theForm.get("uid")); |
if(SystemUserManager.getInstance().uidExists(user, u, uid)) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.NONUNIQUE_SYSTEM_USER_UID); |
} |
u.setUid(user, uid); |
String name = (String)theForm.get("name"); |
if(SystemUserManager.getInstance().nameExists(user, u, name)) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.NONUNIQUE_SYSTEM_USER_NAME); |
} |
u.setName(user, name); |
Long ownerId = StringConverter.parseLong(theForm.get("owner")); |
if(ownerId == null) |
u.setOwner(user, null); |
else |
u.setOwner(user, UserManager.getInstance().get(user, ownerId)); |
u.setEnabled(user, (Boolean)theForm.get("enabled")); |
u.setComment(user, (String)theForm.get("comment")); |
SystemUserManager.getInstance().save(user, u); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initUserList(HttpServletRequest request, User user) |
throws Exception |
{ |
List list = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/IndexAction.java |
---|
0,0 → 1,40 |
package ak.hostadmiral.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionForward; |
import ak.hostadmiral.util.ProjectVersion; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.SystemUserManager; |
import ak.hostadmiral.core.model.InetDomainManager; |
import ak.hostadmiral.core.model.MailboxManager; |
import ak.hostadmiral.core.model.MailAliasManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class IndexAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
request.setAttribute("showSystemUsers", |
Boolean.valueOf(SystemUserManager.getInstance().areSystemUsersAvailable(user))); |
request.setAttribute("showInetDomains", |
Boolean.valueOf(InetDomainManager.getInstance().areInetDomainsAvailable(user))); |
request.setAttribute("showMailboxes", |
Boolean.valueOf(MailboxManager.getInstance().areMailboxesAvailable(user))); |
request.setAttribute("showMailAliases", |
Boolean.valueOf(MailAliasManager.getInstance().areMailAliasesAvailable(user))); |
return mapping.findForward("success"); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/InetDomainAction.java |
---|
0,0 → 1,163 |
package ak.hostadmiral.core.action; |
import java.util.List; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.ArrayList; |
import java.util.HashSet; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.StringConverter; |
import ak.hostadmiral.util.UserException; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.core.resources.CoreResources; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.model.InetDomain; |
import ak.hostadmiral.core.model.InetDomainManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class InetDomainAction |
extends Action |
implements ErrorHandlerX |
{ |
public static final int PAGE_SIZE = 20; |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
if("submit".equals(mapping.getParameter())) { |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
initUserList(request, user); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
if("list".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long page = StringConverter.parseLong(theForm.get("pg")); |
CollectionInfo listInfo = new CollectionInfo(); |
Collection list = InetDomainManager.getInstance().listInetDomains( |
listInfo, PAGE_SIZE, (page == null) ? 0 : page.intValue(), |
new Integer[] { InetDomainManager.SORT_NAME }, user); |
request.setAttribute("domains", list); |
request.setAttribute("listInfo", listInfo); |
request.setAttribute("allowedToCreate", |
Boolean.valueOf(InetDomainManager.getInstance().allowedToCreate(user))); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long domainId = StringConverter.parseLong(theForm.get("id")); |
InetDomain domain; |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "InetDomainEditForm"); |
if(domainId == null) { |
domain = InetDomainManager.getInstance().create(user); |
showForm.set("enabled", Boolean.TRUE); |
} |
else { |
domain = InetDomainManager.getInstance().get(user, domainId); |
showForm.set("name", domain.getName()); |
if(domain.getOwner() != null) |
showForm.set("owner", StringConverter.toString(domain.getOwner().getId())); |
showForm.set("enabled", domain.getEnabled()); |
showForm.set("comment", domain.getComment()); |
} |
initUserList(request, user); |
request.setAttribute("domain", domain); |
if(domain.editableBy(user)) |
return mapping.findForward("default"); |
else |
return mapping.findForward("view"); |
} |
else if("deleting".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long domainId = StringConverter.parseLong(theForm.get("id")); |
InetDomain domain = InetDomainManager.getInstance().get(user, domainId); |
request.setAttribute("action", "/domain/delete.do"); |
request.setAttribute("object", domain); |
request.setAttribute("cascade", |
InetDomainManager.getInstance().beforeDelete(user, domain, new HashSet())); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long domainId = StringConverter.parseLong(theForm.get("id")); |
InetDomain domain = InetDomainManager.getInstance().get(user, domainId); |
InetDomainManager.getInstance().delete(user, domain); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long domainId = StringConverter.parseLong(theForm.get("id")); |
InetDomain domain; |
if(domainId == null) { |
domain = InetDomainManager.getInstance().create(user); |
} |
else { |
domain = InetDomainManager.getInstance().get(user, domainId); |
} |
String name = (String)theForm.get("name"); |
if(InetDomainManager.getInstance().nameExists(user, domain, name)) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.NONUNIQUE_DOMAIN_NAME); |
} |
domain.setName(user, name); |
domain.setOwner(user, UserManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("owner")))); |
domain.setEnabled(user, (Boolean)theForm.get("enabled")); |
domain.setComment(user, (String)theForm.get("comment")); |
InetDomainManager.getInstance().save(user, domain); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initUserList(HttpServletRequest request, User user) |
throws Exception |
{ |
List list = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", list); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/ChangePasswordAction.java |
---|
0,0 → 1,53 |
package ak.hostadmiral.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.backpath.BackPath; |
import ak.hostadmiral.core.resources.CoreResources; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class ChangePasswordAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
if("first".equals(mapping.getParameter())) { |
return mapping.findForward("default"); |
} |
else { |
DynaActionForm theForm = (DynaActionForm)form; |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
if(user.checkPassword((String)theForm.get("oldpassword"))) { |
user.setPassword(user, (String)theForm.get("password")); |
UserManager.getInstance().save(user, user); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
ActionErrors errors = new ActionErrors(); |
errors.add(ActionMessages.GLOBAL_MESSAGE, |
new ActionError(CoreResources.OLD_PASSWORD_WRONG)); |
saveErrors(request, errors); |
return mapping.getInputForward(); |
} |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/UserLoginsAction.java |
---|
0,0 → 1,49 |
package ak.hostadmiral.core.action; |
import java.util.List; |
import java.util.Collection; |
import java.util.Collections; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import ak.hostadmiral.util.StringConverter; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class UserLoginsAction |
extends Action |
{ |
public static final int PAGE_SIZE = 20; |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
DynaActionForm theForm = (DynaActionForm)form; |
Long userId = StringConverter.parseLong(theForm.get("id")); |
User u = UserManager.getInstance().get(user, userId); |
Long page = StringConverter.parseLong(theForm.get("pg")); |
CollectionInfo listInfo = new CollectionInfo(); |
Collection logins = UserManager.getInstance().listUserLogins( |
listInfo, PAGE_SIZE, (page == null) ? 0 : page.intValue(), |
new Integer[] { UserManager.SORT_LOGINS_TIME_REVERSE }, user, u); |
request.setAttribute("u", u); |
request.setAttribute("logins", logins); |
request.setAttribute("listInfo", listInfo); |
return mapping.findForward("default"); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/MailboxAction.java |
---|
0,0 → 1,205 |
package ak.hostadmiral.core.action; |
import java.util.List; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.ArrayList; |
import java.util.HashSet; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.hostadmiral.util.StringConverter; |
import ak.hostadmiral.util.UserException; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.core.resources.CoreResources; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.model.Mailbox; |
import ak.hostadmiral.core.model.MailboxManager; |
import ak.hostadmiral.core.model.SystemUserManager; |
import ak.hostadmiral.core.model.InetDomainManager; |
import ak.hostadmiral.core.servlet.SessionKeys; |
public final class MailboxAction |
extends Action |
implements ErrorHandlerX |
{ |
public static final int PAGE_SIZE = 20; |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
if("submit".equals(mapping.getParameter())) { |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
initLists(request, user); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
User user = (User)request.getSession().getAttribute(SessionKeys.USER); |
if("list".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long page = StringConverter.parseLong(theForm.get("pg")); |
CollectionInfo listInfo = new CollectionInfo(); |
Collection list = MailboxManager.getInstance().listMailboxes( |
listInfo, PAGE_SIZE, (page == null) ? 0 : page.intValue(), |
new Integer[] { MailboxManager.SORT_DOMAIN, MailboxManager.SORT_LOGIN }, user); |
request.setAttribute("mailboxes", list); |
request.setAttribute("listInfo", listInfo); |
request.setAttribute("allowedToCreate", |
Boolean.valueOf(MailboxManager.getInstance().allowedToCreate(user))); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long boxId = StringConverter.parseLong(theForm.get("id")); |
Mailbox mailbox; |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "MailboxEditForm"); |
if(boxId == null) { |
mailbox = MailboxManager.getInstance().create(user); |
showForm.set("enabled", Boolean.TRUE); |
showForm.set("viruscheck", Boolean.TRUE); |
showForm.set("spamcheck", Boolean.TRUE); |
} |
else { |
mailbox = MailboxManager.getInstance().get(user, boxId); |
showForm.set("login", mailbox.getLogin()); |
if(mailbox.getDomain() != null) |
showForm.set("domain", StringConverter.toString(mailbox.getDomain().getId())); |
if(mailbox.getOwner() != null) |
showForm.set("owner", StringConverter.toString(mailbox.getOwner().getId())); |
showForm.set("viruscheck", mailbox.getVirusCheck()); |
showForm.set("spamcheck", mailbox.getSpamCheck()); |
if(mailbox.getSystemUser() != null) |
showForm.set("systemuser", StringConverter.toString(mailbox.getSystemUser().getId())); |
showForm.set("enabled", mailbox.getEnabled()); |
showForm.set("comment", mailbox.getComment()); |
} |
initLists(request, user); |
request.setAttribute("mailbox", mailbox); |
if(mailbox.editableBy(user)) |
return mapping.findForward("default"); |
else |
return mapping.findForward("view"); |
} |
else if("deleting".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long boxId = StringConverter.parseLong(theForm.get("id")); |
Mailbox mailbox = MailboxManager.getInstance().get(user, boxId); |
request.setAttribute("action", "/mail/box/delete.do"); |
request.setAttribute("object", mailbox); |
request.setAttribute("cascade", |
MailboxManager.getInstance().beforeDelete(user, mailbox, new HashSet())); |
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(user, boxId); |
MailboxManager.getInstance().delete(user, mailbox); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long boxId = StringConverter.parseLong(theForm.get("id")); |
Mailbox mailbox; |
String password = (String)theForm.get("password"); |
if(boxId == null) { |
if(password == null || password.equals("")) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.PASSWORD_REQUIRED); |
} |
mailbox = MailboxManager.getInstance().create(user); |
// FIXME: create an user as owner of the new mailbox here, |
// create a mail alias with the same name |
} |
else { |
mailbox = MailboxManager.getInstance().get(user, boxId); |
} |
mailbox.setDomain(user, InetDomainManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("domain")))); |
String login = (String)theForm.get("login"); |
if(MailboxManager.getInstance().loginExists(user, mailbox, login)) { |
handleErrors(mapping, form, request, response); |
throw new UserException(CoreResources.NONUNIQUE_MAILBOX_LOGIN); |
} |
mailbox.setLogin(user, login); |
mailbox.setOwner(user, UserManager.getInstance().get(user, |
StringConverter.parseLong(theForm.get("owner")))); |
mailbox.setVirusCheck(user, (Boolean)theForm.get("viruscheck")); |
mailbox.setSpamCheck(user, (Boolean)theForm.get("spamcheck")); |
Long systemUserId = StringConverter.parseLong(theForm.get("systemuser")); |
if(systemUserId == null) { |
mailbox.setSystemUser(user, null); |
} |
else { |
mailbox.setSystemUser(user, SystemUserManager.getInstance().get(user, systemUserId)); |
} |
if(password != null && !password.equals("")) |
mailbox.setPassword(user, password); |
mailbox.setEnabled(user, (Boolean)theForm.get("enabled")); |
mailbox.setComment(user, (String)theForm.get("comment")); |
MailboxManager.getInstance().save(user, mailbox); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initLists(HttpServletRequest request, User user) |
throws Exception |
{ |
List users = new ArrayList(UserManager.getInstance().listUsers(user)); |
Collections.sort(users, UserManager.LOGIN_COMPARATOR); |
request.setAttribute("users", users); |
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(user)); |
Collections.sort(domains, InetDomainManager.NAME_COMPARATOR); |
request.setAttribute("domains", domains); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/GeneralExceptionHandler.java |
---|
0,0 → 1,131 |
package ak.hostadmiral.core.action; |
import javax.servlet.ServletException; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.Globals; |
import org.apache.struts.action.ActionError; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ExceptionHandler; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.config.ExceptionConfig; |
import org.apache.log4j.Logger; |
import ak.strutsx.ErrorHandlerX; |
import ak.hostadmiral.util.UserException; |
import ak.hostadmiral.util.ModelUserException; |
import ak.hostadmiral.util.ModelSecurityException; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.FormException; |
public final class GeneralExceptionHandler |
extends ExceptionHandler |
{ |
private static final Logger logger = Logger.getLogger(GeneralExceptionHandler.class); |
public ActionForward execute(Exception ex, ExceptionConfig config, |
ActionMapping mapping, ActionForm formInstance, |
HttpServletRequest request, HttpServletResponse response) |
throws ServletException |
{ |
if(ex instanceof UserException) { |
return handleUserException((UserException)ex, |
config, mapping, formInstance, request, response); |
} |
else if(ex instanceof ModelUserException) { |
return handleModelUserException((ModelUserException)ex, |
config, mapping, formInstance, request, response); |
} |
else if(ex instanceof ModelSecurityException) { |
logger.error("security exception", ex); |
Exception subex = ((ModelSecurityException)ex).getChainedException(); |
if(subex != null && subex instanceof ModelException) |
logChainedException((ModelSecurityException)subex); |
return mapping.findForward("accessDenied"); |
} |
else if(ex instanceof ModelException) { |
logger.error("model exception", ex); |
Exception subex = ((ModelException)ex).getChainedException(); |
if(subex != null && subex instanceof ModelException) |
logChainedException((ModelException)subex); |
return mapping.findForward("generalError"); |
} |
else { |
logger.error("unhandled exception", ex); |
return mapping.findForward("generalError"); |
} |
} |
protected void logChainedException(ModelException ex) |
{ |
logger.error("chained exception", ex); |
Exception subex = ex.getChainedException(); |
if(subex != null && subex instanceof ModelException) |
logChainedException((ModelException)subex); |
} |
protected ActionForward handleUserException(UserException ex, ExceptionConfig config, |
ActionMapping mapping, ActionForm formInstance, |
HttpServletRequest request, HttpServletResponse response) |
throws ServletException |
{ |
logger.info("user exception handle:" + ex.getMessage()); |
request.setAttribute("TRANSACTION_FAILED", Boolean.TRUE); |
// try to get property for this exception if any |
String property = ActionMessages.GLOBAL_MESSAGE; |
if(ex instanceof FormException) { |
FormException formEx = (FormException)ex; |
if(formEx.getProperty() != null) |
property = formEx.getProperty(); |
} |
// create new error message |
ActionErrors errors = (ActionErrors)request.getAttribute(Globals.ERROR_KEY); |
if(errors == null) { |
errors = new ActionErrors(); |
request.setAttribute(Globals.ERROR_KEY, errors); |
} |
errors.add(property, new ActionError(ex.getMessage(), ex.getValues())); |
// find forward |
if(mapping.getInput() == null) |
return mapping.findForward("error"); |
else |
return mapping.getInputForward(); |
} |
protected ActionForward handleModelUserException(ModelUserException ex, ExceptionConfig config, |
ActionMapping mapping, ActionForm formInstance, |
HttpServletRequest request, HttpServletResponse response) |
throws ServletException |
{ |
logger.info("model user exception handle:" + ex.getMessage()); |
request.setAttribute("TRANSACTION_FAILED", Boolean.TRUE); |
// create new error message |
ActionErrors errors = (ActionErrors)request.getAttribute(Globals.ERROR_KEY); |
if(errors == null) { |
errors = new ActionErrors(); |
request.setAttribute(Globals.ERROR_KEY, errors); |
} |
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionError(ex.getMessage(), ex.getValues())); |
// find forward |
if(mapping.getInput() == null) |
return mapping.findForward("error"); |
else |
return mapping.getInputForward(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/ActionUtils.java |
---|
0,0 → 1,15 |
package ak.hostadmiral.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import ak.hostadmiral.util.ProjectVersion; |
public final class ActionUtils |
{ |
public static void prepare(HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
request.setAttribute("projectVersion", ProjectVersion.getVersion()); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/action/LogoutAction.java |
---|
0,0 → 1,28 |
package ak.hostadmiral.core.action; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
public final class LogoutAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
ActionUtils.prepare(request, response); |
if(request.getSession() != null) |
request.getSession().invalidate(); |
return mapping.findForward("default"); |
} |
} |