Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 918 → Rev 919

/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/SystemUserAction.java
1,124 → 1,124
package ak.hostcaptain.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;
package ak.hostcaptain.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.hostcaptain.util.StringConverter;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
import ak.hostcaptain.core.model.SystemUser;
import ak.hostcaptain.core.model.SystemUserManager;
 
public final class SystemUserAction
extends Action
import ak.backpath.BackPath;
 
import ak.hostcaptain.util.StringConverter;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
import ak.hostcaptain.core.model.SystemUser;
import ak.hostcaptain.core.model.SystemUserManager;
 
public final class SystemUserAction
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");
User user = (User)request.getSession().getAttribute("user");
initUserList(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(SystemUserManager.getInstance().listSystemUsers(user));
Collections.sort(list, SystemUserManager.NAME_COMPARATOR);
request.setAttribute("users", list);
request.setAttribute("allowedToCreate",
new Boolean(SystemUserManager.getInstance().allowedToCreate(user)));
 
return mapping.findForward("default");
}
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.hostcaptain.core.form.SystemUserEditForm");
 
if(userId == null) {
showForm.set("enabled", new Boolean(true));
}
else {
SystemUser u = SystemUserManager.getInstance().get(user, userId);
showForm.set("uid", StringConverter.toString(u.getUid()));
showForm.set("name", u.getName());
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(user));
Collections.sort(list, SystemUserManager.NAME_COMPARATOR);
request.setAttribute("users", list);
request.setAttribute("allowedToCreate",
new Boolean(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"));
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ak.hostcaptain.core.form.SystemUserEditForm");
 
if(userId == null) {
showForm.set("enabled", new Boolean(true));
}
else {
SystemUser 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());
}
 
showForm.set("owner", StringConverter.toString(u.getOwner().getId()));
showForm.set("enabled", u.getEnabled());
showForm.set("comment", u.getComment());
}
 
initUserList(request, user);
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);
}
 
u.setUid(StringConverter.parseInteger(theForm.get("uid")));
u.setName((String)theForm.get("name"));
 
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);
}
 
u.setUid(StringConverter.parseInteger(theForm.get("uid")));
u.setName((String)theForm.get("name"));
 
Long ownerId = StringConverter.parseLong(theForm.get("owner"));
if(ownerId == null)
u.setOwner(null);
else
u.setOwner(UserManager.getInstance().get(user, ownerId));
 
u.setEnabled((Boolean)theForm.get("enabled"));
u.setComment((String)theForm.get("comment"));
 
SystemUserManager.getInstance().save(user, u);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
else {
throw new Exception("unknown mapping parameter");
}
}
 
u.setEnabled((Boolean)theForm.get("enabled"));
u.setComment((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
{
126,4 → 126,4
Collections.sort(list, UserManager.LOGIN_COMPARATOR);
request.setAttribute("users", list);
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/IndexAction.java
1,37 → 1,37
package ak.hostcaptain.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.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.SystemUserManager;
import ak.hostcaptain.core.model.InetDomainManager;
import ak.hostcaptain.core.model.MailboxManager;
import ak.hostcaptain.core.model.MailAliasManager;
 
public final class IndexAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
User user = (User)request.getSession().getAttribute("user");
 
request.setAttribute("showSystemUsers",
new Boolean(SystemUserManager.getInstance().areSystemUsersAvailable(user)));
request.setAttribute("showInetDomains",
new Boolean(InetDomainManager.getInstance().areInetDomainsAvailable(user)));
request.setAttribute("showMailboxes",
new Boolean(MailboxManager.getInstance().areMailboxesAvailable(user)));
request.setAttribute("showMailAliases",
new Boolean(MailAliasManager.getInstance().areMailAliasesAvailable(user)));
 
return mapping.findForward("success");
}
}
package ak.hostcaptain.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.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.SystemUserManager;
import ak.hostcaptain.core.model.InetDomainManager;
import ak.hostcaptain.core.model.MailboxManager;
import ak.hostcaptain.core.model.MailAliasManager;
 
public final class IndexAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
User user = (User)request.getSession().getAttribute("user");
 
request.setAttribute("showSystemUsers",
new Boolean(SystemUserManager.getInstance().areSystemUsersAvailable(user)));
request.setAttribute("showInetDomains",
new Boolean(InetDomainManager.getInstance().areInetDomainsAvailable(user)));
request.setAttribute("showMailboxes",
new Boolean(MailboxManager.getInstance().areMailboxesAvailable(user)));
request.setAttribute("showMailAliases",
new Boolean(MailAliasManager.getInstance().areMailAliasesAvailable(user)));
 
return mapping.findForward("success");
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/InetDomainAction.java
1,123 → 1,123
package ak.hostcaptain.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.hostcaptain.util.StringConverter;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
import ak.hostcaptain.core.model.InetDomain;
import ak.hostcaptain.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())) {
User user = (User)request.getSession().getAttribute("user");
initUserList(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(InetDomainManager.getInstance().listInetDomains(user));
Collections.sort(list, InetDomainManager.NAME_COMPARATOR);
request.setAttribute("domains", list);
request.setAttribute("allowedToCreate",
new Boolean(InetDomainManager.getInstance().allowedToCreate(user)));
 
return mapping.findForward("default");
}
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.hostcaptain.core.form.InetDomainEditForm");
 
if(domainId == null) {
showForm.set("enabled", new Boolean(true));
}
else {
InetDomain 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);
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);
}
 
domain.setName((String)theForm.get("name"));
domain.setOwner(UserManager.getInstance().get(user,
StringConverter.parseLong(theForm.get("owner"))));
 
domain.setEnabled((Boolean)theForm.get("enabled"));
domain.setComment((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);
}
}
package ak.hostcaptain.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.hostcaptain.util.StringConverter;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
import ak.hostcaptain.core.model.InetDomain;
import ak.hostcaptain.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())) {
User user = (User)request.getSession().getAttribute("user");
initUserList(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(InetDomainManager.getInstance().listInetDomains(user));
Collections.sort(list, InetDomainManager.NAME_COMPARATOR);
request.setAttribute("domains", list);
request.setAttribute("allowedToCreate",
new Boolean(InetDomainManager.getInstance().allowedToCreate(user)));
 
return mapping.findForward("default");
}
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.hostcaptain.core.form.InetDomainEditForm");
 
if(domainId == null) {
showForm.set("enabled", new Boolean(true));
}
else {
InetDomain 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);
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);
}
 
domain.setName((String)theForm.get("name"));
domain.setOwner(UserManager.getInstance().get(user,
StringConverter.parseLong(theForm.get("owner"))));
 
domain.setEnabled((Boolean)theForm.get("enabled"));
domain.setComment((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);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/ChangePasswordAction.java
1,51 → 1,51
package ak.hostcaptain.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.hostcaptain.core.CoreResources;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.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.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();
}
}
}
}
package ak.hostcaptain.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.hostcaptain.core.CoreResources;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.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.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();
}
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/LoginAction.java
1,53 → 1,53
package ak.hostcaptain.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.hostcaptain.core.CoreResources;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.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;
}
}
}
}
package ak.hostcaptain.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.hostcaptain.core.CoreResources;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.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
1,27 → 1,27
package ak.hostcaptain.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");
}
}
package ak.hostcaptain.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
1,163 → 1,163
package ak.hostcaptain.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.hostcaptain.util.StringConverter;
import ak.hostcaptain.util.UserException;
import ak.hostcaptain.core.CoreResources;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
import ak.hostcaptain.core.model.Mailbox;
import ak.hostcaptain.core.model.MailboxManager;
import ak.hostcaptain.core.model.SystemUserManager;
import ak.hostcaptain.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())) {
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(MailboxManager.getInstance().listMailboxes(user));
Collections.sort(list, MailboxManager.LOGIN_COMPARATOR);
request.setAttribute("mailboxes", list);
request.setAttribute("allowedToCreate",
new Boolean(MailboxManager.getInstance().allowedToCreate(user)));
 
return mapping.findForward("default");
}
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.hostcaptain.core.form.MailboxEditForm");
 
