From 953f0320d252b39a984488154fbc23e62a271189 Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Fri, 12 Apr 2013 12:56:53 +0200 Subject: [PATCH] Exit pac processor factory when processing "unknown" pac types. Renamed DW/B and SW/B to PAC/DB and PAC/SW. Introduced new pac type PAC/WEB. Fixed tests. --- hsarback/src/de/hsadmin/mods/dom/Domain.java | 9 ++++++ .../mods/dom/DomainProcessorFactory.java | 11 +++---- .../src/de/hsadmin/mods/dom/httpd-vhost.vm | 6 ++-- hsarback/src/de/hsadmin/mods/pac/Pac.java | 4 --- .../hsadmin/mods/pac/PacProcessorFactory.java | 32 +++++++++++++------ .../src/de/hsadmin/remote/RoleRemote.java | 6 +--- .../de/hsadmin/processor/PacProcessor.java | 2 +- .../test/de/hsadmin/remote/InitDataTest.java | 2 +- .../hsadmin/remote/LongCustomerNameTest.java | 6 ++-- hsarback/test/de/hsadmin/remote/PacTest.java | 6 ++-- .../test/de/hsadmin/remote/RemoteTest.java | 2 +- hsarback/test/de/hsadmin/remote/RoleTest.java | 2 +- .../de/hsadmin/remote/SSLCertDomainTest.java | 2 +- 13 files changed, 51 insertions(+), 39 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/Domain.java b/hsarback/src/de/hsadmin/mods/dom/Domain.java index c84f734..083bbe4 100644 --- a/hsarback/src/de/hsadmin/mods/dom/Domain.java +++ b/hsarback/src/de/hsadmin/mods/dom/Domain.java @@ -180,4 +180,13 @@ public class Domain extends AbstractEntity { this.domainoptions = domainOptions; } + public boolean isDynamic() { + String pacType = getUser().getPac().getBasepac().getName(); + return isPacDomain() || (pacType == "PAC/WEB") || (pacType == "PAC/DW"); + } + + public boolean isStatic() { + return !isDynamic(); + } + } diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 8b92cf5..01d2f21 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -25,12 +25,12 @@ import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.user.UnixUser; public class DomainProcessorFactory implements EntityProcessorFactory { - - private static final String[] DW_STRUCTURE = new String[] { + + private static final String[] DYNAMIC_STRUCTURE = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "cgi", "fastcgi", "cgi-ssl", "fastcgi-ssl", "etc", "var" }; - private static final String[] SW_STRUCTURE = new String[] { + private static final String[] STATIC_STRUCTURE = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "etc", "var" }; @@ -205,13 +205,12 @@ public class DomainProcessorFactory implements EntityProcessorFactory { UnixUser domUser = dom.getUser(); String domName = dom.getName(); Pac pac = domUser.getPac(); - boolean dynamicWeb = pac.isDynamicWeb() || dom.isPacDomain(); String pacName = pac.getName(); String homeDir = domUser.getHomedir(); String domsDir = homeDir + "/doms"; String userName = domUser.getName(); String domainDir = domsDir + "/" + dom.getName(); - String[] subDirs = dynamicWeb ? DW_STRUCTURE : SW_STRUCTURE; + String[] subDirs = dom.isDynamic() ? DYNAMIC_STRUCTURE : STATIC_STRUCTURE; String httpdRights = ""; if (pacName != userName) { httpdRights = @@ -248,7 +247,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { domDirsProcessor.appendProcessor( new CreateFileProcessor("/de/hsadmin/mods/dom/index.html.vm", templateVars, dom, domainDir + "/subs-ssl/www/index.html", userName, pacName, "644", false) ); - if (dynamicWeb) { + if (dom.isDynamic()) { domDirsProcessor.appendProcessor( new CreateFileProcessor("/de/hsadmin/mods/dom/test.cgi.vm", templateVars, dom, domainDir + "/cgi/test.cgi", userName, pacName, "755", false) ); diff --git a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm index ee021b5..9474e6d 100644 --- a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm +++ b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm @@ -13,7 +13,7 @@ DocumentRoot /home/doms/${dom.name}/htdocs -#if( ${pac.dynamicWeb} || ${dom.pacDomain} ) +#if( ${dom.isDynamic} ) Alias /cgi-bin/ /home/doms/${dom.name}/cgi/ Alias /fastcgi-bin/ /home/doms/${dom.name}/fastcgi/ #end @@ -26,7 +26,7 @@ AllowOverride AuthConfig FileInfo Indexes Limit -#if( ${pac.dynamicWeb} || ${dom.pacDomain} ) +#if( ${dom.isDynamic} ) SetHandler cgi-script Options +ExecCGI ${includes} -Indexes -MultiViews +SymLinksIfOwnerMatch @@ -63,7 +63,7 @@ RewriteRule ^(.*) - [redirect=404,last] #end -#if( ${pac.dynamicWeb} || ${dom.pacDomain} ) +#if( ${dom.isDynamic} ) AddType application/x-httpd-php .php .php5 .php4 .php3 Action application/x-httpd-php /fastcgi-bin/phpstub #end diff --git a/hsarback/src/de/hsadmin/mods/pac/Pac.java b/hsarback/src/de/hsadmin/mods/pac/Pac.java index 15ae41e..4b634d2 100644 --- a/hsarback/src/de/hsadmin/mods/pac/Pac.java +++ b/hsarback/src/de/hsadmin/mods/pac/Pac.java @@ -294,10 +294,6 @@ public class Pac extends AbstractEntity implements Serializable { || super.isReadAllowedFor(loginUser); } - public boolean isDynamicWeb() { - return getBasepac().getName().startsWith("DW"); - } - public static String restriction() { return // all pacs of customer diff --git a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java index 59d1654..e84311d 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java @@ -23,11 +23,12 @@ public class PacProcessorFactory implements EntityProcessorFactory { public Processor createCreateProcessor( EntityManager em, T entity) throws ProcessorException { Pac pac = (Pac) entity; - String pacName = pac.getName(); - Hive hive = pac.getHive(); - UnixUser unixUser = getPacAdminUser(pac); - String password = PasswordTool.generatePassword(); - return new CompoundProcessor( + if (pac.getBasepac().getName().startsWith("PAC/")) { + String pacName = pac.getName(); + Hive hive = pac.getHive(); + UnixUser unixUser = getPacAdminUser(pac); + String password = PasswordTool.generatePassword(); + return new CompoundProcessor( createAddUserProc(pacName, unixUser, password), createSetQuotaProc(pac), createEtcHostsProc(hive), @@ -39,6 +40,9 @@ public class PacProcessorFactory implements EntityProcessorFactory { createIfUp(pacName), createHttpdVirtualProc(hive), createAccountingRulesProc()); + } else { + return new ShellProcessor("exit 0"); //TODO: Nothing should happen here. + } } private Processor createAccountingRulesProc() { @@ -72,15 +76,20 @@ public class PacProcessorFactory implements EntityProcessorFactory { public Processor createUpdateProcessor(EntityManager em, T entity) throws ProcessorException { Pac pac = (Pac) entity; - return createSetQuotaProc(pac); + if (pac.getBasepac().getName().startsWith("PAC/")) { + return createSetQuotaProc(pac); + } else { + return new ShellProcessor("exit 0"); //TODO: Nothing should happen here. + } } @Override public Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException { Pac pac = (Pac) entity; - Hive hive = pac.getHive(); - WaitingTasksProcessor waiting = new WaitingTasksProcessor(createDelUserProc(pac.getName())); - waiting.appendProcessor(pac.getHiveName(), new CompoundProcessor( + if (pac.getBasepac().getName().startsWith("PAC/")) { + Hive hive = pac.getHive(); + WaitingTasksProcessor waiting = new WaitingTasksProcessor(createDelUserProc(pac.getName())); + waiting.appendProcessor(pac.getHiveName(), new CompoundProcessor( createIfDown(pac.getName()), createEtcHostsProc(hive), createNetworkInterfacesProc(hive), @@ -88,7 +97,10 @@ public class PacProcessorFactory implements EntityProcessorFactory { createProftpdConfProc(hive), createHttpdVirtualProc(hive), createAccountingRulesProc()), "remove packet"); - return waiting; + return waiting; + } else { + return new ShellProcessor("exit 0"); //TODO: Nothing should happen here. + } } private Processor createEtcHostsProc(Hive hive) throws ProcessorException { diff --git a/hsarback/src/de/hsadmin/remote/RoleRemote.java b/hsarback/src/de/hsadmin/remote/RoleRemote.java index 6523ed0..6b3cd70 100644 --- a/hsarback/src/de/hsadmin/remote/RoleRemote.java +++ b/hsarback/src/de/hsadmin/remote/RoleRemote.java @@ -34,11 +34,7 @@ public class RoleRemote implements IRemote { role = "HOSTMASTER"; } if (user.equals(pacName)) { - if (pac.isDynamicWeb()) { - role = "PAC_ADMIN_DW"; - } else { - role = "PAC_ADMIN_SW"; - } + role = "PAC_ADMIN"; } if (role.equals("USER")) { GenericModuleImpl module = new GenericModuleImpl(transaction); diff --git a/hsarback/test/de/hsadmin/processor/PacProcessor.java b/hsarback/test/de/hsadmin/processor/PacProcessor.java index fe7fe1f..bc455d3 100644 --- a/hsarback/test/de/hsadmin/processor/PacProcessor.java +++ b/hsarback/test/de/hsadmin/processor/PacProcessor.java @@ -69,7 +69,7 @@ public class PacProcessor { private BasePac findBasePacDW() { Query basepacQuery = entityManager.createQuery("SELECT b FROM BasePacs b WHERE b.name = :basepacName AND b.valid = :valid"); - basepacQuery.setParameter("basepacName", "DW/B"); + basepacQuery.setParameter("basepacName", "PAC/WEB"); basepacQuery.setParameter("valid", Boolean.TRUE); return (BasePac) basepacQuery.getSingleResult(); } diff --git a/hsarback/test/de/hsadmin/remote/InitDataTest.java b/hsarback/test/de/hsadmin/remote/InitDataTest.java index fc09636..9fd02a4 100644 --- a/hsarback/test/de/hsadmin/remote/InitDataTest.java +++ b/hsarback/test/de/hsadmin/remote/InitDataTest.java @@ -77,7 +77,7 @@ public class InitDataTest { setParams.put("name", "aaa00"); setParams.put("hive", "h99"); setParams.put("customer", "hsh00-aaa"); - setParams.put("basepac", "DW/B"); + setParams.put("basepac", "PAC/WEB"); setParams.put("curinetaddr", "176.9.242.74"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), diff --git a/hsarback/test/de/hsadmin/remote/LongCustomerNameTest.java b/hsarback/test/de/hsadmin/remote/LongCustomerNameTest.java index b99fe60..f26c117 100644 --- a/hsarback/test/de/hsadmin/remote/LongCustomerNameTest.java +++ b/hsarback/test/de/hsadmin/remote/LongCustomerNameTest.java @@ -100,12 +100,12 @@ public class LongCustomerNameTest { pacParams.put("name", "p#"); pacParams.put("hive", "h99"); pacParams.put("customer", customer); - pacParams.put("basepac", "DW/B"); + pacParams.put("basepac", "WEB/PAC"); pacParams.put("curinetaddr", "176.9.242.76"); HashMap pacComponents = new HashMap(); pacComponents.put("QUOTA", "512"); - pacComponents.put("TRAFFIC", "8"); - pacComponents.put("TOMCAT", "0"); + pacComponents.put("TRAFFIC", "5"); + pacComponents.put("DAEMON", "1"); pacParams.put("components", pacComponents); Object[] pacCallBlock = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), diff --git a/hsarback/test/de/hsadmin/remote/PacTest.java b/hsarback/test/de/hsadmin/remote/PacTest.java index 45cccc9..30c417d 100644 --- a/hsarback/test/de/hsadmin/remote/PacTest.java +++ b/hsarback/test/de/hsadmin/remote/PacTest.java @@ -92,12 +92,12 @@ public class PacTest { setParams.put("name", "aaa01"); setParams.put("hive", "h99"); setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa"); - setParams.put("basepac", "DW/B"); + setParams.put("basepac", "PAC/WEB"); setParams.put("curinetaddr", "176.9.242.76"); HashMap components = new HashMap(); components.put("QUOTA", "512"); - components.put("TRAFFIC", "8"); - components.put("TOMCAT", "1"); + components.put("TRAFFIC", "5"); + components.put("DAEMON", "1"); setParams.put("components", components); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), diff --git a/hsarback/test/de/hsadmin/remote/RemoteTest.java b/hsarback/test/de/hsadmin/remote/RemoteTest.java index 8de90d7..6747dcf 100644 --- a/hsarback/test/de/hsadmin/remote/RemoteTest.java +++ b/hsarback/test/de/hsadmin/remote/RemoteTest.java @@ -16,8 +16,8 @@ import org.junit.runners.Suite; EMailAliasTest.class, DomainTest.class, EMailAddressTest.class, + LongCustomerNameTest.class // CustomerTest.class, - LongCustomerNameTest.class // QueueTaskTest.class }) diff --git a/hsarback/test/de/hsadmin/remote/RoleTest.java b/hsarback/test/de/hsadmin/remote/RoleTest.java index 0236509..7f114f7 100644 --- a/hsarback/test/de/hsadmin/remote/RoleTest.java +++ b/hsarback/test/de/hsadmin/remote/RoleTest.java @@ -45,7 +45,7 @@ public class RoleTest { Object[] result = (Object[]) execute; assertTrue(result.length == 1); String role = (String) ((Map) result[0]).get("role"); - assertEquals("PAC_ADMIN_DW", role); + assertEquals("PAC_ADMIN", role); } catch (XmlRpcException e) { fail(e.getMessage()); } diff --git a/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java b/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java index e17b1bc..28804c9 100644 --- a/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java +++ b/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java @@ -46,7 +46,7 @@ public class SSLCertDomainTest { setParams.put("name", "aaa02"); setParams.put("hive", "h99"); setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa"); - setParams.put("basepac", "DW/B"); + setParams.put("basepac", "PAC/WEB"); setParams.put("curinetaddr", "176.9.242.77"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),