From dbef80b91f9f8d64b4ac3b447f2b6b3a57264f54 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 13 Nov 2012 12:20:13 +0100 Subject: [PATCH] fix: set default options for compatibility, allow update on pac-domain --- .../de/hsadmin/mods/dom/DomainModuleImpl.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java index 0b82220..01511e1 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java @@ -19,6 +19,18 @@ import de.hsadmin.mods.user.UnixUser; public class DomainModuleImpl extends AbstractModuleImpl { + public static final String DOMOPT_GREYLISTING = "greylisting"; + public static final String DOMOPT_MULTIVIEWS = "multiviews"; + public static final String DOMOPT_INDEXES = "indexes"; + public static final String DOMOPT_HTDOCSFALLBACK = "htdocsfallback"; + public static final String DOMOPT_INCLUDES = "includes"; + public static final String DOMOPT_BACKUPFOREXTERNALMX = "backupmxforexternalmx"; + + public static final String[] ALL_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMOPT_MULTIVIEWS, + DOMOPT_INDEXES, DOMOPT_HTDOCSFALLBACK, DOMOPT_INCLUDES, DOMOPT_BACKUPFOREXTERNALMX }; + public static final String[] DEFAULT_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMOPT_MULTIVIEWS, + DOMOPT_INDEXES, DOMOPT_HTDOCSFALLBACK, DOMOPT_INCLUDES }; + @Override public AbstractEntity initialize(AbstractEntity newEntity) throws AuthorisationException { AbstractEntity newDom = super.initialize(newEntity); @@ -123,16 +135,18 @@ public class DomainModuleImpl extends AbstractModuleImpl { dom.setUser((UnixUser) adminQuery.getSingleResult()); needsWriteAccessOn(newEntity, "add"); em.persist(dom); - Query q = em.createQuery("SELECT opt FROM " + - DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() + - " opt WHERE opt.name=:optName"); HashSet domainOptions = new HashSet(); - q.setParameter("optName", "greylisting"); - List list = q.getResultList(); - if (list.size() != 1) { - throw new HSAdminException("invalid domain option: " + "greylisting"); - } else { - domainOptions.add((DomainOption) list.get(0)); + for (String domOpt : DEFAULT_DOMOPTS) { + Query q = em.createQuery("SELECT opt FROM " + + DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() + + " opt WHERE opt.name=:optName"); + q.setParameter("optName", domOpt); + List list = q.getResultList(); + if (list.size() == 1) { + domainOptions.add((DomainOption) list.get(0)); + } else { + throw new HSAdminException("invalid domain option: " + domOpt); + } } dom.setDomainoptions(domainOptions); if (dom.isPacDomain()) { @@ -234,8 +248,10 @@ public class DomainModuleImpl extends AbstractModuleImpl { if (dom.isPacDomain() && !dom.getUser().getName().equals(domPac.getName())) { throw new AuthorisationException(loginUser, method, dom); } - if (dom.isPacDomain() && !isHostmaster && !"add".equals(method)) { - throw new AuthorisationException(loginUser, method, dom); + if (dom.isPacDomain() && !isHostmaster) { + if (!"add".equals(method) && !"update".equals(method)) { + throw new AuthorisationException(loginUser, method, dom); + } } } else { throw new AuthorisationException(loginUser, method, entity);