if(boxId == null) {
showForm.set("enabled", new Boolean(true));
showForm.set("viruscheck", new Boolean(true));
showForm.set("spamcheck", new Boolean(true));
}
else {
Mailbox mailbox = MailboxManager.getInstance().get(user, boxId);
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);
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(""))
throw new UserException(CoreResources.PASSWORD_REQUIRED);
 
mailbox = MailboxManager.getInstance().create(user);
 
// FIXME: create an user as owner of the new mailbox here
}
else {
mailbox = MailboxManager.getInstance().get(user, boxId);
}
 
mailbox.setLogin((String)theForm.get("login"));
mailbox.setDomain(InetDomainManager.getInstance().get(user,
StringConverter.parseLong(theForm.get("domain"))));
mailbox.setOwner(UserManager.getInstance().get(user,
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(user, systemUserId));
}
 
if(password != null && !password.equals(""))
mailbox.setNewPassword(password);
 
mailbox.setEnabled((Boolean)theForm.get("enabled"));
mailbox.setComment((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);
}
}
package ak.hostcaptain.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.hostcaptain.util.StringConverter;
import ak.hostcaptain.util.UserException;
import ak.hostcaptain.core.CoreResources;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
import ak.hostcaptain.core.model.Mailbox;
import ak.hostcaptain.core.model.MailboxManager;
import ak.hostcaptain.core.model.SystemUserManager;
import ak.hostcaptain.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())) {
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(MailboxManager.getInstance().listMailboxes(user));
Collections.sort(list, MailboxManager.LOGIN_COMPARATOR);
request.setAttribute("mailboxes", list);
request.setAttribute("allowedToCreate",
new Boolean(MailboxManager.getInstance().allowedToCreate(user)));
 
return mapping.findForward("default");
}
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.hostcaptain.core.form.MailboxEditForm");
 
if(boxId == null) {
showForm.set("enabled", new Boolean(true));
showForm.set("viruscheck", new Boolean(true));
showForm.set("spamcheck", new Boolean(true));
}
else {
Mailbox mailbox = MailboxManager.getInstance().get(user, boxId);
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);
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(""))
throw new UserException(CoreResources.PASSWORD_REQUIRED);
 
mailbox = MailboxManager.getInstance().create(user);
 
// FIXME: create an user as owner of the new mailbox here
}
else {
mailbox = MailboxManager.getInstance().get(user, boxId);
}
 
mailbox.setLogin((String)theForm.get("login"));
mailbox.setDomain(InetDomainManager.getInstance().get(user,
StringConverter.parseLong(theForm.get("domain"))));
mailbox.setOwner(UserManager.getInstance().get(user,
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(user, systemUserId));
}
 
if(password != null && !password.equals(""))
mailbox.setNewPassword(password);
 
mailbox.setEnabled((Boolean)theForm.get("enabled"));
mailbox.setComment((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);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/MailAliasAction.java
1,254 → 1,254
package ak.hostcaptain.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.hostcaptain.util.StringConverter;
import ak.hostcaptain.util.UserException;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
import ak.hostcaptain.core.model.Mailbox;
import ak.hostcaptain.core.model.MailboxManager;
import ak.hostcaptain.core.model.MailAlias;
import ak.hostcaptain.core.model.MailAliasManager;
import ak.hostcaptain.core.model.MailAliasDestination;
import ak.hostcaptain.core.model.MailAliasDestinationManager;
import ak.hostcaptain.core.model.InetDomainManager;
import ak.hostcaptain.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(user));
Collections.sort(list, MailAliasManager.ADDRESS_COMPARATOR);
request.setAttribute("aliases", list);
request.setAttribute("allowedToCreate",
new Boolean(MailAliasManager.getInstance().allowedToCreate(user)));
 
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.hostcaptain.core.form.MailAliasEditForm");
 
if(aliasId == null) {
showForm.set("enabled", new Boolean(true));
}
else {
MailAlias alias = MailAliasManager.getInstance().get(user, 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()));
showForm.set("enabled", alias.getEnabled());
showForm.set("comment", alias.getComment());
}
 
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(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) ? null
: 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")))
throw new UserException("ak.hostcaptain.core.mail.alias.edit.address.empty");
if(StringConverter.isEmpty(theForm.get("domain")))
throw new UserException("ak.hostcaptain.core.mail.alias.edit.domain.wrong");
if(StringConverter.isEmpty(theForm.get("owner")))
throw new UserException("ak.hostcaptain.core.mail.alias.edit.owner.wrong");
 
if(alias == null)
alias = MailAliasManager.getInstance().create(user);
 
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(user);
else
dest = MailAliasDestinationManager.getInstance().get(user, destId);
 
// set mailbox or email
if(mailboxId != null) {
dest.setMailbox(MailboxManager.getInstance().get(user, mailboxId));
dest.setEmail(null);
}
else if(dests[i].getEmail() != null && !dests[i].getEmail().equals("")) {
dest.setMailbox(null);
dest.setEmail(dests[i].getEmail());
}
 
dest.setEnabled(dests[i].getEnabled());
dest.setComment(dests[i].getComment());
 
// connect
dest.setAlias(alias);
alias.getDestinations().add(dest);
}
 
alias.setAddress((String)theForm.get("address"));
alias.setDomain(InetDomainManager.getInstance().get(user,
StringConverter.parseLong(theForm.get("domain"))));
alias.setOwner(UserManager.getInstance().get(user,
StringConverter.parseLong(theForm.get("owner"))));
alias.setEnabled((Boolean)theForm.get("enabled"));
alias.setComment((String)theForm.get("comment"));
 
// 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(new Boolean(true));
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;
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(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);
}
}
package ak.hostcaptain.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.hostcaptain.util.StringConverter;
import ak.hostcaptain.util.UserException;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
import ak.hostcaptain.core.model.Mailbox;
import ak.hostcaptain.core.model.MailboxManager;
import ak.hostcaptain.core.model.MailAlias;
import ak.hostcaptain.core.model.MailAliasManager;
import ak.hostcaptain.core.model.MailAliasDestination;
import ak.hostcaptain.core.model.MailAliasDestinationManager;
import ak.hostcaptain.core.model.InetDomainManager;
import ak.hostcaptain.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(user));
Collections.sort(list, MailAliasManager.ADDRESS_COMPARATOR);
request.setAttribute("aliases", list);
request.setAttribute("allowedToCreate",
new Boolean(MailAliasManager.getInstance().allowedToCreate(user)));
 
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.hostcaptain.core.form.MailAliasEditForm");
 
if(aliasId == null) {
showForm.set("enabled", new Boolean(true));
}
else {
MailAlias alias = MailAliasManager.getInstance().get(user, 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()));
showForm.set("enabled", alias.getEnabled());
showForm.set("comment", alias.getComment());
}
 
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(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) ? null
: 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")))
throw new UserException("ak.hostcaptain.core.mail.alias.edit.address.empty");
if(StringConverter.isEmpty(theForm.get("domain")))
throw new UserException("ak.hostcaptain.core.mail.alias.edit.domain.wrong");
if(StringConverter.isEmpty(theForm.get("owner")))
throw new UserException("ak.hostcaptain.core.mail.alias.edit.owner.wrong");
 
if(alias == null)
alias = MailAliasManager.getInstance().create(user);
 
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(user);
else
dest = MailAliasDestinationManager.getInstance().get(user, destId);
 
// set mailbox or email
if(mailboxId != null) {
dest.setMailbox(MailboxManager.getInstance().get(user, mailboxId));
dest.setEmail(null);
}
else if(dests[i].getEmail() != null && !dests[i].getEmail().equals("")) {
dest.setMailbox(null);
dest.setEmail(dests[i].getEmail());
}
 
dest.setEnabled(dests[i].getEnabled());
dest.setComment(dests[i].getComment());
 
// connect
dest.setAlias(alias);
alias.getDestinations().add(dest);
}
 
alias.setAddress((String)theForm.get("address"));
alias.setDomain(InetDomainManager.getInstance().get(user,
StringConverter.parseLong(theForm.get("domain"))));
alias.setOwner(UserManager.getInstance().get(user,
StringConverter.parseLong(theForm.get("owner"))));
alias.setEnabled((Boolean)theForm.get("enabled"));
alias.setComment((String)theForm.get("comment"));
 
