Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1043 → Rev 1044

/hostadmiral/trunk/webapp/accessDenied.jsp
0,0 → 1,33
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/ak-backpath.tld" prefix="backpath" %>
<%@ taglib uri="/WEB-INF/ak-strutsx.tld" prefix="strutsx" %>
<%@ taglib uri="/WEB-INF/hostadmiral-core.tld" prefix="core" %>
<html>
 
<head>
<meta http-equiv="expires" content="0">
<title><bean:message key="ak.hostadmiral.page.accessDenied.title" /></title>
<link rel="stylesheet" type="text/css" href="<strutsx:root />/style/general.css">
</head>
 
<body>
 
<h1><bean:message key="ak.hostadmiral.page.accessDenied.title" /></h1>
 
<p><bean:message key="ak.hostadmiral.page.accessDenied.message" /></p>
 
<html:link path="/"><bean:message key="ak.hostadmiral.page.accessDenied.index" /></html:link>
<br>
<backpath:backlink><bean:message key="ak.hostadmiral.page.accessDenied.back" /></backpath:backlink>
 
<p>
<bean:message key="ak.hostadmiral.page.general.version" />:
<bean:write name="projectVersion" />
</p>
 
</body>
 
</html>
/hostadmiral/trunk/webapp/WEB-INF/struts-config.xml
168,9 → 168,9
/ -->
 
<exception
key="UserException"
type="ak.hostadmiral.util.UserException"
handler="ak.hostadmiral.core.action.UserExceptionHandler"
key="GeneralException"
type="java.lang.Exception"
handler="ak.hostadmiral.core.action.GeneralExceptionHandler"
/>
</global-exceptions>
 
179,6 → 179,16
name="error"
path="/error.jsp"
/>
 
<forward
name="accessDenied"
path="/accessDenied.jsp"
/>
 
<forward
name="generalError"
path="/generalError.jsp"
/>
</global-forwards>
 
<action-mappings>
/hostadmiral/trunk/webapp/generalError.jsp
19,11 → 19,11
 
<p><bean:message key="ak.hostadmiral.page.generalError.message" /></p>
 
<!-- FIXME: backpath:link><bean:message key="ak.hostadmiral.page.generalError.index" /></ backpath : link-->
<html:link path="/"><bean:message key="ak.hostadmiral.page.generalError.index" /></html:link>
<br>
<backpath:backlink><bean:message key="ak.hostadmiral.page.generalError.back" /></backpath:backlink>
 
<p>
<p>
<bean:message key="ak.hostadmiral.page.general.version" />:
<bean:write name="projectVersion" />
</p>
/hostadmiral/trunk/src/ak/hostadmiral/core/action/UserExceptionHandler.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/action/GeneralExceptionHandler.java
0,0 → 1,127
package ak.hostadmiral.core.action;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.struts.Globals;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.config.ExceptionConfig;
 
import org.apache.log4j.Logger;
 
import ak.strutsx.ErrorHandlerX;
 
import ak.hostadmiral.util.UserException;
import ak.hostadmiral.util.ModelUserException;
import ak.hostadmiral.util.ModelSecurityException;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.FormException;
 
