Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 902 → Rev 903

/sun/hostcaptain/trunk/src/ak/webcontrol/core/CoreResources.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/form/UserPasswordForm.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/form/MailAliasDestBean.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/servlet/HibernateFilter.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/servlet/EncodingFilter.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/servlet/LoginFilter.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/MailAliasAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/UserExceptionHandler.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/UserAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/SystemUserAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/InetDomainAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/IndexAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/LoginAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/ChangePasswordAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/LogoutAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/action/MailboxAction.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/CoreResources.properties
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/MailAliasDestination.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/SystemUserManager.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/User.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/test/Test.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/InetDomainManager.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/SystemUser.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/MailboxManager.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/ModelObject.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/MailAliasManager.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/InetDomain.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/UserManager.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/MailAliasDestinationManager.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/Mailbox.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/core/model/MailAlias.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/util/HibernateUtil.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/util/ModelException.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/util/Digest.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/util/FormException.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/util/UserException.java
File deleted
/sun/hostcaptain/trunk/src/ak/webcontrol/util/StringConverter.java
File deleted
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/IndexAction.java
0,0 → 1,28
package ak.webcontrol.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.strutsx.ErrorHandlerX;
 
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
{
return mapping.findForward("success");
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/InetDomainAction.java
0,0 → 1,115
package ak.webcontrol.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 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.webcontrol.util.StringConverter;
import ak.webcontrol.core.model.User;
import ak.webcontrol.core.model.UserManager;
import ak.webcontrol.core.model.InetDomain;
import ak.webcontrol.core.model.InetDomainManager;
 
public final class InetDomainAction
extends Action
implements ErrorHandlerX
{
public void handleErrors(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
if("submit".equals(mapping.getParameter())) {
initUserList(request);
}
}
 
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
User user = (User)request.getSession().getAttribute("user");
 
if("list".equals(mapping.getParameter())) {
List list = new ArrayList(InetDomainManager.getInstance().listInetDomains());
Collections.sort(list, InetDomainManager.NAME_COMPARATOR);
request.setAttribute("domains", list);
 
return mapping.findForward("default");
}
else if("edit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long domainId = StringConverter.parseLong(theForm.get("id"));
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ak.webcontrol.core.form.InetDomainEditForm");
 
if(domainId == null) {
 
}
else {
InetDomain domain = InetDomainManager.getInstance().get(domainId);
showForm.set("name", domain.getName());
if(domain.getOwner() != null)
showForm.set("owner", StringConverter.toString(domain.getOwner().getId()));
}
 
initUserList(request);
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(domainId);
 
InetDomainManager.getInstance().delete(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();
}
else {
domain = InetDomainManager.getInstance().get(domainId);
}
 
domain.setName((String)theForm.get("name"));
domain.setOwner(UserManager.getInstance().get(
StringConverter.parseLong(theForm.get("owner"))));
 
InetDomainManager.getInstance().save(domain);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
else {
throw new Exception("unknown mapping parameter");
}
}
 
private void initUserList(HttpServletRequest request)
throws Exception
{
List list = new ArrayList(UserManager.getInstance().listUsers());
Collections.sort(list, UserManager.LOGIN_COMPARATOR);
request.setAttribute("users", list);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/ChangePasswordAction.java
0,0 → 1,51
package ak.webcontrol.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.webcontrol.core.CoreResources;
import ak.webcontrol.core.model.User;
import ak.webcontrol.core.model.UserManager;
 
public final class ChangePasswordAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
if("first".equals(mapping.getParameter())) {
return mapping.findForward("default");
}
else {
DynaActionForm theForm = (DynaActionForm)form;
 
User user = (User)request.getSession().getAttribute("user");
 
if(user.checkPassword((String)theForm.get("oldpassword"))) {
user.setNewPassword((String)theForm.get("password"));
UserManager.getInstance().save(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();
}
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/LoginAction.java
0,0 → 1,53
package ak.webcontrol.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.webcontrol.core.CoreResources;
import ak.webcontrol.core.model.User;
import ak.webcontrol.core.model.UserManager;
 
public final class LoginAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
DynaActionForm theForm = (DynaActionForm)form;
 
User user = UserManager.getInstance().loginUser(
(String)theForm.get("login"), (String)theForm.get("password"));
 
if(user == null) {
ActionErrors errors = new ActionErrors();
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionError(CoreResources.LOGIN_FAILED));
saveErrors(request, errors);
return mapping.getInputForward();
}
else {
request.getSession().setAttribute("user", user);
 
String origin = BackPath.findBackPath(request).getBackwardUrl();
if(origin == null || origin.length() <= 0) {
return mapping.findForward("default");
}
else {
response.sendRedirect(origin);
return null;
}
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/LogoutAction.java
0,0 → 1,27
package ak.webcontrol.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
{
if(request.getSession() != null)
request.getSession().invalidate();
 
return mapping.findForward("default");
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/MailboxAction.java
0,0 → 1,151
package ak.webcontrol.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 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.webcontrol.util.StringConverter;
import ak.webcontrol.core.model.User;
import ak.webcontrol.core.model.UserManager;
import ak.webcontrol.core.model.Mailbox;
import ak.webcontrol.core.model.MailboxManager;
import ak.webcontrol.core.model.SystemUserManager;
import ak.webcontrol.core.model.InetDomainManager;
 
public final class MailboxAction
extends Action
implements ErrorHandlerX
{
public void handleErrors(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
if("submit".equals(mapping.getParameter())) {
initLists(request);
}
}
 
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
User user = (User)request.getSession().getAttribute("user");
if("list".equals(mapping.getParameter())) {
List list = new ArrayList(MailboxManager.getInstance().listMailboxes());
Collections.sort(list, MailboxManager.LOGIN_COMPARATOR);
request.setAttribute("mailboxes", list);
 
return mapping.findForward("default");
}
else if("edit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long boxId = StringConverter.parseLong(theForm.get("id"));
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ak.webcontrol.core.form.MailboxEditForm");
 
if(boxId == null) {
 
}
else {
Mailbox mailbox = MailboxManager.getInstance().get(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()));
}
 
initLists(request);
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);
 
MailboxManager.getInstance().delete(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(""))
throw new Exception("empty password"); // FIXME: exception type and message?
 
mailbox = MailboxManager.getInstance().create();
 
// FIXME: create an user as owner of the new mailbox here
}
else {
mailbox = MailboxManager.getInstance().get(boxId);
}
 
mailbox.setLogin((String)theForm.get("login"));
mailbox.setDomain(InetDomainManager.getInstance().get(
StringConverter.parseLong(theForm.get("domain"))));
mailbox.setOwner(UserManager.getInstance().get(
StringConverter.parseLong(theForm.get("owner"))));
mailbox.setVirusCheck((Boolean)theForm.get("viruscheck"));
mailbox.setSpamCheck((Boolean)theForm.get("spamcheck"));
 
Long systemUserId = StringConverter.parseLong(theForm.get("systemuser"));
if(systemUserId == null) {
mailbox.setSystemUser(null);
}
else {
mailbox.setSystemUser(SystemUserManager.getInstance().get(systemUserId));
}
 
if(password != null && !password.equals(""))
mailbox.setNewPassword(password);
 
MailboxManager.getInstance().save(mailbox);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
else {
throw new Exception("unknown mapping parameter");
}
}
 
private void initLists(HttpServletRequest request)
throws Exception
{
List users = new ArrayList(UserManager.getInstance().listUsers());
Collections.sort(users, UserManager.LOGIN_COMPARATOR);
request.setAttribute("users", users);
 
List systemUsers = new ArrayList(SystemUserManager.getInstance().listSystemUsers());
Collections.sort(systemUsers, SystemUserManager.UID_COMPARATOR);
request.setAttribute("systemusers", systemUsers);
 
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains());
Collections.sort(domains, InetDomainManager.NAME_COMPARATOR);
request.setAttribute("domains", domains);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/MailAliasAction.java
0,0 → 1,238
package ak.webcontrol.core.action;
 
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.ArrayList;
 
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.webcontrol.util.StringConverter;
import ak.webcontrol.core.model.User;
import ak.webcontrol.core.model.UserManager;
import ak.webcontrol.core.model.Mailbox;
import ak.webcontrol.core.model.MailboxManager;
import ak.webcontrol.core.model.MailAlias;
import ak.webcontrol.core.model.MailAliasManager;
import ak.webcontrol.core.model.MailAliasDestination;
import ak.webcontrol.core.model.MailAliasDestinationManager;
import ak.webcontrol.core.model.InetDomainManager;
import ak.webcontrol.core.form.MailAliasDestBean;
 
public final class MailAliasAction
extends Action
implements ErrorHandlerX
{
public void handleErrors(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
if("submit".equals(mapping.getParameter())) {
User user = (User)request.getSession().getAttribute("user");
initLists(request, user);
}
}
 
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
User user = (User)request.getSession().getAttribute("user");
if("list".equals(mapping.getParameter())) {
List list = new ArrayList(MailAliasManager.getInstance().listMailAliases());
Collections.sort(list, MailAliasManager.ADDRESS_COMPARATOR);
request.setAttribute("aliases", list);
 
return mapping.findForward("default");
}
else if("edit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long aliasId = StringConverter.parseLong(theForm.get("id"));
 
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ak.webcontrol.core.form.MailAliasEditForm");
 
if(aliasId == null) {
 
}
else {
MailAlias alias = MailAliasManager.getInstance().get(aliasId);
List 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()));
}
 
initLists(request, user);
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(aliasId);
 
MailAliasManager.getInstance().delete(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) ? null
: MailAliasManager.getInstance().get(aliasId);
MailAliasDestBean[] dests = (MailAliasDestBean[])theForm.get("dests");
 
// submit
if(request.getParameter("submit") != null) {
if(alias == null)
alias = MailAliasManager.getInstance().create();
 
alias.getDestinations().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();
else
dest = MailAliasDestinationManager.getInstance().get(destId);
 
// set mailbox or email
if(mailboxId != null) {
dest.setMailbox(MailboxManager.getInstance().get(mailboxId));
dest.setEmail(null);
}
else if(dests[i].getEmail() != null && !dests[i].getEmail().equals("")) {
dest.setMailbox(null);
dest.setEmail(dests[i].getEmail());
}
 
// connect
dest.setAlias(alias);
alias.getDestinations().add(dest);
}
 
alias.setAddress((String)theForm.get("address"));
alias.setDomain(InetDomainManager.getInstance().get(
StringConverter.parseLong(theForm.get("domain"))));
alias.setOwner(UserManager.getInstance().get(
StringConverter.parseLong(theForm.get("owner"))));
 
// update alias
MailAliasManager.getInstance().save(alias);
 
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
 
// add
else if(request.getParameter("add") != null) {
MailAliasDestBean[] newDests = new MailAliasDestBean[dests.length+1];
System.arraycopy(dests, 0, newDests, 0, dests.length);
newDests[dests.length] = new MailAliasDestBean();
theForm.set("dests", newDests);
 
initLists(request, user);
return mapping.findForward("back");
}
 
// 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;
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);
}
theForm.set("dests", newDests);
 
break;
}
catch(NumberFormatException ex) {
}
}
}
}
 