// 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(new Boolean(true));
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;
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(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);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/action/UserExceptionHandler.java
1,62 → 1,62
package ak.hostcaptain.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.hostcaptain.util.UserException;
import ak.hostcaptain.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();
}
}
package ak.hostcaptain.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.hostcaptain.util.UserException;
import ak.hostcaptain.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
1,166 → 1,166
package ak.hostcaptain.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;
package ak.hostcaptain.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.hostcaptain.util.StringConverter;
import ak.hostcaptain.util.UserException;
import ak.hostcaptain.core.CoreResources;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
 
public final class UserAction
extends Action
import ak.backpath.BackPath;
 
import ak.hostcaptain.util.StringConverter;
import ak.hostcaptain.util.UserException;
import ak.hostcaptain.core.CoreResources;
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.UserManager;
 
public final class UserAction
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");
User user = (User)request.getSession().getAttribute("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);
 
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
{
User user = (User)request.getSession().getAttribute("user");
 
if("list".equals(mapping.getParameter())) {
List list = new ArrayList(UserManager.getInstance().listUsers(user));
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"));
User u;
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ak.hostcaptain.core.form.UserEditForm");
 
if(userId == null) {
u = UserManager.getInstance().create(user);
showForm.set("enabled", new Boolean(true));
}
else {
u = UserManager.getInstance().get(user, userId);
showForm.set("login", u.getLogin());
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(user));
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"));
User u;
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ak.hostcaptain.core.form.UserEditForm");
 
if(userId == null) {
u = UserManager.getInstance().create(user);
showForm.set("enabled", new 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("enabled", u.getEnabled());
showForm.set("comment", u.getComment());
}
 
showForm.set("superuser", u.getSuperuser());
showForm.set("enabled", u.getEnabled());
showForm.set("comment", u.getComment());
}
 
initUserList(request, user);
request.setAttribute("u", u);
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))
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(""))
throw new UserException(CoreResources.PASSWORD_REQUIRED);
 
u = UserManager.getInstance().create(user);
}
else {
u = UserManager.getInstance().get(user, userId);
}
request.setAttribute("u", u);
 
u.setLogin(user, (String)theForm.get("login"));
 
request.setAttribute("u", u);
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))
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(""))
throw new UserException(CoreResources.PASSWORD_REQUIRED);
 
u = UserManager.getInstance().create(user);
}
else {
u = UserManager.getInstance().get(user, userId);
}
request.setAttribute("u", u);
 
u.setLogin(user, (String)theForm.get("login"));
 
if(u.editableBy(user)) {
Long bossId = StringConverter.parseLong(theForm.get("boss"));
if(bossId == null)
u.setBoss(user, null);
u.setBoss(user, null);
else
u.setBoss(user, UserManager.getInstance().get(user, bossId));
}
 
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.mayChangePassword(user)) // user have to enter first the old password
{
u.setPassword(user, password);
}
 
u.setEnabled((Boolean)theForm.get("enabled"));
u.setComment((String)theForm.get("comment"));
 
UserManager.getInstance().save(user, u);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
else {
throw new Exception("unknown mapping parameter");
}
}
u.setSuperuser(user, (Boolean)theForm.get("superuser"));
 
if(password != null && !password.equals("")
&& u.editableBy(user) // more strong condition, because normal
&& u.mayChangePassword(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 {
throw new Exception("unknown mapping parameter");
}
}
 
private void initUserList(HttpServletRequest request, User user)
throws Exception
{
168,4 → 168,4
Collections.sort(list, UserManager.LOGIN_COMPARATOR);
request.setAttribute("users", list);
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAlias.java
1,127 → 1,127
package ak.hostcaptain.core.model;
 
import java.util.Collection;
 
/**
*
* @hibernate.class table="mailaliases"
*/
public class MailAlias
extends GeneralModelObject
{
private Long id;
private String address;
private InetDomain domain;
private User owner;
private Collection destinations; // Collection(MailAliasDestintion)
 
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.hostcaptain.core.model.MailAliasDestination"
*/
public Collection getDestinations()
{
return destinations;
}
 
/**
* @param destinations Collection(MailAliasDestination)
*/
protected void setDestinations(Collection destinations)
{
this.destinations = destinations;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_MAIL_ALIAS;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_MAIL_ALIAS;
}
 
public Object[] getIdentParams()
{
return new Object[] { getAddress(), getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
}
package ak.hostcaptain.core.model;
 
import java.util.Collection;
 
/**
*
* @hibernate.class table="mailaliases"
*/
public class MailAlias
extends GeneralModelObject
{
private Long id;
private String address;
private InetDomain domain;
private User owner;
private Collection destinations; // Collection(MailAliasDestintion)
 
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.hostcaptain.core.model.MailAliasDestination"
*/
public Collection getDestinations()
{
return destinations;
}
 
/**
* @param destinations Collection(MailAliasDestination)
*/
protected void setDestinations(Collection destinations)
{
this.destinations = destinations;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_MAIL_ALIAS;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_MAIL_ALIAS;
}
 
public Object[] getIdentParams()
{
return new Object[] { getAddress(), getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasDestination.java
1,110 → 1,110
package ak.hostcaptain.core.model;
 
/**
*
* @hibernate.class table="mailaliasdests"
*/
public class MailAliasDestination
extends GeneralModelObject
{
private Long id;
private MailAlias alias;
private Mailbox mailbox;
private String email;
 
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;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_MAIL_ALIAS_DESTINATION;
}
 
public String getIdentKey()
{
if(getMailbox() == null)
return ak.hostcaptain.core.CoreResources.IDENT_MAIL_ALIAS_DESTINATION_EXTERNAL;
else
return ak.hostcaptain.core.CoreResources.IDENT_MAIL_ALIAS_DESTINATION_INTERNAL;
}
 
public Object[] getIdentParams()
{
if(getMailbox() == null)
return new Object[] { getEmail() };
else
return new Object[] { getMailbox().getLogin(), getMailbox().getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return alias.viewableBy(user);
}
 
public boolean editableBy(User user)
{
return alias.editableBy(user);
}
 
public boolean deleteableBy(User user)
{
return alias.deleteableBy(user);
}
}
package ak.hostcaptain.core.model;
 
/**
*
* @hibernate.class table="mailaliasdests"
*/
public class MailAliasDestination
extends GeneralModelObject
{
private Long id;
private MailAlias alias;
private Mailbox mailbox;
private String email;
 
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;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_MAIL_ALIAS_DESTINATION;
}
 
public String getIdentKey()
{
if(getMailbox() == null)
return ak.hostcaptain.core.CoreResources.IDENT_MAIL_ALIAS_DESTINATION_EXTERNAL;
else
return ak.hostcaptain.core.CoreResources.IDENT_MAIL_ALIAS_DESTINATION_INTERNAL;
}
 
public Object[] getIdentParams()
{
if(getMailbox() == null)
return new Object[] { getEmail() };
else
return new Object[] { getMailbox().getLogin(), getMailbox().getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return alias.viewableBy(user);
}
 
public boolean editableBy(User user)
{
return alias.editableBy(user);
}
 
public boolean deleteableBy(User user)
{
return alias.deleteableBy(user);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/SystemUserManager.java
1,240 → 1,240
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
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/hostcaptain/core/model/SystemUser.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private SystemUserManager()
{
}
 
public SystemUser create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new SystemUser();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser();
}
 
public SystemUser get(User editor, Long id)
throws ModelException
{
SystemUser user;
 
try {
user = (SystemUser)HibernateUtil.currentSession().load(SystemUser.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!user.viewableBy(editor))
throw new ModelSecurityException();
 
return user;
}
 
protected 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);
}
}
 
protected 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(User editor, SystemUser systemUser)
throws ModelException
{
if(!systemUser.editableBy(editor))
throw new ModelSecurityException();
 
systemUser.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(systemUser);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, SystemUser systemUser)
throws ModelException
{
if(!systemUser.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(systemUser);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listSystemUsers(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()) {
return HibernateUtil.currentSession().find("from SystemUser");
}
else {
return HibernateUtil.currentSession().find(
"select u from SystemUser u left join u.owner o where o is null or o=?",
editor, Hibernate.entity(User.class));
}
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areSystemUsersAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return true;
else
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from SystemUser u left join u.owner o where o is null or o=?",
editor, Hibernate.entity(User.class)).next()).intValue() > 0;
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static SystemUserManager systemUserManager = null;
 
public static SystemUserManager getInstance()
{
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);
}
}
}
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
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/hostcaptain/core/model/SystemUser.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private SystemUserManager()
{
}
 
public SystemUser create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new SystemUser();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser();
}
 
public SystemUser get(User editor, Long id)
throws ModelException
{
SystemUser user;
 
try {
user = (SystemUser)HibernateUtil.currentSession().load(SystemUser.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!user.viewableBy(editor))
throw new ModelSecurityException();
 
return user;
}
 
protected 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);
}
}
 