public final class GeneralExceptionHandler
extends ExceptionHandler
{
private static final Logger logger = Logger.getLogger(GeneralExceptionHandler.class);
 
public ActionForward execute(Exception ex, ExceptionConfig config,
ActionMapping mapping, ActionForm formInstance,
HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
if(ex instanceof UserException) {
return handleUserException((UserException)ex,
config, mapping, formInstance, request, response);
}
else if(ex instanceof ModelUserException) {
return handleModelUserException((ModelUserException)ex,
config, mapping, formInstance, request, response);
}
else if(ex instanceof ModelSecurityException) {
logger.error("security exception", ex);
Exception subex = ((ModelSecurityException)ex).getChainedException();
if(subex != null && subex instanceof ModelException)
logChainedException((ModelSecurityException)subex);
 
return mapping.findForward("accessDenied");
}
else if(ex instanceof ModelException) {
logger.error("model exception", ex);
Exception subex = ((ModelException)ex).getChainedException();
if(subex != null && subex instanceof ModelException)
logChainedException((ModelException)subex);
 
return mapping.findForward("generalError");
}
else {
logger.error("unhandled exception", ex);
return mapping.findForward("generalError");
}
}
 
protected void logChainedException(ModelException ex)
{
logger.error("chained exception", ex);
 
Exception subex = ex.getChainedException();
if(subex != null && subex instanceof ModelException)
logChainedException((ModelException)subex);
}
 
protected ActionForward handleUserException(UserException ex, ExceptionConfig config,
ActionMapping mapping, ActionForm formInstance,
HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
logger.info("user exception handle:" + ex.getMessage());
 
// try to get property for this exception if any
String property = ActionMessages.GLOBAL_MESSAGE;
if(ex instanceof FormException) {
FormException formEx = (FormException)ex;
if(formEx.getProperty() != null)
property = formEx.getProperty();
}
 
// create new error message
ActionErrors errors = (ActionErrors)request.getAttribute(Globals.ERROR_KEY);
if(errors == null) {
errors = new ActionErrors();
request.setAttribute(Globals.ERROR_KEY, errors);
}
errors.add(property, new ActionError(ex.getMessage(), ex.getValues()));
 
// find forward
if(mapping.getInput() == null)
return mapping.findForward("error");
else
return mapping.getInputForward();
}
 
protected ActionForward handleModelUserException(ModelUserException ex, ExceptionConfig config,
ActionMapping mapping, ActionForm formInstance,
HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
logger.info("model user exception handle:" + ex.getMessage());
 
// create new error message
ActionErrors errors = (ActionErrors)request.getAttribute(Globals.ERROR_KEY);
if(errors == null) {
errors = new ActionErrors();
request.setAttribute(Globals.ERROR_KEY, errors);
}
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionError(ex.getMessage(), ex.getValues()));
 
// find forward
if(mapping.getInput() == null)
return mapping.findForward("error");
else
return mapping.getInputForward();
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/CoreResources.properties
69,6 → 69,11
ak.hostadmiral.page.generalError.index=start page
ak.hostadmiral.page.generalError.back=back
 
ak.hostadmiral.page.accessDenied.title=Host Admiral - access denied
ak.hostadmiral.page.accessDenied.message=You have no permission to execute requested action.
ak.hostadmiral.page.accessDenied.index=start page
ak.hostadmiral.page.accessDenied.back=back
 
ak.hostadmiral.page.index.title=Host Admiral
ak.hostadmiral.page.index.password_change=change password
ak.hostadmiral.page.index.user_list=users
348,4 → 353,6
ak.hostadmiral.page.mail.alias.view.external=external redirect
ak.hostadmiral.page.mail.alias.view.back=back
 
ak.hostadmiral.core.uservalidator.atdomain.login.wrong=User login must end with name of your domain, e.g. me@example.com
 
org.apache.struts.taglib.bean.format.sql.timestamp=dd-MM-yyyy HH:mm:ss.SSS
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserValidator.java
0,0 → 1,9
package ak.hostadmiral.core.model;
 
import ak.hostadmiral.util.ModelException;
 
public interface UserValidator
{
public void validateUser(User editor, User user)
throws ModelException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserValidatorAtDomain.java
0,0 → 1,26
package ak.hostadmiral.core.model;
 
import java.util.Collection;
import java.util.Iterator;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.ModelUserException;
 
public class UserValidatorAtDomain
implements UserValidator
{
public void validateUser(User editor, User user)
throws ModelException
{
if(editor.isSuperuser()) return;
 
Collection domains = InetDomainManager.getInstance().listInetDomains(editor);
for(Iterator i = domains.iterator(); i.hasNext(); ) {
InetDomain domain = (InetDomain)i.next();
 
if(user.getLogin().endsWith("@" + domain.getName()))
return;
}
 
throw new ModelUserException("ak.hostadmiral.core.uservalidator.atdomain.login.wrong");
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/model/UserManager.java
20,7 → 20,8
UserBeforeDeleteListener,
UserDeletingListener
{
private UserStore store;
private UserStore store;
private UserValidator userValidator;
 
private Collection createdListeners = new ArrayList();
private Collection modifiedListeners = new ArrayList();
99,6 → 100,9
throw new ModelSecurityException();
}
 
if(userValidator != null)
userValidator.validateUser(editor, user);
 
boolean isNew = user.isNew();
 
//user.setModUser(editor); // FIXME: disabled because hb throws exception
375,6 → 379,12
 
Class c = Class.forName((String)params.get("store"));
store = (UserStore)c.newInstance();
 
String userValidatorName = (String)params.get("userValidator");
if(userValidatorName != null) {
Class c2 = Class.forName(userValidatorName);
userValidator = (UserValidator)c2.newInstance();
}
}
catch(Exception ex) {
throw new ModelException(ex);
/hostadmiral/trunk/src/ak/hostadmiral/core/model/store/hibernate/MailboxHibernate.java
193,12 → 193,18
throws ModelStoreException
{
try {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { user, user },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue();
List countlist = HibernateUtil.sqlQuery(
"select count(*) from ("
+ " select mb.id from mailboxes mb"
+ " where mb.owner=?"
+ " union"
+ " select mb.id from mailboxes mb"
+ " left join domains as d on mb.domain = d.id"
+ " where d.owner=?"
+ ") as count_table",
new Object[] { user.getId(), user.getId() });
 
return ((Long)countlist.get(0)).intValue();
}
catch(HibernateException ex)
{
/hostadmiral/trunk/src/ak/hostadmiral/core/model/store/hibernate/MailAliasHibernate.java
178,12 → 178,18
throws ModelStoreException
{
try {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from MailAlias a left join a.domain as d"
+ " where d.owner=? or a.owner=?",
new Object[] { user, user },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue();
List countlist = HibernateUtil.sqlQuery(
"select count(*) from ("
+ " select a.id from mailaliases a"
+ " where a.owner=?"
+ " union"
+ " select a.id from mailaliases a"
+ " left join domains as d on a.domain = d.id"
+ " where d.owner=?"
+ ") as count_table",
new Object[] { user.getId(), user.getId() });
 
return ((Long)countlist.get(0)).intValue();
}
catch(HibernateException ex)
{
/hostadmiral/trunk/src/ak/hostadmiral/util/ModelUserException.java
0,0 → 1,28
package ak.hostadmiral.util;
 
public class ModelUserException
extends ModelException
{
private Object[] values;
 
public ModelUserException()
{
this(null, null);
}
 
public ModelUserException(String message)
{
this(message, null);
}
 
public ModelUserException(String message, Object[] values)
{
super(message);
this.values = values;
}
 
public Object[] getValues()
{
return values;
}
}