initLists(request, user);
return mapping.findForward("back");
}
}
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());
Collections.sort(users, UserManager.LOGIN_COMPARATOR);
request.setAttribute("users", users);
 
List domains = new ArrayList(InetDomainManager.getInstance().listInetDomains());
Collections.sort(domains, InetDomainManager.NAME_COMPARATOR);
request.setAttribute("domains", domains);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/UserExceptionHandler.java
0,0 → 1,62
package ak.webcontrol.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.webcontrol.util.UserException;
import ak.webcontrol.util.FormException;
 
public final class UserExceptionHandler
extends ExceptionHandler
{
private static final Logger logger = Logger.getLogger(UserExceptionHandler.class);
 
public ActionForward execute(Exception ex, ExceptionConfig config,
ActionMapping mapping, ActionForm formInstance,
HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
if(!(ex instanceof UserException))
throw new ServletException("Unknown type of exception: " + ex.getClass());
 
UserException userEx = (UserException)ex;
logger.info("begin exception handle:" + userEx.getMessage());
 
// try to get property for this exception if any
String property = ActionMessages.GLOBAL_MESSAGE;
if(userEx instanceof FormException) {
FormException formEx = (FormException)userEx;
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(userEx.getMessage(), userEx.getValues()));
 
// find forward
if(mapping.getInput() == null)
return mapping.findForward("error");
else
return mapping.getInputForward();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/UserAction.java
0,0 → 1,104
package ak.webcontrol.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 org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
 
import ak.strutsx.RequestUtilsX;
import ak.backpath.BackPath;
 
import ak.webcontrol.util.StringConverter;
import ak.webcontrol.util.UserException;
import ak.webcontrol.core.CoreResources;
import ak.webcontrol.core.model.User;
import ak.webcontrol.core.model.UserManager;
 
public final class UserAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
User user = (User)request.getSession().getAttribute("user");
 
if("list".equals(mapping.getParameter())) {
List list = new ArrayList(UserManager.getInstance().listUsers());
Collections.sort(list, UserManager.LOGIN_COMPARATOR);
request.setAttribute("users", list);
 
return mapping.findForward("default");
}
else if("edit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long userId = StringConverter.parseLong(theForm.get("id"));
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ak.webcontrol.core.form.UserEditForm");
 
if(userId == null) {
 
}
else {
User u = UserManager.getInstance().get(userId);
showForm.set("login", u.getLogin());
}
 
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);
 
if(u.equals(user))
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(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(""))
throw new UserException(CoreResources.PASSWORD_REQUIRED);
 
u = UserManager.getInstance().create();
}
else {
u = UserManager.getInstance().get(userId);
}
 
u.setLogin((String)theForm.get("login"));
 
if(password != null && !password.equals(""))
u.setNewPassword(password);
 
UserManager.getInstance().save(u);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
else {
throw new Exception("unknown mapping parameter");
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/SystemUserAction.java
0,0 → 1,92
package ak.webcontrol.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 org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
 
import ak.strutsx.RequestUtilsX;
import ak.backpath.BackPath;
 
import ak.webcontrol.util.StringConverter;
import ak.webcontrol.core.model.User;
import ak.webcontrol.core.model.SystemUser;
import ak.webcontrol.core.model.SystemUserManager;
 
public final class SystemUserAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
User user = (User)request.getSession().getAttribute("user");
 
if("list".equals(mapping.getParameter())) {
List list = new ArrayList(SystemUserManager.getInstance().listSystemUsers());
Collections.sort(list, SystemUserManager.NAME_COMPARATOR);
request.setAttribute("users", list);
 
return mapping.findForward("default");
}
else if("edit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long userId = StringConverter.parseLong(theForm.get("id"));
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ak.webcontrol.core.form.SystemUserEditForm");
 
if(userId == null) {
 
}
else {
SystemUser u = SystemUserManager.getInstance().get(userId);
showForm.set("uid", StringConverter.toString(u.getUid()));
showForm.set("name", u.getName());
}
 
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(userId);
 
SystemUserManager.getInstance().delete(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();
}
else {
u = SystemUserManager.getInstance().get(userId);
}
 
u.setUid(StringConverter.parseInteger(theForm.get("uid")));
u.setName((String)theForm.get("name"));
 
SystemUserManager.getInstance().save(u);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
else {
throw new Exception("unknown mapping parameter");
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/CoreResources.properties
0,0 → 1,164
ak.webcontrol.core.type.user=user
ak.webcontrol.core.type.systemUser=system user
ak.webcontrol.core.type.domain=domain
ak.webcontrol.core.type.mailbox=mailbox
ak.webcontrol.core.type.mailAlias=mail alias
ak.webcontrol.core.type.mailAliasDestination=mail alias destination
 
ak.webcontrol.core.login.failed=Wrong login or password
ak.webcontrol.core.login.required=You have to enter the login
ak.webcontrol.core.password.required=You have to enter the password
ak.webcontrol.core.oldpassword.required=You have to enter the old password
ak.webcontrol.core.oldpassword.wrong=Wrong old password
ak.webcontrol.core.password.dontMatch=The passwords you entered doesn't match
 
ak.webcontrol.core.user.password.change.id.wrong=Please select an user from the list
ak.webcontrol.core.user.deletemeself=Can not delete the user you are logged in
 
ak.webcontrol.core.mailbox.edit.id.wrong=Please select a mailbox from the list
ak.webcontrol.core.mailbox.edit.login.empty=You have to enter the login
ak.webcontrol.core.mailbox.edit.domain.wrong=Please select a domain from the list
ak.webcontrol.core.mailbox.edit.owner.wrong=Please select an owner from the list
ak.webcontrol.core.mailbox.edit.systemuser.wrong=Please select a system user from the list
 
ak.webcontrol.core.mail.alias.edit.id.wrong=Please select a mail alias from the list
ak.webcontrol.core.mail.alias.edit.dest.id.wrong=Wrong ID
ak.webcontrol.core.mail.alias.edit.mailbox.id.wrong=Please select a mailbox from the list
ak.webcontrol.core.mail.alias.edit.email.wrong=Please enter an email
ak.webcontrol.core.mail.alias.edit.address.empty=Please enter an address
ak.webcontrol.core.mail.alias.edit.domain.wrong=Please select a domain from the list
ak.webcontrol.core.mail.alias.edit.owner.wrong=Please select an owner from the list
 
ak.webcontrol.core.user.system.edit.id.wrong=Please select an user from the list
ak.webcontrol.core.user.system.edit.uid.wrong=Please enter the UID
ak.webcontrol.core.user.system.edit.name.required=Please enter name of the user
 
ak.webcontrol.core.domain.edit.id.wrong=Please select a domain from the list
ak.webcontrol.core.domain.edit.owner.wrong=Please select an owner from the list
ak.webcontrol.core.domain.edit.name.empty=Please enter domain name
 
ak.webcontrol.core.mail.alias.edit.id.wrong=Please select an alias from the list
 
ak.webcontrol.page.error.title=webcontrol - error
ak.webcontrol.page.error.back=back
 
ak.webcontrol.page.generalError.title=webcontrol - error
ak.webcontrol.page.generalError.message=There is internal server error occured. Please go back and try again. If the error occurs again continue with the start page.
ak.webcontrol.page.generalError.index=start page
ak.webcontrol.page.generalError.back=back
 
ak.webcontrol.page.index.title=webcontrol
ak.webcontrol.page.index.password_change=change password
ak.webcontrol.page.index.user_list=users
ak.webcontrol.page.index.system_user_list=system users
ak.webcontrol.page.index.domain_list=domains
ak.webcontrol.page.index.mail_alias_list=mail aliases
ak.webcontrol.page.index.mail_box_list=mail boxes
ak.webcontrol.page.index.logout=logout
ak.webcontrol.page.index.login=Logged in as
 
ak.webcontrol.page.system.login.title=webcontrol - login
ak.webcontrol.page.system.login.login=Login
ak.webcontrol.page.system.login.password=Password
ak.webcontrol.page.system.login.submit=Login
ak.webcontrol.page.system.login.reset=Reset
 
ak.webcontrol.page.system.logout.title=webcontrol - logout
ak.webcontrol.page.system.logout.message=You are logged out sucessfully. See you later!
ak.webcontrol.page.system.logout.login=start new session
ak.webcontrol.page.system.logout.back=return to system
 
ak.webcontrol.page.user.password.change.title=webcontrol - change password
ak.webcontrol.page.user.password.change.old_password=Old password
ak.webcontrol.page.user.password.change.new_password=New password
ak.webcontrol.page.user.password.change.new_password_again=New password again
ak.webcontrol.page.user.password.change.submit=Change
ak.webcontrol.page.user.password.change.cancel=Cancel
 
ak.webcontrol.page.user.list.title=webcontrol - users - list
ak.webcontrol.page.user.list.login=Login
ak.webcontrol.page.user.list.delete=delete
ak.webcontrol.page.user.list.edit=edit
ak.webcontrol.page.user.list.add=add new user
ak.webcontrol.page.user.list.back=back
 
ak.webcontrol.page.user.edit.title=webcontrol - user - edit
ak.webcontrol.page.user.edit.login=Login
ak.webcontrol.page.user.edit.password=Password
ak.webcontrol.page.user.edit.password_again=Password again
ak.webcontrol.page.user.edit.submit=submit
ak.webcontrol.page.user.edit.back=back
 
ak.webcontrol.page.user.system.list.title=webcontrol - system users - list
ak.webcontrol.page.user.system.list.uid=System ID
ak.webcontrol.page.user.system.list.name=User name
ak.webcontrol.page.user.system.list.delete=delete
ak.webcontrol.page.user.system.list.edit=edit
ak.webcontrol.page.user.system.list.add=add new user
ak.webcontrol.page.user.system.list.back=back
 
ak.webcontrol.page.user.system.edit.title=webcontrol - system user - edit
ak.webcontrol.page.user.system.edit.uid=System ID
ak.webcontrol.page.user.system.edit.name=User name
ak.webcontrol.page.user.system.edit.submit=submit
ak.webcontrol.page.user.system.edit.back=back
 
ak.webcontrol.page.domain.list.title=webcontrol - domains - list
ak.webcontrol.page.domain.list.name=Name
ak.webcontrol.page.domain.list.owner=Owner
ak.webcontrol.page.domain.list.delete=delete
ak.webcontrol.page.domain.list.edit=edit
ak.webcontrol.page.domain.list.add=add new domain
ak.webcontrol.page.domain.list.back=back
 
ak.webcontrol.page.domain.edit.title=webcontrol - domain - edit
ak.webcontrol.page.domain.edit.name=Name
ak.webcontrol.page.domain.edit.owner=Owner
ak.webcontrol.page.domain.edit.owner.empty=-- please select --
ak.webcontrol.page.domain.edit.submit=submit
ak.webcontrol.page.domain.edit.back=back
 
ak.webcontrol.page.mail.alias.list.title=webcontrol - mail aliases - list
ak.webcontrol.page.mail.alias.list.alias=Alias
ak.webcontrol.page.mail.alias.list.edit=edit
ak.webcontrol.page.mail.alias.list.delete=delete
ak.webcontrol.page.mail.alias.list.back=back
ak.webcontrol.page.mail.alias.list.add=add new mail alias
 
ak.webcontrol.page.mail.alias.edit.title=webcontrol - mail alias - edit
ak.webcontrol.page.mail.alias.edit.address=Address
ak.webcontrol.page.mail.alias.edit.domain=Domain
ak.webcontrol.page.mail.alias.edit.domain.empty=-- please select --
ak.webcontrol.page.mail.alias.edit.owner=Owner
ak.webcontrol.page.mail.alias.edit.owner.empty=-- please select --
ak.webcontrol.page.mail.alias.edit.header.tomailbox=To mailbox
ak.webcontrol.page.mail.alias.edit.header.toexternal=or to external email
ak.webcontrol.page.mail.alias.edit.external=external redirect
ak.webcontrol.page.mail.alias.edit.add=add new destination
ak.webcontrol.page.mail.alias.edit.delete=delete
ak.webcontrol.page.mail.alias.edit.submit=submit
ak.webcontrol.page.mail.alias.edit.cancel=cancel
 
ak.webcontrol.page.mail.box.list.title=webcontrol - mail boxes - list
ak.webcontrol.page.mail.box.list.login=Box
ak.webcontrol.page.mail.box.list.domain=Domain
ak.webcontrol.page.mail.box.list.owner=Owner
ak.webcontrol.page.mail.box.list.edit=edit
ak.webcontrol.page.mail.box.list.delete=delete
ak.webcontrol.page.mail.box.list.add=add new mail box
ak.webcontrol.page.mail.box.list.back=back
 
ak.webcontrol.page.mail.box.edit.title=webcontrol - mail box - edit
ak.webcontrol.page.mail.box.edit.login=Box
ak.webcontrol.page.mail.box.edit.password=Password
ak.webcontrol.page.mail.box.edit.password_again=Password again
ak.webcontrol.page.mail.box.edit.domain=Domain
ak.webcontrol.page.mail.box.edit.domain.empty=-- please select --
ak.webcontrol.page.mail.box.edit.owner=Owner
ak.webcontrol.page.mail.box.edit.owner.empty=-- please select --
ak.webcontrol.page.mail.box.edit.systemuser=System user
ak.webcontrol.page.mail.box.edit.systemuser.empty=-- please select --
ak.webcontrol.page.mail.box.edit.viruscheck=check mails for viruses
ak.webcontrol.page.mail.box.edit.spamcheck=check mails for spam
ak.webcontrol.page.mail.box.edit.submit=submit
ak.webcontrol.page.mail.box.edit.back=back
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/Mailbox.java
0,0 → 1,170
package ak.webcontrol.core.model;
 
import java.util.Date;
import ak.webcontrol.util.Digest;
 
/**
*
* @hibernate.class table="mailboxes"
*/
public class Mailbox
implements ModelObject
{
private Long id;
private String login;
private String password;
private InetDomain domain;
private User owner;
private Boolean virusCheck;
private Boolean spamCheck;
private SystemUser systemUser;
private Date modStamp;
 
protected Mailbox()
{
}
 
/**
*
* @hibernate.id generator-class="native"
*/
public Long getId()
{
return id;
}
 
public void setId(Long id)
{
this.id = id;
}
 
/**
*
* @hibernate.property
*/
public String getLogin()
{
return login;
}
 
public void setLogin(String login)
{
this.login = login;
}
 
/**
*
* @hibernate.property
*/
public String getPassword()
{
return password;
}
 
public void setPassword(String password)
{
this.password = password;
}
 
public void setNewPassword(String password)
{
if(password == null)
throw new NullPointerException("Null password");
 
this.password = Digest.encode(password);
}
 
/**
*
* @hibernate.many-to-one
*/
public InetDomain getDomain()
{
return domain;
}
 
public void setDomain(InetDomain domain)
{
this.domain = domain;
}
 
/**
*
* @hibernate.many-to-one
*/
public User getOwner()
{
return owner;
}
 
public void setOwner(User owner)
{
this.owner = owner;
}
 
/**
*
* @hibernate.property
*/
public Boolean getVirusCheck()
{
return virusCheck;
}
 
public void setVirusCheck(Boolean virusCheck)
{
this.virusCheck = virusCheck;
}
 
/**
*
* @hibernate.property
*/
public Boolean getSpamCheck()
{
return spamCheck;
}
 
public void setSpamCheck(Boolean spamCheck)
{
this.spamCheck = spamCheck;
}
 
/**
*
* @hibernate.many-to-one
*/
public SystemUser getSystemUser()
{
return systemUser;
}
 
public void setSystemUser(SystemUser systemUser)
{
this.systemUser = systemUser;
}
 
/**
*
* @hibernate.timestamp column="mod_stamp"
*/
public Date getModStamp()
{
return modStamp;
}
 
public void setModStamp(Date modStamp)
{
this.modStamp = modStamp;
}
 
public String getTypeKey()
{
return ak.webcontrol.core.CoreResources.TYPE_MAILBOX;
}
 
public String getIdentificationString()
{
return getLogin() + "@" + getDomain().getName();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAlias.java
0,0 → 1,123
package ak.webcontrol.core.model;
 
import java.util.Collection;
import java.util.Date;
 
/**
*
* @hibernate.class table="mailaliases"
*/
public class MailAlias
implements ModelObject
{
private Long id;
private String address;
private InetDomain domain;
private User owner;
private Collection destinations; // Collection(MailAliasDestintion)
private Date modStamp;
 
protected MailAlias()
{
}
 
/**
*
* @hibernate.id generator-class="native"
*/
public Long getId()
{
return id;
}
 
public void setId(Long id)
{
this.id = id;
}
 
/**
*
* @hibernate.property
*/
public String getAddress()
{
return address;
}
 
public void setAddress(String address)
{
this.address = address;
}
 
/**
*
* @hibernate.many-to-one
*/
public InetDomain getDomain()
{
return domain;
}
 
public void setDomain(InetDomain domain)
{
this.domain = domain;
}
 
/**
*
* @hibernate.many-to-one
*/
public User getOwner()
{
return owner;
}
 
public void setOwner(User owner)
{
this.owner = owner;
}
 
/**
* @return Collection(MailAliasDestination)
*
* @hibernate.bag inverse="true" cascade="all-delete-orphan"
* @hibernate.collection-key column="alias"
* @hibernate.collection-one-to-many class="ak.webcontrol.core.model.MailAliasDestination"
*/
public Collection getDestinations()
{
return destinations;
}
 
/**
* @param destinations Collection(MailAliasDestination)
*/
protected void setDestinations(Collection destinations)
{
this.destinations = destinations;
}
 
/**
*
* @hibernate.timestamp column="mod_stamp"
*/
public Date getModStamp()
{
return modStamp;
}
 
public void setModStamp(Date modStamp)
{
this.modStamp = modStamp;
}
 
public String getTypeKey()
{
return ak.webcontrol.core.CoreResources.TYPE_MAIL_ALIAS;
}
 
public String getIdentificationString()
{
return getAddress() + "@" + getDomain().getName();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasDestination.java
0,0 → 1,101
package ak.webcontrol.core.model;
 
import java.util.Date;
 
/**
*
* @hibernate.class table="mailaliasdests"
*/
public class MailAliasDestination
implements ModelObject
{
private Long id;
private MailAlias alias;
private Mailbox mailbox;
private String email;
private Date modStamp;
 
protected MailAliasDestination()
{
}
 
/**
*
* @hibernate.id generator-class="native"
*/
public Long getId()
{
return id;
}
 
public void setId(Long id)
{
this.id = id;
}
 
/**
*
* @hibernate.many-to-one
*/
public MailAlias getAlias()
{
return alias;
}
 
public void setAlias(MailAlias alias)
{
this.alias = alias;
}
 
/**
*
* @hibernate.many-to-one
*/
public Mailbox getMailbox()
{
return mailbox;
}
 
public void setMailbox(Mailbox mailbox)
{
this.mailbox = mailbox;
}
 
/**
*
* @hibernate.property
*/
public String getEmail()
{
return email;
}
 
public void setEmail(String email)
{
this.email = email;
}
 
/**
*
* @hibernate.timestamp column="mod_stamp"
*/
public Date getModStamp()
{
return modStamp;
}
 
public void setModStamp(Date modStamp)
{
this.modStamp = modStamp;
}
 
public String getTypeKey()
{
return ak.webcontrol.core.CoreResources.TYPE_MAIL_ALIAS_DESTINATION;
}
 
public String getIdentificationString()
{
return (getMailbox() == null) ? getEmail() : getMailbox().getIdentificationString();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/SystemUserManager.java
0,0 → 1,191
package ak.webcontrol.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.webcontrol.util.HibernateUtil;
import ak.webcontrol.util.ModelException;
 
public class SystemUserManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(SystemUserManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/webcontrol/core/model/SystemUser.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private SystemUserManager()
{
}
 
public SystemUser create()
{
return new SystemUser();
}
 
public SystemUser get(Long id)
throws ModelException
{
try {
return (SystemUser)HibernateUtil.currentSession().load(SystemUser.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public SystemUser findForName(String name)
throws ModelException
{
try {
List list = HibernateUtil.currentSession().find(
"from SystemUser where name=?", name, Hibernate.STRING);
 
if(list.size() == 0)
return null;
else
return (SystemUser)list.get(0);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public SystemUser findForUid(Integer uid)
throws ModelException
{
try {
List list = HibernateUtil.currentSession().find(
"from SystemUser where uid=?", uid, Hibernate.INTEGER);
 
if(list.size() == 0)
return null;
else
return (SystemUser)list.get(0);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void save(SystemUser systemUser)
throws ModelException
{
try {
HibernateUtil.currentSession().saveOrUpdate(systemUser);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(SystemUser systemUser)
throws ModelException
{
try {
HibernateUtil.currentSession().delete(systemUser);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listSystemUsers()
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from SystemUser");
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static SystemUserManager systemUserManager = null;
 
public static SystemUserManager getInstance()
{
if(systemUserManager == null)
systemUserManager = new SystemUserManager();
 
return systemUserManager;
}
 
public static final Comparator UID_COMPARATOR = new UidComparator();
public static final Comparator NAME_COMPARATOR = new NameComparator();
 
private static class UidComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof SystemUser) || !(o2 instanceof SystemUser))
throw new ClassCastException("not a SystemUser");
 
SystemUser a1 = (SystemUser)o1;
SystemUser a2 = (SystemUser)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getUid().compareTo(a2.getUid());
}
 
public boolean equals(Object obj)
{
return (obj instanceof UidComparator);
}
}
 
private static class NameComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof SystemUser) || !(o2 instanceof SystemUser))
throw new ClassCastException("not a SystemUser");
 
SystemUser a1 = (SystemUser)o1;
SystemUser a2 = (SystemUser)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getName().compareToIgnoreCase(a2.getName());
}
 
public boolean equals(Object obj)
{
return (obj instanceof NameComparator);
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/User.java
0,0 → 1,124
package ak.webcontrol.core.model;
 
import java.util.Date;
import ak.webcontrol.util.Digest;
 
/**
*
* @hibernate.class table="users"
*/
public class User
implements ModelObject
{
private Long id;
private String login;
private String password;
private Date modStamp;
 
protected User()
{
}
 
/**
*
* @hibernate.id generator-class="native"
*/
public Long getId()
{
return id;
}
 
public void setId(Long id)
{
this.id = id;
}
 
/**
*
* @hibernate.property
*/
public String getLogin()
{
return login;
}
 
public void setLogin(String login)
{
this.login = login;
}
 
/**
*
* @hibernate.property
*/
protected String getPassword()
{
return password;
}
 
protected void setPassword(String password)
{
this.password = password;
}
 
public void setNewPassword(String password)
{
if(password == null)
throw new NullPointerException("Null password");
 
this.password = Digest.encode(password);
}
 
public boolean checkPassword(String password)
{
if(password == null)
throw new NullPointerException("Null password");
 
return checkMd5Password(Digest.encode(password));
}
 
public boolean checkMd5Password(String password)
{
return this.password.equals(password);
}
 
/**
*
* @hibernate.timestamp column="mod_stamp"
*/
public Date getModStamp()
{
return modStamp;
}
 
public void setModStamp(Date modStamp)
{
this.modStamp = modStamp;
}
 
public boolean equals(Object o)
{
if(!(o instanceof User)) return false;
 
User u = (User)o;
return (id != null) && (u.getId() != null) && (id.equals(u.getId()));
}
 
public int hashCode()
{
if(id == null)
return 0;
else
return id.hashCode();
}
 
public String getTypeKey()
{
return ak.webcontrol.core.CoreResources.TYPE_USER;
}
 
public String getIdentificationString()
{
return getLogin();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/test/Test.java
0,0 → 1,164
package ak.webcontrol.core.model.test;
 
import net.sf.hibernate.*;
import ak.webcontrol.core.model.*;
import ak.webcontrol.util.*;
 
public class Test
{
public static void test()
throws Exception
{
// delete objects if they are already in the database
HibernateUtil.currentSession().delete(
"from MailAlias where address like ?", "%@test.domain", Hibernate.STRING);
HibernateUtil.currentSession().delete(
"from SystemUser where uid=?", new Integer(1001), Hibernate.INTEGER);
HibernateUtil.currentSession().delete(
"from Mailbox where login=?", "testuser@test.domain", Hibernate.STRING);
HibernateUtil.currentSession().delete(
"from InetDomain where name=?", "test.domain", Hibernate.STRING);
HibernateUtil.currentSession().delete(
"from User where login=?", "testuser", Hibernate.STRING);
HibernateUtil.currentSession().flush();
 
User user;
InetDomain inetDomain;
Mailbox mailbox;
MailAlias mailAlias;
SystemUser systemUser;
 
// create objects
user = UserManager.getInstance().create();
user.setLogin("testuser");
user.setNewPassword("none");
UserManager.getInstance().save(user);
 
inetDomain = InetDomainManager.getInstance().create();
inetDomain.setName("test.domain");
inetDomain.setOwner(UserManager.getInstance().findForLogin("testuser"));
InetDomainManager.getInstance().save(inetDomain);
 
systemUser = SystemUserManager.getInstance().create();
systemUser.setUid(new Integer(1001));
systemUser.setName("test");
SystemUserManager.getInstance().save(systemUser);
 
mailbox = MailboxManager.getInstance().create();
mailbox.setLogin("testuser@test.domain");
mailbox.setDomain(InetDomainManager.getInstance().findForName("test.domain"));
mailbox.setOwner(UserManager.getInstance().findForLogin("testuser"));
mailbox.setVirusCheck(new Boolean(true));
mailbox.setSpamCheck(new Boolean(false));
mailbox.setSystemUser(systemUser);
MailboxManager.getInstance().save(mailbox);
 
mailAlias = MailAliasManager.getInstance().create();
mailAlias.setAddress("some.name@test.domain");
mailAlias.setDomain(InetDomainManager.getInstance().findForName("test.domain"));
mailAlias.setOwner(UserManager.getInstance().findForLogin("testuser"));
MailAliasManager.getInstance().save(mailAlias);
 
HibernateUtil.currentSession().flush();
}
 
public static void testUser()
throws Exception
{
User user = UserManager.getInstance().findForLogin("testuser");
 
if(user == null) {
System.out.println("create new user");
user = UserManager.getInstance().create();
}
else {
System.out.println("get existing user");
}
 
user.setLogin("testuser");
 
//
// benchmark hibernate update
//
int benchmarkCount = 100;
 
// first measure object change time
long startTime = System.currentTimeMillis();
for(int i = 0; i < benchmarkCount; i++) {
user.setNewPassword((i % 2 == 0) ? "a" : "b");
}
 
// then object change & DB update
long betweenTime = System.currentTimeMillis();
for(int i = 0; i < benchmarkCount; i++) {
user.setNewPassword((i % 2 == 0) ? "a" : "b");
UserManager.getInstance().save(user);
HibernateUtil.currentSession().flush();
}
 
// results
long endTime = System.currentTimeMillis();
System.out.println("Object change: " + (betweenTime-startTime) + " ms");
System.out.println("DB update: " + (endTime-betweenTime) + " ms");
 
user.setNewPassword("none");
UserManager.getInstance().save(user);
}
 
public static void testInetDomain()
throws Exception
{
InetDomain inetDomain = InetDomainManager.getInstance().findForName("test.domain");
 
if(inetDomain == null) {
System.out.println("create new domain");
inetDomain = InetDomainManager.getInstance().create();
}
else {
System.out.println("get existing domain");
}
 
inetDomain.setName("test.domain");
inetDomain.setOwner(UserManager.getInstance().findForLogin("testuser"));
 
InetDomainManager.getInstance().save(inetDomain);
}
 
public static void main(String[] args)
throws Exception
{
UserManager.getInstance();
InetDomainManager.getInstance();
SystemUserManager.getInstance();
MailboxManager.getInstance();
MailAliasManager.getInstance();
 
try {
HibernateUtil.beginTransaction();
//testUser();
//testInetDomain();
test();
HibernateUtil.commitTransaction();
}
catch(Exception ex) {
ex.printStackTrace();
HibernateUtil.rollbackTransaction();
throw ex;
}
finally {
HibernateUtil.closeSession();
}
}
 
private static String randomString(int len)
throws java.io.UnsupportedEncodingException
{
byte[] buf = new byte[len];
 
for(int i = 0; i < len; i++) {
buf[i] = (byte)(Math.random() * 26 + 97);
}
 
return new String(buf, "ascii");
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/InetDomainManager.java
0,0 → 1,145
package ak.webcontrol.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.webcontrol.util.HibernateUtil;
import ak.webcontrol.util.ModelException;
 
public class InetDomainManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(InetDomainManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/webcontrol/core/model/InetDomain.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private InetDomainManager()
{
}
 
public InetDomain create()
{
return new InetDomain();
}
 
public InetDomain get(Long id)
throws ModelException
{
try {
return (InetDomain)HibernateUtil.currentSession().load(InetDomain.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public InetDomain findForName(String name)
throws ModelException
{
try {
List list = HibernateUtil.currentSession().find(
"from InetDomain where name=?", name, Hibernate.STRING);
 
if(list.size() == 0)
return null;
else
return (InetDomain)list.get(0);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void save(InetDomain inetDomain)
throws ModelException
{
try {
HibernateUtil.currentSession().saveOrUpdate(inetDomain);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(InetDomain inetDomain)
throws ModelException
{
try {
HibernateUtil.currentSession().delete(inetDomain);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listInetDomains()
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from InetDomain");
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static InetDomainManager inetDomainManager = null;
 
public static InetDomainManager getInstance()
{
if(inetDomainManager == null)
inetDomainManager = new InetDomainManager();
 
return inetDomainManager;
}
 
public static final Comparator NAME_COMPARATOR = new NameComparator();
 
private static class NameComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof InetDomain) || !(o2 instanceof InetDomain))
throw new ClassCastException("not a InetDomain");
 
InetDomain a1 = (InetDomain)o1;
InetDomain a2 = (InetDomain)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getName().compareToIgnoreCase(a2.getName());
}
 
public boolean equals(Object obj)
{
return (obj instanceof NameComparator);
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/SystemUser.java
0,0 → 1,88
package ak.webcontrol.core.model;
 
import java.util.Date;
 
/**
*
* @hibernate.class table="systemusers"
*/
public class SystemUser
implements ModelObject
{
private Long id;
 
/** user id in the OS */
private Integer uid;
private String name;
private Date modStamp;
 
protected SystemUser()
{
}
 
/**
*
* @hibernate.id generator-class="native"
*/
public Long getId()
{
return id;
}
 
public void setId(Long id)
{
this.id = id;
}
 
/**
*
* @hibernate.property
*/
public Integer getUid()
{
return uid;
}
 
public void setUid(Integer uid)
{
this.uid = uid;
}
 
/**
*
* @hibernate.property
*/
public String getName()
{
return name;
}
 
public void setName(String name)
{
this.name = name;
}
 
/**
*
* @hibernate.timestamp column="mod_stamp"
*/
public Date getModStamp()
{
return modStamp;
}
 
public void setModStamp(Date modStamp)
{
this.modStamp = modStamp;
}
 
public String getTypeKey()
{
return ak.webcontrol.core.CoreResources.TYPE_SYSTEM_USER;
}
 
public String getIdentificationString()
{
return getName() + " (" + getUid() + ")"; // FIXME: is it really so good style?
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailboxManager.java
0,0 → 1,158
package ak.webcontrol.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.webcontrol.util.HibernateUtil;
import ak.webcontrol.util.ModelException;
 
public class MailboxManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailboxManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/webcontrol/core/model/Mailbox.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailboxManager()
{
}
 
public Mailbox create()
{
return new Mailbox();
}
 
public Mailbox get(Long id)
throws ModelException
{
try {
return (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Mailbox findForLogin(String login)
throws ModelException
{
try {
List list = HibernateUtil.currentSession().find(
"from Mailbox where login=?", login, Hibernate.STRING);
 
if(list.size() == 0)
return null;
else
return (Mailbox)list.get(0);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void save(Mailbox mailbox)
throws ModelException
{
try {
HibernateUtil.currentSession().saveOrUpdate(mailbox);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(Mailbox mailbox)
throws ModelException
{
try {
HibernateUtil.currentSession().delete(mailbox);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailboxes()
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from Mailbox");
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailboxes(User owner)
throws ModelException
{
try {
return HibernateUtil.currentSession().find(
"from Mailbox where owner=?", owner, Hibernate.entity(User.class));
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static MailboxManager mailboxManager = null;
 
public static MailboxManager getInstance()
{
if(mailboxManager == null)
mailboxManager = new MailboxManager();
 
return mailboxManager;
}
 
public static final Comparator LOGIN_COMPARATOR = new LoginComparator();
 
private static class LoginComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof Mailbox) || !(o2 instanceof Mailbox))
throw new ClassCastException("not a Mailbox");
 
Mailbox a1 = (Mailbox)o1;
Mailbox a2 = (Mailbox)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getLogin().compareToIgnoreCase(a2.getLogin());
}
 
public boolean equals(Object obj)
{
return (obj instanceof LoginComparator);
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/InetDomain.java
0,0 → 1,86
package ak.webcontrol.core.model;
 
import java.util.Date;
 
/**
*
* @hibernate.class table="domains"
*/
public class InetDomain
implements ModelObject
{
private Long id;
private String name;
private User owner;
private Date modStamp;
 
protected InetDomain()
{
}
 
/**
*
* @hibernate.id generator-class="native"
*/
public Long getId()
{
return id;
}
 
public void setId(Long id)
{
this.id = id;
}
 
/**
*
* @hibernate.property
*/
public String getName()
{
return name;
}
 
public void setName(String name)
{
this.name = name;
}
 
/**
*
* @hibernate.many-to-one
*/
public User getOwner()
{
return owner;
}
 
public void setOwner(User owner)
{
this.owner = owner;
}
 
/**
*
* @hibernate.timestamp column="mod_stamp"
*/
public Date getModStamp()
{
return modStamp;
}
 
public void setModStamp(Date modStamp)
{
this.modStamp = modStamp;
}
 
public String getTypeKey()
{
return ak.webcontrol.core.CoreResources.TYPE_DOMAIN;
}
 
public String getIdentificationString()
{
return getName();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasManager.java
0,0 → 1,160
package ak.webcontrol.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.webcontrol.util.HibernateUtil;
import ak.webcontrol.util.ModelException;
 
public class MailAliasManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailAliasManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/webcontrol/core/model/MailAlias.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailAliasManager()
{
}
 
public MailAlias create()
{
MailAlias alias = new MailAlias();
alias.setDestinations(new ArrayList());
return alias;
}
 
public MailAlias get(Long id)
throws ModelException
{
try {
return (MailAlias)HibernateUtil.currentSession().load(MailAlias.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public MailAlias findForName(String name)
throws ModelException
{
try {
List list = HibernateUtil.currentSession().find(
"from MailAlias where name=?", name, Hibernate.STRING);
 
if(list.size() == 0)
return null;
else
return (MailAlias)list.get(0);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void save(MailAlias mailAlias)
throws ModelException
{
try {
HibernateUtil.currentSession().saveOrUpdate(mailAlias);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(MailAlias mailAlias)
throws ModelException
{
try {
HibernateUtil.currentSession().delete(mailAlias);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailAliases()
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from MailAlias");
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailAliases(User owner)
throws ModelException
{
try {
return HibernateUtil.currentSession().find(
"from MailAlias where owner=?", owner, Hibernate.entity(User.class));
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static MailAliasManager mailAliasManager = null;
 
public static MailAliasManager getInstance()
{
if(mailAliasManager == null)
mailAliasManager = new MailAliasManager();
 
return mailAliasManager;
}
 
public static final Comparator ADDRESS_COMPARATOR = new AddressComparator();
 
private static class AddressComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof MailAlias) || !(o2 instanceof MailAlias))
throw new ClassCastException("not a MailAlias");
 
MailAlias a1 = (MailAlias)o1;
MailAlias a2 = (MailAlias)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getAddress().compareToIgnoreCase(a2.getAddress());
}
 
public boolean equals(Object obj)
{
return (obj instanceof AddressComparator);
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/ModelObject.java
0,0 → 1,8
package ak.webcontrol.core.model;
 
public interface ModelObject
{
public String getTypeKey();
 
public String getIdentificationString();
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasDestinationManager.java
0,0 → 1,135
package ak.webcontrol.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.webcontrol.util.HibernateUtil;
import ak.webcontrol.util.ModelException;
 
public class MailAliasDestinationManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailAliasDestinationManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/webcontrol/core/model/MailAliasDestination.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailAliasDestinationManager()
{
}
 
public MailAliasDestination create()
{
return new MailAliasDestination();
}
 
public MailAliasDestination get(Long id)
throws ModelException
{
try {
return (MailAliasDestination)HibernateUtil.currentSession()
.load(MailAliasDestination.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void save(MailAliasDestination mailAliasDestination)
throws ModelException
{
try {
HibernateUtil.currentSession().saveOrUpdate(mailAliasDestination);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(MailAliasDestination mailAliasDestination)
throws ModelException
{
try {
HibernateUtil.currentSession().delete(mailAliasDestination);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailAliasesDestination()
{
return null;
}
 
public Collection listMailAliasesDestination(MailAlias alias)
throws ModelException
{
try {
return HibernateUtil.currentSession().find(
"from MailAliasDestination where alias=?",
alias, Hibernate.entity(MailAlias.class));
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static MailAliasDestinationManager mailAliasDestinationManager = null;
 
public static MailAliasDestinationManager getInstance()
{
if(mailAliasDestinationManager == null)
mailAliasDestinationManager = new MailAliasDestinationManager();
 
return mailAliasDestinationManager;
}
 
public static final Comparator EMAIL_COMPARATOR = new EmailComparator();
 
private static class EmailComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof MailAliasDestination) || !(o2 instanceof MailAliasDestination))
throw new ClassCastException("not a MailAliasDestination");
 
MailAliasDestination a1 = (MailAliasDestination)o1;
MailAliasDestination a2 = (MailAliasDestination)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getEmail().compareToIgnoreCase(a2.getEmail());
}
 
public boolean equals(Object obj)
{
return (obj instanceof EmailComparator);
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/UserManager.java
0,0 → 1,162
package ak.webcontrol.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.webcontrol.util.HibernateUtil;
import ak.webcontrol.util.ModelException;
 
public class UserManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailboxManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/webcontrol/core/model/User.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private UserManager()
{
}
 
public User create()
{
return new User();
}
 
public User get(Long id)
throws ModelException
{
try {
return (User)HibernateUtil.currentSession().load(User.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public User findForLogin(String login)
throws ModelException
{
try {
List list = HibernateUtil.currentSession().find(
"from User where login=?", login, Hibernate.STRING);
 
if(list.size() == 0)
return null;
else
return (User)list.get(0);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void save(User user)
throws ModelException
{
try {
HibernateUtil.currentSession().saveOrUpdate(user);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User user)
throws ModelException
{
try {
HibernateUtil.currentSession().delete(user);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listUsers()
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from User");
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public User loginUser(String login, String password)
throws ModelException
{
if(login == null || password == null)
return null;
 
User user = findForLogin(login);
 
if(user != null) {
if(user.checkPassword(password))
return user;
}
 
// wrong login or password
return null;
}
 
private static UserManager userManager = null;
 
public static UserManager getInstance()
{
if(userManager == null)
userManager = new UserManager();
 
return userManager;
}
 
public static final Comparator LOGIN_COMPARATOR = new LoginComparator();
 
private static class LoginComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof User) || !(o2 instanceof User))
throw new ClassCastException("not a User");
 
User a1 = (User)o1;
User a2 = (User)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getLogin().compareToIgnoreCase(a2.getLogin());
}
 
public boolean equals(Object obj)
{
return (obj instanceof LoginComparator);
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/CoreResources.java
0,0 → 1,18
package ak.webcontrol.core;
 
public abstract class CoreResources
{
public static final String LOGIN_FAILED = "ak.webcontrol.core.login.failed";
public static final String OLD_PASSWORD_WRONG = "ak.webcontrol.core.oldpassword.wrong";
public static final String DELETE_ME_SELF = "ak.webcontrol.core.user.deletemeself";
public static final String PASSWORD_REQUIRED = "ak.webcontrol.core.password.required";
public static final String PASSWORDS_DONT_MATCH = "ak.webcontrol.core.password.dontMatch";
 
public static final String TYPE_USER = "ak.webcontrol.core.type.user";
public static final String TYPE_SYSTEM_USER = "ak.webcontrol.core.type.systemUser";
public static final String TYPE_DOMAIN = "ak.webcontrol.core.type.domain";
public static final String TYPE_MAILBOX = "ak.webcontrol.core.type.mailbox";
public static final String TYPE_MAIL_ALIAS = "ak.webcontrol.core.type.mailAlias";
public static final String TYPE_MAIL_ALIAS_DESTINATION
= "ak.webcontrol.core.type.mailAliasDestination";
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/form/MailAliasDestBean.java
0,0 → 1,53
package ak.webcontrol.core.form;
 
import ak.webcontrol.util.StringConverter;
import ak.webcontrol.core.model.MailAliasDestination;
 
public final class MailAliasDestBean
{
private String id;
private String mailbox;
private String email;
 
public MailAliasDestBean()
{
}
 
public MailAliasDestBean(MailAliasDestination dest)
{
this.id = StringConverter.toString(dest.getId());
this.mailbox = (dest.getMailbox() == null)
? null : StringConverter.toString(dest.getMailbox().getId());
this.email = dest.getEmail();
}
 
public String getId()
{
return id;
}
 
public void setId(String id)
{
this.id = id;
}
 
public String getMailbox()
{
return mailbox;
}
 
public void setMailbox(String mailbox)
{
this.mailbox = mailbox;
}
 
public String getEmail()
{
return email;
}
 
public void setEmail(String email)
{
this.email = email;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/form/UserPasswordForm.java
0,0 → 1,30
package ak.webcontrol.core.form;
 
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
 
import ak.webcontrol.core.CoreResources;
 
public final class UserPasswordForm
extends org.apache.struts.validator.DynaValidatorForm
{
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = super.validate(mapping, request);
 
if(errors == null || errors.size() == 0) { // if no errors in simple checks
String password = (String)get("password");
String password2 = (String)get("password2");
 
if(!password.equals(password2)) {
if(errors == null) errors = new ActionErrors();
errors.add("password", new ActionError(CoreResources.PASSWORDS_DONT_MATCH));
}
}
 
return errors;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/servlet/EncodingFilter.java
0,0 → 1,37
package ak.webcontrol.core.servlet;
 
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
 
public class EncodingFilter
implements Filter
{
public static final String ENCODING = "UTF-8";
 
private FilterConfig filterConfig;
 
public void init(FilterConfig filterConfig)
throws ServletException
{
this.filterConfig = filterConfig;
}
 
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException
{
if(request.getCharacterEncoding() == null)
request.setCharacterEncoding(ENCODING);
 
chain.doFilter(request, response);
}
 
public void destroy()
{
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/servlet/LoginFilter.java
0,0 → 1,169
package ak.webcontrol.core.servlet;
 
import java.util.List;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.IOException;
import java.net.URLEncoder;
import java.security.Principal;
import java.security.AccessControlException;
 
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.log4j.Logger;
 
import ak.backpath.BackPath;
 
import ak.webcontrol.core.model.User;
 
/**
* Ensures that user is logged in to the system to process its request.
*/
public class LoginFilter
implements Filter
{
private static final Logger logger = Logger.getLogger(LoginFilter.class);
 
private FilterConfig filterConfig;
private String loginUrl;
private String loginServlet;
private List passUrls = new ArrayList();
private List passMasks = new ArrayList();
 
public void init(FilterConfig filterConfig)
throws ServletException
{
// get config
this.filterConfig = filterConfig;
 
if(filterConfig == null)
throw new ServletException("No configuration for the filter");
 
// get login url
loginUrl = filterConfig.getInitParameter("loginUrl");
 
if(loginUrl == null)
throw new ServletException("No login URL specified");
 
// ensure it's absolute path
if(!loginUrl.startsWith("/"))
loginUrl = "/" + loginUrl;
 
// get servlet part ot the url
int qPos = loginUrl.indexOf("?");
 
if(qPos < 0)
loginServlet = loginUrl;
else
loginServlet = loginUrl.substring(0, qPos);
 
// get pass through URLs
String passUrlsStr = filterConfig.getInitParameter("passUrls");
if(passUrlsStr != null) {
String[] urls = passUrlsStr.split("\\s*;\\s*");
 
for(int i = 0; i < urls.length; i++) {
if(urls[i].endsWith("*")) {
passMasks.add(urls[i].substring(0, urls[i].length()-1));
}
else {
passUrls.add(urls[i]);
}
}
}
 
// avoid loop
if(!isPassThrough(loginServlet)) {
passUrls.add(loginServlet);
}
}
 
private boolean isPassThrough(String url)
{
for(int i = 0; i < passUrls.size(); i++) {
if(url.equals((String)passUrls.get(i))) return true;
}
 
for(int i = 0; i < passMasks.size(); i++) {
if(url.startsWith((String)passMasks.get(i))) return true;
}
 
return false;
}
 
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException
{
boolean processNext;
 
if(!(request instanceof HttpServletRequest))
throw new ServletException("Do not know how to handle non-HTTP requests");
if(!(response instanceof HttpServletResponse))
throw new ServletException("Do not know how to handle non-HTTP response");
 
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse = (HttpServletResponse)response;
 
logger.debug("Requested " + httpRequest.getServletPath());
 
if(isPassThrough(httpRequest.getServletPath())) {
processNext = true;
logger.debug("pass through");
}
else {
try {
HttpSession session = httpRequest.getSession(false);
 
if(session == null)
throw new AccessControlException("No session");
 
Object userObj = session.getAttribute("user");
if(userObj == null)
throw new AccessControlException("No user");
 
if(!(userObj instanceof User))
throw new ServletException(
"Wrong type of user information: " + userObj.getClass().getName());
 
processNext = true;
logger.debug("User found - OK");
}
catch(AccessControlException ex) {
String origin = httpRequest.getRequestURI();
String originParams = httpRequest.getQueryString();
 
String redirectUrl;
try {
redirectUrl = httpRequest.getContextPath() + loginUrl
+ BackPath.findBackPath(httpRequest).getForwardParams();
}
catch(Exception ex2) {
logger.error("Cannot get forward redirect", ex2);
redirectUrl = httpRequest.getContextPath() + loginUrl;
}
 
logger.info("Redirect because of '" + ex.getMessage() + "' to " + redirectUrl);
httpResponse.sendRedirect(httpResponse.encodeRedirectURL(redirectUrl));
 
processNext = false;
}
}
 
if(processNext) { // no problems found
chain.doFilter(request, response);
}
}
 
public void destroy()
{
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/servlet/HibernateFilter.java
0,0 → 1,106
package ak.webcontrol.core.servlet;
 
import java.util.List;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.IOException;
import java.net.URLEncoder;
import java.security.Principal;
import java.security.AccessControlException;
 
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.log4j.Logger;
 
import net.sf.hibernate.HibernateException;
 
import ak.webcontrol.util.HibernateUtil;
import ak.webcontrol.util.ModelException;
 
public class HibernateFilter
implements Filter
{
private static final Logger logger = Logger.getLogger(HibernateFilter.class);
 
private FilterConfig filterConfig;
 
public void init(FilterConfig filterConfig)
throws ServletException
{
// get config
this.filterConfig = filterConfig;
 
if(filterConfig != null) {
// register hibernate classes
String toRegister = filterConfig.getInitParameter("register");
if(toRegister != null) {
String[] registers = toRegister.split("\\s*;\\s*");
 
for(int i = 0; i < registers.length; i++) {
try {
String name = registers[i].trim();
if(name.equals("")) continue;
 
Class cl = Class.forName(name);
}
catch(Exception ex) {
logger.error("cannot register class", ex);
}
}
}
}
}
 
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException
{
try {
logger.info("begin transaction");
HibernateUtil.beginTransaction();
 
chain.doFilter(request, response);
 
if(HibernateUtil.isTransactionOpen()) {
logger.info("commit transaction");
HibernateUtil.commitTransaction();
}
}
catch(Exception ex) {
logger.error("exception by program execution", ex);
try {
if(HibernateUtil.isTransactionOpen()) {
logger.info("rollback transaction");
HibernateUtil.rollbackTransaction();
}
}
catch(Exception ex2) {
logger.error("cannot rollback transaction", ex2);
}
 
if(ex instanceof ServletException)
throw (ServletException)ex;
else
throw new ServletException("Internal server error");
}
 
try {
HibernateUtil.closeSession();
}
catch(Exception ex) {
logger.error("cannot close session", ex);
}
}
 
public void destroy()
{
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/util/UserException.java
0,0 → 1,28
package ak.webcontrol.util;
 
public class UserException
extends Exception
{
private Object[] values;
 
public UserException()
{
this(null, null);
}
 
public UserException(String message)
{
this(message, null);
}
 
public UserException(String message, Object[] values)
{
super(message);
this.values = values;
}
 
public Object[] getValues()
{
return values;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/util/StringConverter.java
0,0 → 1,42
package ak.webcontrol.util;
 
public abstract class StringConverter
{
public static Long parseLong(Object o)
throws NumberFormatException
{
if(o instanceof String) {
String s = (String)o;
if(s == null || s.equals(""))
return null;
else
return new Long(s);
}
else {
throw new ClassCastException("String is expected, but it is " + o.getClass());
}
}
 
public static Integer parseInteger(Object o)
throws NumberFormatException
{
if(o instanceof String) {
String s = (String)o;
if(s == null || s.equals(""))
return null;
else
return new Integer(s);
}
else {
throw new ClassCastException("String is expected, but it is " + o.getClass());
}
}
 
public static String toString(Object o)
{
if(o == null)
return null;
else
return o.toString();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/util/Digest.java
0,0 → 1,51
package ak.webcontrol.util;
 
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
public class Digest
{
/**
* digest to encode passwords
*/
protected static MessageDigest digest = null;
 
private static final char[] hexDigits = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
 
public static String encode(String password)
{
return bytesToHex(digest.digest(password.getBytes()));
}
 
/**
* converts password bytes to hex string
*/
protected static String bytesToHex(byte[] bytes)
{
char[] buffer = new char[bytes.length * 2];
 
for (int i = 0; i < bytes.length; i++) {
int low = (int)( bytes[i] & 0x0f);
int high = (int)((bytes[i] & 0xf0) >> 4);
 
buffer[i * 2] = hexDigits[high];
buffer[i * 2 + 1] = hexDigits[low];
}
 
return new String(buffer);
}
 
/**
* digest initialization
*/
static {
try {
digest = MessageDigest.getInstance("MD5");
}
catch(NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/util/HibernateUtil.java
0,0 → 1,109
package ak.webcontrol.util;
 
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
 
public class HibernateUtil
{
private static Configuration configuration;
private static SessionFactory sessionFactory;
private static final ThreadLocal hibernateBean = new ThreadLocal();
 
public static Configuration getConfiguration()
throws HibernateException
{
if(configuration == null)
configuration = new Configuration();
 
return configuration;
}
 
public static SessionFactory getSessionFactory()
throws HibernateException
{
if(sessionFactory == null)
sessionFactory = getConfiguration().configure().buildSessionFactory();
 
return sessionFactory;
}
 
private static HibernateBean currentBean()
throws HibernateException
{
HibernateBean hb = (HibernateBean)hibernateBean.get();
 
if(hb == null) {
hb = new HibernateBean();
hb.session = getSessionFactory().openSession();
hibernateBean.set(hb);
}
return hb;
}
 
public static Session currentSession()
throws HibernateException
{
return currentBean().session;
}
 
public static void closeSession()
throws HibernateException, ModelException
{
HibernateBean hb = (HibernateBean)hibernateBean.get();
 
if(hb == null)
throw new ModelException("No session found for this thread");
 
hibernateBean.set(null);
hb.session.close();
}
 
public static void beginTransaction()
throws HibernateException, ModelException
{
HibernateBean hb = (HibernateBean)hibernateBean.get();
 
if(hb != null && hb.transaction != null)
throw new ModelException("Transaction is already open");
 
currentBean().transaction = currentSession().beginTransaction();
}
 
public static boolean isTransactionOpen()
throws HibernateException, ModelException
{
HibernateBean hb = (HibernateBean)hibernateBean.get();
 
return (hb != null) && (hb.transaction != null);
}
 
public static void commitTransaction()
throws HibernateException, ModelException
{
HibernateBean hb = (HibernateBean)hibernateBean.get();
 
if(hb == null || hb.transaction == null)
throw new ModelException("No open transaction");
 
hb.transaction.commit();
hb.transaction = null;
}
 
public static void rollbackTransaction()
throws HibernateException, ModelException
{
HibernateBean hb = (HibernateBean)hibernateBean.get();
 
if(hb == null || hb.transaction == null)
throw new ModelException("No open transaction");
 
hb.transaction.rollback();
hb.transaction = null;
}
 
static class HibernateBean
{
public Session session;
public Transaction transaction;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/util/ModelException.java
0,0 → 1,44
package ak.webcontrol.util;
 
public class ModelException
extends Exception
{
private Exception chainedException;
 
public ModelException()
{
this(null, null);
}
 
public ModelException(String message)
{
this(message, null);
}
 
public ModelException(Exception chainedException)
{
this(null, chainedException);
}
 
public ModelException(String message, Exception chainedException)
{
super(message);
this.chainedException = chainedException;
}
 
public Exception getChainedException()
{
return chainedException;
}
 
public void setChainedException(Exception chainedException)
{
this.chainedException = chainedException;
}
 
public String toString()
{
return super.toString()
+ (chainedException == null ? "" : "\n" + chainedException.toString());
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/util/FormException.java
0,0 → 1,39
package ak.webcontrol.util;
 
public class FormException
extends UserException
{
private String property;
 
public FormException()
{
this(null, null, null);
}
 
public FormException(String message)
{
this(message, null, null);
}
 
public FormException(String message, String property)
{
this(message, property, null);
}
 
public FormException(String message, String property, Object[] values)
{
super(message, values);
this.property = property;
}
 
public String getProperty()
{
return property;
}
 
public String toString()
{
return super.toString()
+ (property == null ? "" : " for " + property);
}
}