protected 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(User editor, SystemUser systemUser)
throws ModelException
{
if(!systemUser.editableBy(editor))
throw new ModelSecurityException();
 
systemUser.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(systemUser);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, SystemUser systemUser)
throws ModelException
{
if(!systemUser.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(systemUser);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listSystemUsers(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()) {
return HibernateUtil.currentSession().find("from SystemUser");
}
else {
return HibernateUtil.currentSession().find(
"select u from SystemUser u left join u.owner o where o is null or o=?",
editor, Hibernate.entity(User.class));
}
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areSystemUsersAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return true;
else
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from SystemUser u left join u.owner o where o is null or o=?",
editor, Hibernate.entity(User.class)).next()).intValue() > 0;
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static SystemUserManager systemUserManager = null;
 
public static SystemUserManager getInstance()
{
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
1,101 → 1,101
package ak.hostcaptain.core.model;
 
import ak.hostcaptain.util.Digest;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
/**
*
* @hibernate.class table="users"
*/
public class User
extends GeneralModelObject
{
private Long id;
private String login;
private String password;
package ak.hostcaptain.core.model;
 
import ak.hostcaptain.util.Digest;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
/**
*
* @hibernate.class table="users"
*/
public class User
extends GeneralModelObject
{
private Long id;
private String login;
private String password;
private User boss;
private Boolean superuser;
 
protected User()
{
}
 
/**
*
* @hibernate.id generator-class="native"
*/
public Long getId()
{
return id;
}
 
protected void setId(Long id)
{
this.id = id;
}
 
/**
*
* @hibernate.property
*/
public String getLogin()
{
return login;
}
 
protected void setLogin(String login)
{
this.login = login;
}
 
public void setLogin(User editor, String login)
throws ModelException
{
if(!editableBy(editor))
throw new ModelSecurityException();
 
this.login = login;
}
 
/**
*
* @hibernate.property
*/
protected String getPassword()
{
return password;
}
 
protected void setPassword(String password)
{
 
protected User()
{
}
 
/**
*
* @hibernate.id generator-class="native"
*/
public Long getId()
{
return id;
}
 
protected void setId(Long id)
{
this.id = id;
}
 
/**
*
* @hibernate.property
*/
public String getLogin()
{
return login;
}
 
protected void setLogin(String login)
{
this.login = login;
}
 
public void setLogin(User editor, String login)
throws ModelException
{
if(!editableBy(editor))
throw new ModelSecurityException();
 
this.login = login;
}
 
/**
*
* @hibernate.property
*/
protected String getPassword()
{
return password;
}
 
protected void setPassword(String password)
{
this.password = password;
}
 
public void setPassword(User editor, String password)
throws ModelException
{
if(!mayChangePassword(editor))
throw new ModelSecurityException();
 
if(password == null)
throw new NullPointerException("Null password");
 
}
 
public void setPassword(User editor, String password)
throws ModelException
{
if(!mayChangePassword(editor))
throw new ModelSecurityException();
 
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");
 
}
 
public boolean checkPassword(String password)
{
if(password == null)
throw new NullPointerException("Null password");
 
return checkMd5Password(Digest.encode(password));
}
 
public boolean checkMd5Password(String password)
{
}
 
public boolean checkMd5Password(String password)
{
return this.password.equals(password);
}
}
 
/**
*
112,11 → 112,11
}
 
public void setBoss(User editor, User boss)
throws ModelException
throws ModelException
{
if(!editableBy(editor))
throw new ModelSecurityException();
 
if(!editableBy(editor))
throw new ModelSecurityException();
 
this.boss = boss;
}
 
133,7 → 133,7
{
return (superuser != null) && superuser.booleanValue();
}
 
 
protected void setSuperuser(Boolean superuser)
{
this.superuser = superuser;
140,73 → 140,73
}
 
public void setSuperuser(User editor, Boolean superuser)
throws ModelException
throws ModelException
{
if(!mayChangeSuperuser(editor))
throw new ModelSecurityException();
 
if(!mayChangeSuperuser(editor))
throw new ModelSecurityException();
 
this.superuser = superuser;
}
 
public boolean equals(Object o)
{
if(o == null || !(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.hostcaptain.core.CoreResources.TYPE_USER;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_USER;
}
 
public Object[] getIdentParams()
{
return new Object[] { getLogin() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(boss) || user.equals(this);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(boss);
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(boss);
}
 
public boolean mayChangePassword(User user)
{
return user.isSuperuser() || user.equals(boss) || user.equals(this);
}
 
public boolean mayChangeSuperuser(User user)
{
return user.isSuperuser() && !user.equals(this);
}
 
protected static boolean allowedToCreate(UserManager manager, User editor)
throws ModelException
{
return editor.isSuperuser();
}
}
 
public boolean equals(Object o)
{
if(o == null || !(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.hostcaptain.core.CoreResources.TYPE_USER;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_USER;
}
 
public Object[] getIdentParams()
{
return new Object[] { getLogin() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(boss) || user.equals(this);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(boss);
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(boss);
}
 
public boolean mayChangePassword(User user)
{
return user.isSuperuser() || user.equals(boss) || user.equals(this);
}
 
public boolean mayChangeSuperuser(User user)
{
return user.isSuperuser() && !user.equals(this);
}
 
protected static boolean allowedToCreate(UserManager manager, User editor)
throws ModelException
{
return editor.isSuperuser();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/InetDomainManager.java
1,193 → 1,193
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
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/hostcaptain/core/model/InetDomain.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private InetDomainManager()
{
}
 
public InetDomain create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new InetDomain();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser();
}
 
public InetDomain get(User editor, Long id)
throws ModelException
{
InetDomain domain;
 
try {
domain = (InetDomain)HibernateUtil.currentSession().load(
InetDomain.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!domain.viewableBy(editor))
throw new ModelSecurityException();
 
return domain;
}
 
protected 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(User editor, InetDomain inetDomain)
throws ModelException
{
if(!inetDomain.editableBy(editor))
throw new ModelSecurityException();
 
inetDomain.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(inetDomain);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, InetDomain inetDomain)
throws ModelException
{
if(!inetDomain.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
 
HibernateUtil.currentSession().delete(inetDomain);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listInetDomains(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from InetDomain");
else
return HibernateUtil.currentSession().find(
"from InetDomain where owner=?", editor, Hibernate.entity(User.class));
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areInetDomainsAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return true;
else
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from InetDomain where owner=?",
editor, Hibernate.entity(User.class)).next()).intValue() > 0;
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static InetDomainManager inetDomainManager = null;
 
public static InetDomainManager getInstance()
{
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);
}
}
}
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
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/hostcaptain/core/model/InetDomain.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private InetDomainManager()
{
}
 
public InetDomain create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new InetDomain();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser();
}
 
public InetDomain get(User editor, Long id)
throws ModelException
{
InetDomain domain;
 
try {
domain = (InetDomain)HibernateUtil.currentSession().load(
InetDomain.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!domain.viewableBy(editor))
throw new ModelSecurityException();
 
return domain;
}
 
protected 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(User editor, InetDomain inetDomain)
throws ModelException
{
if(!inetDomain.editableBy(editor))
throw new ModelSecurityException();
 
inetDomain.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(inetDomain);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, InetDomain inetDomain)
throws ModelException
{
if(!inetDomain.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
 
HibernateUtil.currentSession().delete(inetDomain);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listInetDomains(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from InetDomain");
else
return HibernateUtil.currentSession().find(
"from InetDomain where owner=?", editor, Hibernate.entity(User.class));
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areInetDomainsAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return true;
else
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from InetDomain where owner=?",
editor, Hibernate.entity(User.class)).next()).intValue() > 0;
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
private static InetDomainManager inetDomainManager = null;
 
public static InetDomainManager getInstance()
{
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
1,67 → 1,67
package ak.hostcaptain.core.model;
 
/**
*
* @hibernate.class table="systemusers"
*/
public class SystemUser
extends GeneralModelObject
{
private Long id;
 
/** user id in the OS */
private Integer uid;
private String name;
package ak.hostcaptain.core.model;
 
/**
*
* @hibernate.class table="systemusers"
*/
public class SystemUser
extends GeneralModelObject
{
private Long id;
 
/** user id in the OS */
private Integer uid;
private String name;
private User owner;
 
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;
}
 
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.many-to-one
*/
public User getOwner()
74,33 → 74,33
this.owner = owner;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_SYSTEM_USER;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_SYSTEM_USER;
}
 
public Object[] getIdentParams()
{
return new Object[] { getName(), getUid() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || (owner == null) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser();
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser();
}
}
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_SYSTEM_USER;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_SYSTEM_USER;
}
 
public Object[] getIdentParams()
{
return new Object[] { getName(), getUid() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || (owner == null) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser();
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/GeneralModelObject.java
1,59 → 1,79
package ak.hostcaptain.core.model;
 
import java.util.Date;
 
public abstract class GeneralModelObject
implements ModelObject
{
private Boolean enabled;
private String comment;
private Date modStamp;
package ak.hostcaptain.core.model;
 
import java.util.Date;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public abstract class GeneralModelObject
implements ModelObject
{
private Boolean enabled;
private String comment;
private Date modStamp;
private User modUser;
 
/**
*
* @hibernate.property
*/
public Boolean getEnabled()
{
return enabled;
}
 
public void setEnabled(Boolean enabled)
{
this.enabled = enabled;
}
 
/**
*
* @hibernate.property
*/
public String getComment()
{
return comment;
}
 
public void setComment(String comment)
{
this.comment = comment;
}
 
/**
*
* @hibernate.timestamp column="mod_stamp"
*/
public Date getModStamp()
{
return modStamp;
}
 
protected void setModStamp(Date modStamp)
{
this.modStamp = modStamp;
}
 
 
/**
*
* @hibernate.property
*/
public Boolean getEnabled()
{
return enabled;
}
 
public void setEnabled(Boolean enabled)
{
this.enabled = enabled;
}
 
public void setEnabled(User editor, Boolean enabled)
throws ModelException
{
if(!editableBy(editor))
throw new ModelSecurityException();
 
this.enabled = enabled;
}
 
/**
*
* @hibernate.property
*/
public String getComment()
{
return comment;
}
 
public void setComment(String comment)
{
this.comment = comment;
}
 
public void setComment(User editor, String comment)
throws ModelException
{
if(!editableBy(editor))
throw new ModelSecurityException();
 
this.comment = comment;
}
 
/**
*
* @hibernate.timestamp column="mod_stamp"
*/
public Date getModStamp()
{
return modStamp;
}
 
protected void setModStamp(Date modStamp)
{
this.modStamp = modStamp;
}
 
/**
*
* @hibernate.many-to-one column="mod_user"
*/
public User getModUser()
65,4 → 85,4
{
this.modUser = modUser;
}
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailboxManager.java
1,203 → 1,203
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class MailboxManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailboxManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/hostcaptain/core/model/Mailbox.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailboxManager()
{
}
 
public Mailbox create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new Mailbox();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
 
public Mailbox get(User editor, Long id)
throws ModelException
{
Mailbox mailbox;
 
try {
mailbox = (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!mailbox.viewableBy(editor))
throw new ModelSecurityException();
 
return mailbox;
}
 
protected 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(User editor, Mailbox mailbox)
throws ModelException
{
if(!mailbox.editableBy(editor))
throw new ModelSecurityException();
 
mailbox.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailbox);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, Mailbox mailbox)
throws ModelException
{
if(!mailbox.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailbox);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailboxes(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from Mailbox");
else
return HibernateUtil.currentSession().find(
"select mb from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areMailboxesAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor))
{
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
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);
}
}
}
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class MailboxManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailboxManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/hostcaptain/core/model/Mailbox.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailboxManager()
{
}
 
public Mailbox create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new Mailbox();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
 
public Mailbox get(User editor, Long id)
throws ModelException
{
Mailbox mailbox;
 
try {
mailbox = (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!mailbox.viewableBy(editor))
throw new ModelSecurityException();
 
return mailbox;
}
 
protected 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(User editor, Mailbox mailbox)
throws ModelException
{
if(!mailbox.editableBy(editor))
throw new ModelSecurityException();
 
mailbox.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailbox);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, Mailbox mailbox)
throws ModelException
{
if(!mailbox.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailbox);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailboxes(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from Mailbox");
else
return HibernateUtil.currentSession().find(
"select mb from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areMailboxesAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor))
{
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
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
1,89 → 1,89
package ak.hostcaptain.core.model;
 
/**
*
* @hibernate.class table="domains"
*/
public class InetDomain
extends GeneralModelObject
{
private Long id;
private String name;
private User owner;
 
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;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_DOMAIN;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_DOMAIN;
}
 
public Object[] getIdentParams()
{
return new Object[] { getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser();
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser();
}
}
package ak.hostcaptain.core.model;
 
/**
*
* @hibernate.class table="domains"
*/
public class InetDomain
extends GeneralModelObject
{
private Long id;
private String name;
private User owner;
 
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;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_DOMAIN;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_DOMAIN;
}
 
public Object[] getIdentParams()
{
return new Object[] { getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser();
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser();
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasManager.java
1,205 → 1,205
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class MailAliasManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailAliasManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/hostcaptain/core/model/MailAlias.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailAliasManager()
{
}
 
public MailAlias create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
MailAlias alias = new MailAlias();
alias.setDestinations(new ArrayList());
return alias;
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
 
public MailAlias get(User editor, Long id)
throws ModelException
{
MailAlias alias;
 
try {
alias = (MailAlias)HibernateUtil.currentSession().load(MailAlias.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!alias.viewableBy(editor))
throw new ModelSecurityException();
 
return alias;
}
 
protected 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(User editor, MailAlias mailAlias)
throws ModelException
{
if(!mailAlias.editableBy(editor))
throw new ModelSecurityException();
 
mailAlias.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailAlias);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, MailAlias mailAlias)
throws ModelException
{
if(!mailAlias.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailAlias);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailAliases(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from MailAlias");
else
return HibernateUtil.currentSession().find(
"select a from MailAlias a left join a.domain as d"
+ " where d.owner=? or a.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areMailAliasesAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor))
{
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from MailAlias a left join a.domain as d"
+ " where d.owner=? or a.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
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);
}
}
}
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class MailAliasManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailAliasManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/hostcaptain/core/model/MailAlias.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailAliasManager()
{
}
 
public MailAlias create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
MailAlias alias = new MailAlias();
alias.setDestinations(new ArrayList());
return alias;
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
 
public MailAlias get(User editor, Long id)
throws ModelException
{
MailAlias alias;
 
try {
alias = (MailAlias)HibernateUtil.currentSession().load(MailAlias.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!alias.viewableBy(editor))
throw new ModelSecurityException();
 
return alias;
}
 
protected 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(User editor, MailAlias mailAlias)
throws ModelException
{
if(!mailAlias.editableBy(editor))
throw new ModelSecurityException();
 
mailAlias.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailAlias);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, MailAlias mailAlias)
throws ModelException
{
if(!mailAlias.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailAlias);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listMailAliases(User editor)
throws ModelException
{
try {
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from MailAlias");
else
return HibernateUtil.currentSession().find(
"select a from MailAlias a left join a.domain as d"
+ " where d.owner=? or a.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areMailAliasesAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor))
{
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from MailAlias a left join a.domain as d"
+ " where d.owner=? or a.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
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
1,16 → 1,16
package ak.hostcaptain.core.model;
 
public interface ModelObject
{
public String getTypeKey();
 
public String getIdentKey();
 
public Object[] getIdentParams();
 
public boolean viewableBy(User user);
 
public boolean editableBy(User user);
 
public boolean deleteableBy(User user);
}
package ak.hostcaptain.core.model;
 
public interface ModelObject
{
public String getTypeKey();
 
public String getIdentKey();
 
public Object[] getIdentParams();
 
public boolean viewableBy(User user);
 
public boolean editableBy(User user);
 
public boolean deleteableBy(User user);
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasDestinationManager.java
1,161 → 1,161
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
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/hostcaptain/core/model/MailAliasDestination.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailAliasDestinationManager()
{
}
 
public MailAliasDestination create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new MailAliasDestination();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return true;
}
 
public MailAliasDestination get(User editor, Long id)
throws ModelException
{
MailAliasDestination dest;
 
try {
dest = (MailAliasDestination)HibernateUtil.currentSession()
.load(MailAliasDestination.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!dest.viewableBy(editor))
throw new ModelSecurityException();
 
return dest;
}
 
public void save(User editor, MailAliasDestination mailAliasDestination)
throws ModelException
{
if(!mailAliasDestination.editableBy(editor))
throw new ModelSecurityException();
 
mailAliasDestination.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailAliasDestination);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, MailAliasDestination mailAliasDestination)
throws ModelException
{
if(!mailAliasDestination.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailAliasDestination);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
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);
}
}
 
public boolean areMailAliasesDestinationsAvailable(User editor)
throws ModelException
{
return true;
}
 
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);
}
}
}
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
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/hostcaptain/core/model/MailAliasDestination.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private MailAliasDestinationManager()
{
}
 
public MailAliasDestination create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new MailAliasDestination();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return true;
}
 
public MailAliasDestination get(User editor, Long id)
throws ModelException
{
MailAliasDestination dest;
 
try {
dest = (MailAliasDestination)HibernateUtil.currentSession()
.load(MailAliasDestination.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!dest.viewableBy(editor))
throw new ModelSecurityException();
 
return dest;
}
 
public void save(User editor, MailAliasDestination mailAliasDestination)
throws ModelException
{
if(!mailAliasDestination.editableBy(editor))
throw new ModelSecurityException();
 
mailAliasDestination.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailAliasDestination);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, MailAliasDestination mailAliasDestination)
throws ModelException
{
if(!mailAliasDestination.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailAliasDestination);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
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);
}
}
 
public boolean areMailAliasesDestinationsAvailable(User editor)
throws ModelException
{
return true;
}
 
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
1,220 → 1,220
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class UserManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailboxManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/hostcaptain/core/model/User.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private UserManager()
{
}
 
public User create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new User();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return User.allowedToCreate(this, editor);
}
 
public User get(User editor, Long id)
throws ModelException
{
User user;
 
try {
user = (User)HibernateUtil.currentSession().load(User.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!user.viewableBy(editor))
throw new ModelSecurityException();
 
return user;
}
 
public User findForLogin(String login)
throws ModelException
{
try {
List list = HibernateUtil.currentSession().find(
"from User where login=? and enabled='1'", 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 editor, User user)
throws ModelException
{
if(!user.editableBy(editor) && !user.mayChangePassword(editor)
&& !user.mayChangeSuperuser(editor))
{
throw new ModelSecurityException();
}
 
user.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(user);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, User user)
throws ModelException
{
if(!user.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(user);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listUsers(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()) {
return HibernateUtil.currentSession().find("from User");
}
else {
return HibernateUtil.currentSession().find(
"from User u where u = ? or u.boss = ?",
new Object[] { editor, editor},
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areSystemUsersAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()) {
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"from User u where u = ? or u.boss = ?",
new Object[] { editor, editor},
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } )
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public User loginUser(String login, String password)
throws ModelException
{
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);
}
}
}
package ak.hostcaptain.core.model;
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class UserManager
{
private static boolean registered = false;
protected static void register()
{
synchronized(MailboxManager.class) {
if(registered) return;
 
registered = true;
try {
HibernateUtil.getConfiguration().addResource(
"/ak/hostcaptain/core/model/User.hbm.xml");
}
catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
}
 
static {
register();
}
 
private UserManager()
{
}
 
public User create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new User();
}
 
public boolean allowedToCreate(User editor)
throws ModelException
{
return User.allowedToCreate(this, editor);
}
 
public User get(User editor, Long id)
throws ModelException
{
User user;
 
try {
user = (User)HibernateUtil.currentSession().load(User.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!user.viewableBy(editor))
throw new ModelSecurityException();
 
return user;
}
 
public User findForLogin(String login)
throws ModelException
{
try {
List list = HibernateUtil.currentSession().find(
"from User where login=? and enabled='1'", 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 editor, User user)
throws ModelException
{
if(!user.editableBy(editor) && !user.mayChangePassword(editor)
&& !user.mayChangeSuperuser(editor))
{
throw new ModelSecurityException();
}
 
user.setModUser(editor);
 
try {
HibernateUtil.currentSession().saveOrUpdate(user);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public void delete(User editor, User user)
throws ModelException
{
if(!user.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(user);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public Collection listUsers(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()) {
return HibernateUtil.currentSession().find("from User");
}
else {
return HibernateUtil.currentSession().find(
"from User u where u = ? or u.boss = ?",
new Object[] { editor, editor},
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public boolean areSystemUsersAvailable(User editor)
throws ModelException
{
try {
if(editor.isSuperuser()) {
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"from User u where u = ? or u.boss = ?",
new Object[] { editor, editor},
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } )
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public User loginUser(String login, String password)
throws ModelException
{
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/model/Mailbox.java
1,174 → 1,174
package ak.hostcaptain.core.model;
 
import ak.hostcaptain.util.Digest;
 
/**
*
* @hibernate.class table="mailboxes"
*/
public class Mailbox
extends GeneralModelObject
{
private Long id;
private String login;
private String password;
private InetDomain domain;
private User owner;
private Boolean virusCheck;
private Boolean spamCheck;
private SystemUser systemUser;
 
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");
 
package ak.hostcaptain.core.model;
 
import ak.hostcaptain.util.Digest;
 
/**
*
* @hibernate.class table="mailboxes"
*/
public class Mailbox
extends GeneralModelObject
{
private Long id;
private String login;
private String password;
private InetDomain domain;
private User owner;
private Boolean virusCheck;
private Boolean spamCheck;
private SystemUser systemUser;
 
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;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_MAILBOX;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_MAILBOX;
}
 
public Object[] getIdentParams()
{
return new Object[] { getLogin(), getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
}
}
 
/**
*
* @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;
}
 
public String getTypeKey()
{
return ak.hostcaptain.core.CoreResources.TYPE_MAILBOX;
}
 
public String getIdentKey()
{
return ak.hostcaptain.core.CoreResources.IDENT_MAILBOX;
}
 
public Object[] getIdentParams()
{
return new Object[] { getLogin(), getDomain().getName() };
}
 
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
}
 
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
 
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/MethodTagBase.java
1,63 → 1,63
package ak.hostcaptain.core.taglib;
 
import java.lang.reflect.Method;
import javax.servlet.jsp.JspException;
 
import ak.hostcaptain.core.model.User;
import org.apache.struts.util.RequestUtils;
 
public abstract class MethodTagBase
extends RightTagBase
{
protected String method;
 
public String getMethod()
{
return method;
}
 
public void setMethod(String method)
{
this.method = method;
}
 
public void release()
{
super.release();
method = null;
}
 
protected boolean condition()
throws JspException
{
Method m;
Object value;
 
// find method
try {
m = object.getClass().getMethod(method, new Class[] { User.class } );
}
catch(NoSuchMethodException ex) {
throw new JspException("Method " + method
+ " with parameter of type user not found");
}
 
// invoke it
try {
value = m.invoke(object, new Object[] { user } );
}
catch(Exception ex) {
throw new JspException("Cannot call " + method + ": " + ex.getMessage());
}
 
// check value type
if(!(value instanceof Boolean))
throw new JspException("Return type of method " + method
+ " must be java.lang.Boolean");
 
return condition(((Boolean)value).booleanValue());
}
 
protected abstract boolean condition(boolean value)
throws JspException;
}
package ak.hostcaptain.core.taglib;
 
import java.lang.reflect.Method;
import javax.servlet.jsp.JspException;
 
import ak.hostcaptain.core.model.User;
import org.apache.struts.util.RequestUtils;
 
public abstract class MethodTagBase
extends RightTagBase
{
protected String method;
 
public String getMethod()
{
return method;
}
 
public void setMethod(String method)
{
this.method = method;
}
 
public void release()
{
super.release();
method = null;
}
 
protected boolean condition()
throws JspException
{
Method m;
Object value;
 
// find method
try {
m = object.getClass().getMethod(method, new Class[] { User.class } );
}
catch(NoSuchMethodException ex) {
throw new JspException("Method " + method
+ " with parameter of type user not found");
}
 
// invoke it
try {
value = m.invoke(object, new Object[] { user } );
}
catch(Exception ex) {
throw new JspException("Cannot call " + method + ": " + ex.getMessage());
}
 
// check value type
if(!(value instanceof Boolean))
throw new JspException("Return type of method " + method
+ " must be java.lang.Boolean");
 
return condition(((Boolean)value).booleanValue());
}
 
protected abstract boolean condition(boolean value)
throws JspException;
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/NoRightsTag.java
1,15 → 1,15
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
import org.apache.struts.util.RequestUtils;
 
public class NoRightsTag
extends MethodTagBase
{
protected boolean condition(boolean value)
throws JspException
{
return !value;
}
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
import org.apache.struts.util.RequestUtils;
 
public class NoRightsTag
extends MethodTagBase
{
protected boolean condition(boolean value)
throws JspException
{
return !value;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/ViewableTag.java
1,13 → 1,13
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class ViewableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.viewableBy(user);
}
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class ViewableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.viewableBy(user);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/NotViewableTag.java
1,13 → 1,13
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class NotViewableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.viewableBy(user);
}
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class NotViewableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.viewableBy(user);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/RightsTag.java
1,15 → 1,15
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
import org.apache.struts.util.RequestUtils;
 
public class RightsTag
extends MethodTagBase
{
protected boolean condition(boolean value)
throws JspException
{
return value;
}
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
import org.apache.struts.util.RequestUtils;
 
public class RightsTag
extends MethodTagBase
{
protected boolean condition(boolean value)
throws JspException
{
return value;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/ModelObjectOptionsTag.java
1,71 → 1,71
// based on jakarta struts taglib
package ak.hostcaptain.core.taglib;
 
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
 
import javax.servlet.jsp.JspException;
 
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.taglib.html.Constants;
import org.apache.struts.taglib.html.SelectTag;
import org.apache.struts.taglib.html.OptionsTag;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.ResponseUtils;
 
import ak.hostcaptain.core.model.ModelObject;
 
public class ModelObjectOptionsTag extends OptionsTag
{
protected static MessageResources coreMessages =
MessageResources.getMessageResources("ak.hostcaptain.core.CoreResources");
 
public int doEndTag() throws JspException
{
SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
if (selectTag == null) {
throw new JspException(messages.getMessage("optionsTag.select"));
}
StringBuffer sb = new StringBuffer();
 
if (collection != null) {
Iterator collIterator = getIterator(collection, null);
while (collIterator.hasNext()) {
Object bean = collIterator.next();
Object value = null;
 
if(!(bean instanceof ModelObject))
throw new JspException("Not a ModelObject");
 
ModelObject model = (ModelObject)bean;
 
try {
value = PropertyUtils.getProperty(bean, property);
if (value == null) {
value = "";
}
} catch (IllegalAccessException e) {
throw new JspException(
messages.getMessage("getter.access", property, collection));
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
throw new JspException(
messages.getMessage("getter.result", property, t.toString()));
} catch (NoSuchMethodException e) {
throw new JspException(
messages.getMessage("getter.method", property, collection));
}
 
String identKey = model.getIdentKey();
Object[] identParams = model.getIdentParams();
String label = coreMessages.getMessage(identKey, identParams);
String stringValue = value.toString();
 
addOption(sb, stringValue, label, selectTag.isMatched(stringValue));
}
}
 
ResponseUtils.write(pageContext, sb.toString());
return EVAL_PAGE;
}
}
// based on jakarta struts taglib
package ak.hostcaptain.core.taglib;
 
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
 
import javax.servlet.jsp.JspException;
 
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.taglib.html.Constants;
import org.apache.struts.taglib.html.SelectTag;
import org.apache.struts.taglib.html.OptionsTag;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.ResponseUtils;
 
import ak.hostcaptain.core.model.ModelObject;
 
public class ModelObjectOptionsTag extends OptionsTag
{
protected static MessageResources coreMessages =
MessageResources.getMessageResources("ak.hostcaptain.core.CoreResources");
 
public int doEndTag() throws JspException
{
SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
if (selectTag == null) {
throw new JspException(messages.getMessage("optionsTag.select"));
}
StringBuffer sb = new StringBuffer();
 
if (collection != null) {
Iterator collIterator = getIterator(collection, null);
while (collIterator.hasNext()) {
Object bean = collIterator.next();
Object value = null;
 
if(!(bean instanceof ModelObject))
throw new JspException("Not a ModelObject");
 
ModelObject model = (ModelObject)bean;
 
try {
value = PropertyUtils.getProperty(bean, property);
if (value == null) {
value = "";
}
} catch (IllegalAccessException e) {
throw new JspException(
messages.getMessage("getter.access", property, collection));
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
throw new JspException(
messages.getMessage("getter.result", property, t.toString()));
} catch (NoSuchMethodException e) {
throw new JspException(
messages.getMessage("getter.method", property, collection));
}
 
String identKey = model.getIdentKey();
Object[] identParams = model.getIdentParams();
String label = coreMessages.getMessage(identKey, identParams);
String stringValue = value.toString();
 
addOption(sb, stringValue, label, selectTag.isMatched(stringValue));
}
}
 
ResponseUtils.write(pageContext, sb.toString());
return EVAL_PAGE;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/DeleteableTag.java
1,13 → 1,13
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class DeleteableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.deleteableBy(user);
}
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class DeleteableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.deleteableBy(user);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/NotDeleteableTag.java
1,13 → 1,13
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class NotDeleteableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.deleteableBy(user);
}
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class NotDeleteableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.deleteableBy(user);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/RightTagBase.java
1,64 → 1,64
package ak.hostcaptain.core.taglib;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
 
import org.apache.struts.util.RequestUtils;
 
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.ModelObject;
 
public abstract class RightTagBase
extends TagSupport
{
protected User user;
protected ModelObject object;
 
protected String name;
 
public String getName()
{
return name;
}
 
public void setName(String name)
{
this.name = name;
}
 
public void release()
{
super.release();
name = null;
user = null;
}
 
public int doStartTag()
throws JspException
{
user = (User)RequestUtils.lookup(pageContext, "user", "session");
 
Object obj = RequestUtils.lookup(pageContext, name, null);
if(obj == null)
throw new JspException(name + " is null");
if(!(obj instanceof ModelObject))
throw new JspException(name + " must be a ModelObject, but is " + obj.getClass());
 
object = (ModelObject)obj;
 
if(condition())
return EVAL_BODY_INCLUDE;
else
return SKIP_BODY;
}
 
public int doEndTag()
throws JspException
{
return EVAL_PAGE;
}
 
protected abstract boolean condition()
throws JspException;
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
 
import org.apache.struts.util.RequestUtils;
 
import ak.hostcaptain.core.model.User;
import ak.hostcaptain.core.model.ModelObject;
 
public abstract class RightTagBase
extends TagSupport
{
protected User user;
protected ModelObject object;
 
protected String name;
 
public String getName()
{
return name;
}
 
public void setName(String name)
{
this.name = name;
}
 
public void release()
{
super.release();
name = null;
user = null;
}
 
public int doStartTag()
throws JspException
{
user = (User)RequestUtils.lookup(pageContext, "user", "session");
 
Object obj = RequestUtils.lookup(pageContext, name, null);
if(obj == null)
throw new JspException(name + " is null");
if(!(obj instanceof ModelObject))
throw new JspException(name + " must be a ModelObject, but is " + obj.getClass());
 
object = (ModelObject)obj;
 
if(condition())
return EVAL_BODY_INCLUDE;
else
return SKIP_BODY;
}
 
public int doEndTag()
throws JspException
{
return EVAL_PAGE;
}
 
protected abstract boolean condition()
throws JspException;
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/EditableTag.java
1,13 → 1,13
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class EditableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.editableBy(user);
}
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class EditableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.editableBy(user);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/NotEditableTag.java
1,13 → 1,13
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class NotEditableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.editableBy(user);
}
}
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
 
public class NotEditableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.editableBy(user);
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/taglib/WriteTag.java
1,50 → 1,50
// based on struts write tag
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;
 
public class WriteTag
extends org.apache.struts.taglib.bean.WriteTag
{
protected String defValue;
 
public String getDefault()
{
return defValue;
}
 
public void setDefault(String defValue)
{
this.defValue = defValue;
}
 
public int doStartTag()
throws JspException
{
Object value;
 
if(ignore && RequestUtils.lookup(pageContext, name, scope) == null)
value = null;
else
value = RequestUtils.lookup(pageContext, name, property, scope);
 
if(value == null) value = defValue;
 
if(value != null) {
if(filter)
ResponseUtils.write(pageContext, ResponseUtils.filter(formatValue(value)));
else
ResponseUtils.write(pageContext, formatValue(value));
}
 
return SKIP_BODY;
}
 
public void release()
{
super.release();
defValue = null;
}
}
// based on struts write tag
package ak.hostcaptain.core.taglib;
 
import javax.servlet.jsp.JspException;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;
 
public class WriteTag
extends org.apache.struts.taglib.bean.WriteTag
{
protected String defValue;
 
public String getDefault()
{
return defValue;
}
 
public void setDefault(String defValue)
{
this.defValue = defValue;
}
 
public int doStartTag()
throws JspException
{
Object value;
 
if(ignore && RequestUtils.lookup(pageContext, name, scope) == null)
value = null;
else
value = RequestUtils.lookup(pageContext, name, property, scope);
 
if(value == null) value = defValue;
 
if(value != null) {
if(filter)
ResponseUtils.write(pageContext, ResponseUtils.filter(formatValue(value)));
else
ResponseUtils.write(pageContext, formatValue(value));
}
 
return SKIP_BODY;
}
 
public void release()
{
super.release();
defValue = null;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/CoreResources.java
1,28 → 1,28
package ak.hostcaptain.core;
 
public abstract class CoreResources
{
public static final String LOGIN_FAILED = "ak.hostcaptain.core.login.failed";
public static final String OLD_PASSWORD_WRONG = "ak.hostcaptain.core.oldpassword.wrong";
public static final String DELETE_ME_SELF = "ak.hostcaptain.core.user.deletemeself";
public static final String PASSWORD_REQUIRED = "ak.hostcaptain.core.password.required";
public static final String PASSWORDS_DONT_MATCH = "ak.hostcaptain.core.password.dontMatch";
 
public static final String TYPE_USER = "ak.hostcaptain.core.type.user";
public static final String TYPE_SYSTEM_USER = "ak.hostcaptain.core.type.systemUser";
public static final String TYPE_DOMAIN = "ak.hostcaptain.core.type.domain";
public static final String TYPE_MAILBOX = "ak.hostcaptain.core.type.mailbox";
public static final String TYPE_MAIL_ALIAS = "ak.hostcaptain.core.type.mailAlias";
public static final String TYPE_MAIL_ALIAS_DESTINATION
= "ak.hostcaptain.core.type.mailAliasDestination";
 
public static final String IDENT_USER = "ak.hostcaptain.core.ident.user";
public static final String IDENT_SYSTEM_USER = "ak.hostcaptain.core.ident.systemUser";
public static final String IDENT_DOMAIN = "ak.hostcaptain.core.ident.domain";
public static final String IDENT_MAILBOX = "ak.hostcaptain.core.ident.mailbox";
public static final String IDENT_MAIL_ALIAS = "ak.hostcaptain.core.ident.mailAlias";
public static final String IDENT_MAIL_ALIAS_DESTINATION_EXTERNAL
= "ak.hostcaptain.core.ident.mailAliasDestination.external";
public static final String IDENT_MAIL_ALIAS_DESTINATION_INTERNAL
= "ak.hostcaptain.core.ident.mailAliasDestination.internal";
}
package ak.hostcaptain.core;
 
public abstract class CoreResources
{
public static final String LOGIN_FAILED = "ak.hostcaptain.core.login.failed";
public static final String OLD_PASSWORD_WRONG = "ak.hostcaptain.core.oldpassword.wrong";
public static final String DELETE_ME_SELF = "ak.hostcaptain.core.user.deletemeself";
public static final String PASSWORD_REQUIRED = "ak.hostcaptain.core.password.required";
public static final String PASSWORDS_DONT_MATCH = "ak.hostcaptain.core.password.dontMatch";
 
public static final String TYPE_USER = "ak.hostcaptain.core.type.user";
public static final String TYPE_SYSTEM_USER = "ak.hostcaptain.core.type.systemUser";
public static final String TYPE_DOMAIN = "ak.hostcaptain.core.type.domain";
public static final String TYPE_MAILBOX = "ak.hostcaptain.core.type.mailbox";
public static final String TYPE_MAIL_ALIAS = "ak.hostcaptain.core.type.mailAlias";
public static final String TYPE_MAIL_ALIAS_DESTINATION
= "ak.hostcaptain.core.type.mailAliasDestination";
 
public static final String IDENT_USER = "ak.hostcaptain.core.ident.user";
public static final String IDENT_SYSTEM_USER = "ak.hostcaptain.core.ident.systemUser";
public static final String IDENT_DOMAIN = "ak.hostcaptain.core.ident.domain";
public static final String IDENT_MAILBOX = "ak.hostcaptain.core.ident.mailbox";
public static final String IDENT_MAIL_ALIAS = "ak.hostcaptain.core.ident.mailAlias";
public static final String IDENT_MAIL_ALIAS_DESTINATION_EXTERNAL
= "ak.hostcaptain.core.ident.mailAliasDestination.external";
public static final String IDENT_MAIL_ALIAS_DESTINATION_INTERNAL
= "ak.hostcaptain.core.ident.mailAliasDestination.internal";
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/form/MailAliasDestBean.java
1,77 → 1,77
package ak.hostcaptain.core.form;
 
import ak.hostcaptain.util.StringConverter;
import ak.hostcaptain.core.model.MailAliasDestination;
 
public final class MailAliasDestBean
{
private String id;
private String mailbox;
private String email;
private Boolean enabled;
private String comment;
 
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();
this.enabled = dest.getEnabled();
this.comment = dest.getComment();
}
 
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;
}
 
public Boolean getEnabled()
{
return enabled;
}
 
public void setEnabled(Boolean enabled)
{
this.enabled = enabled;
}
 
public String getComment()
{
return comment;
}
 
public void setComment(String comment)
{
this.comment = comment;
}
}
package ak.hostcaptain.core.form;
 
import ak.hostcaptain.util.StringConverter;
import ak.hostcaptain.core.model.MailAliasDestination;
 
public final class MailAliasDestBean
{
private String id;
private String mailbox;
private String email;
private Boolean enabled;
private String comment;
 
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();
this.enabled = dest.getEnabled();
this.comment = dest.getComment();
}
 
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;
}
 
public Boolean getEnabled()
{
return enabled;
}
 
public void setEnabled(Boolean enabled)
{
this.enabled = enabled;
}
 
public String getComment()
{
return comment;
}
 
public void setComment(String comment)
{
this.comment = comment;
}
}
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/form/UserPasswordForm.java
1,30 → 1,30
package ak.hostcaptain.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.hostcaptain.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;
}
}
package ak.hostcaptain.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.hostcaptain.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/LoginFilter.java
1,169 → 1,169
package ak.hostcaptain.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.hostcaptain.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()
{
}
}
package ak.hostcaptain.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.hostcaptain.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
1,106 → 1,106
package ak.hostcaptain.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.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.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()
{
}
}
package ak.hostcaptain.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.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.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/core/servlet/EncodingFilter.java
1,37 → 1,37
package ak.hostcaptain.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()
{
}
}
package ak.hostcaptain.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()
{
}
}