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.
This commit is contained in:
Michael Hierweck 2013-04-12 12:56:53 +02:00
parent e9fd3e2170
commit 953f0320d2
13 changed files with 51 additions and 39 deletions

View File

@ -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();
}
}

View File

@ -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)
);

View File

@ -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
</Directory>
#if( ${pac.dynamicWeb} || ${dom.pacDomain} )
#if( ${dom.isDynamic} )
<Location /cgi-bin/>
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

View File

@ -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

View File

@ -23,11 +23,12 @@ public class PacProcessorFactory implements EntityProcessorFactory {
public <T extends AbstractEntity> 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 <T extends AbstractEntity> 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 <T extends AbstractEntity> 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 {

View File

@ -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);

View File

@ -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();
}

View File

@ -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()),

View File

@ -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<String, String> pacComponents = new HashMap<String, String>();
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()),

View File

@ -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<String, String> components = new HashMap<String, String>();
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()),

View File

@ -16,8 +16,8 @@ import org.junit.runners.Suite;
EMailAliasTest.class,
DomainTest.class,
EMailAddressTest.class,
LongCustomerNameTest.class
// CustomerTest.class,
LongCustomerNameTest.class
// QueueTaskTest.class
})

View File

@ -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());
}

View File

@ -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()),