From f05c2ea1f8f04a2f7e9d7fea8f292a0e61906308 Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Mon, 29 Apr 2013 18:49:16 +0200 Subject: [PATCH] Hack: Check multi options and pac types. --- hsarback/database/data.sql | 56 +++++++++++-------- hsarback/database/database_update.sql | 4 +- .../mods/db/MySqlDatabaseModuleImpl.java | 13 +++++ .../hsadmin/mods/db/MySqlUserModuleImpl.java | 13 +++++ .../mods/db/PgSqlDatabaseModuleImpl.java | 14 +++++ .../hsadmin/mods/db/PgSqlUserModuleImpl.java | 13 +++++ .../de/hsadmin/mods/dom/DomainModuleImpl.java | 11 +++- .../mods/email/EMailAddressModuleImpl.java | 16 ++++++ .../mods/email/EMailAliasModuleImpl.java | 15 +++++ hsarback/src/de/hsadmin/mods/pac/Pac.java | 17 ++++-- .../hsadmin/mods/pac/PacProcessorFactory.java | 6 +- .../hsadmin/mods/user/UnixUserModuleImpl.java | 14 ++++- .../test/de/hsadmin/remote/InitDataTest.java | 2 +- hsarback/test/de/hsadmin/remote/PacTest.java | 2 +- .../de/hsadmin/remote/SSLCertDomainTest.java | 4 +- 15 files changed, 159 insertions(+), 41 deletions(-) diff --git a/hsarback/database/data.sql b/hsarback/database/data.sql index 7f4c048..e359fd1 100644 --- a/hsarback/database/data.sql +++ b/hsarback/database/data.sql @@ -2,61 +2,69 @@ -- Table: basepacket -- INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_number) - VALUES ('DW/B', 'Dynamic-Web/Base', 300, true, 100); + VALUES ('PAC/DW', 'Dynamic-Web/Base', 300, true, 100); INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_number) - VALUES ('SW/B', 'Static-Web/Base', 400, true, 200); + VALUES ('PAC/SW', 'Static-Web/Base', 400, true, 200); INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_number) - VALUES ('WEB', 'Web/Base', 100, true, 300); + VALUES ('PAC/WEB', 'Web/Base', 100, true, 300); INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_number) - VALUES ('HIVE', 'Managed Server', 200, true, 400); + VALUES ('SRV/MGD', 'Managed Server', 200, true, 400); -- -- Table: basecomponent -- INSERT INTO basecomponent (basecomponent_code, description, sorting, valid) - VALUES ('TRAFFIC', 'Monatliches Datenvolumen in GB', 100, true); + VALUES ('MULTI', 'Monatliches Datenvolumen in GB', 100, true); INSERT INTO basecomponent (basecomponent_code, description, sorting, valid) - VALUES ('QUOTA', 'Festplattenspeicherplatz in MB', 200, true); + VALUES ('TRAFFIC', 'Monatliches Datenvolumen in GB', 200, true); INSERT INTO basecomponent (basecomponent_code, description, sorting, valid) - VALUES ('DAEMON', 'Nutzung eines eigenen Servers/Daemons', 300, true); + VALUES ('QUOTA', 'Festplattenspeicherplatz in MB', 300, true); INSERT INTO basecomponent (basecomponent_code, description, sorting, valid) - VALUES ('MIRROR', 'Echtzeitspiegelung der Daten', 400, true); + VALUES ('DAEMON', 'Nutzung eines eigenen Servers/Daemons', 400, true); INSERT INTO basecomponent (basecomponent_code, description, sorting, valid) - VALUES ('BACKUP', 'Nächtliches Backup', 500, true); + VALUES ('MIRROR', 'Echtzeitspiegelung der Daten', 500, true); +INSERT INTO basecomponent (basecomponent_code, description, sorting, valid) + VALUES ('BACKUP', 'Nächtliches Backup', 600, true); -- -- Table: component -- INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 128, 40960, 128, 128, 128, false, 101 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='QUOTA'; + SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 100 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='MULTI'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 512, 40960, 512, 512, 512, false, 201 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='QUOTA'; + SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 200 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='MULTI'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 512, 40960, 512, 512, 0, false, 301 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='QUOTA'; + SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 300 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='MULTI'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 2, 40960, 2, 2, 2, false, 102 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='TRAFFIC'; + SELECT basepacket_id, basecomponent_id, 128, 40960, 128, 128, 128, false, 101 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='QUOTA'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 4, 40960, 4, 4, 4, false, 202 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='TRAFFIC'; + SELECT basepacket_id, basecomponent_id, 512, 40960, 512, 512, 512, false, 201 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='QUOTA'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 5, 40960, 5, 5, 0, false, 302 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='TRAFFIC'; + SELECT basepacket_id, basecomponent_id, 512, 40960, 512, 512, 0, false, 301 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='QUOTA'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 4, 0, 1, 0, false, 103 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='DAEMON'; + SELECT basepacket_id, basecomponent_id, 2, 40960, 2, 2, 2, false, 102 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='TRAFFIC'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 0, 0, 1, 0, false, 203 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='DAEMON'; + SELECT basepacket_id, basecomponent_id, 4, 40960, 4, 4, 4, false, 202 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='TRAFFIC'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 4, 0, 1, 0, false, 303 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='DAEMON'; + SELECT basepacket_id, basecomponent_id, 5, 40960, 5, 5, 0, false, 302 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='TRAFFIC'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 104 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='MIRROR'; + SELECT basepacket_id, basecomponent_id, 0, 4, 0, 1, 0, false, 103 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='DAEMON'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 204 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='MIRROR'; + SELECT basepacket_id, basecomponent_id, 0, 0, 0, 1, 0, false, 203 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='DAEMON'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 304 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='MIRROR'; + SELECT basepacket_id, basecomponent_id, 0, 4, 0, 1, 0, false, 303 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='DAEMON'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 105 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='BACKUP'; + SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 104 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='MIRROR'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 205 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='BACKUP'; + SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 204 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='MIRROR'; INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) - SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 305 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='BACKUP'; + SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 304 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='MIRROR'; +INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) + SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 105 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='BACKUP'; +INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) + SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 205 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='BACKUP'; +INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number) + SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 305 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='BACKUP'; -- -- Table: business_partner diff --git a/hsarback/database/database_update.sql b/hsarback/database/database_update.sql index 4687700..1d70974 100644 --- a/hsarback/database/database_update.sql +++ b/hsarback/database/database_update.sql @@ -3,7 +3,7 @@ -- JOIN unixuser on ( domain.domain_owner = unixuser.unixuser_id ) -- JOIN packet on ( unixuser.packet_id = packet.packet_id ) -- JOIN basepacket on ( packet.bp_id = basepacket.basepacket_id ), domain_option --- WHERE basepacket.basepacket_code = 'DW/B' +-- WHERE basepacket.basepacket_code = 'PAC/DW' -- AND domain_option.domain_option_name = 'php' ; -- DELETE FROM domain__domain_option @@ -11,7 +11,7 @@ -- JOIN unixuser on ( domain.domain_owner = unixuser.unixuser_id ) -- JOIN packet on ( unixuser.packet_id = packet.packet_id ) -- JOIN basepacket on ( packet.bp_id = basepacket.basepacket_id ) --- WHERE basepacket.basepacket_code != 'DW/B' +-- WHERE basepacket.basepacket_code != 'PAC/DW' -- AND domain__domain_option.domain_option_id = domain_option.domain_option_id -- AND domain_option.domain_option_name = 'php' ; diff --git a/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java b/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java index f111ad5..3ecfa96 100644 --- a/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java @@ -15,6 +15,8 @@ import de.hsadmin.mods.user.UnixUser; public class MySqlDatabaseModuleImpl extends AbstractModuleImpl { + private static final int DBS_PER_MULTI_OPTION = 25; + @Override public List search(Class entityClass, String condition, String orderBy) throws HSAdminException { @@ -54,6 +56,17 @@ public class MySqlDatabaseModuleImpl extends AbstractModuleImpl { if (!pac.getName().equals(pacPrefix)) { throw new HSAdminException("wrong database owner"); } + //TODO: Needs better implementation + String pacType = pac.getBasepac().getName(); + if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW)) { + throw new HSAdminException("not allowed for this packet type"); + } + //TODO: Needs better implementation + Query qDatabases = em.createQuery("SELECT obj FROM Databases obj WHERE obj.packet_id = :pacId"); + qDatabases.setParameter("pacId", pac.getId()); + if (qDatabases.getResultList().size() >= DBS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) { + throw new HSAdminException("included number of databases exceeded"); + } database.setPac(pac); return super.add(newEntity); } diff --git a/hsarback/src/de/hsadmin/mods/db/MySqlUserModuleImpl.java b/hsarback/src/de/hsadmin/mods/db/MySqlUserModuleImpl.java index 8fb0488..3988c6b 100644 --- a/hsarback/src/de/hsadmin/mods/db/MySqlUserModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/db/MySqlUserModuleImpl.java @@ -15,6 +15,8 @@ import de.hsadmin.mods.user.UnixUser; public class MySqlUserModuleImpl extends AbstractModuleImpl { + private static final int DBUSERS_PER_MULTI_OPTION = 25; + @Override public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException { Transaction transaction = getTransaction(); @@ -35,6 +37,17 @@ public class MySqlUserModuleImpl extends AbstractModuleImpl { if (pac == null || !pac.isReadAllowedFor(loginUser)) { throw new AuthorisationException(loginUser, "add", newEntity); } + //TODO: Needs better implementation + String pacType = pac.getBasepac().getName(); + if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW)) { + throw new HSAdminException("not allowed for this packet type"); + } + //TODO: Needs better implementation + Query qDatabaseUsers = em.createQuery("SELECT obj FROM DatabaseUsers obj WHERE obj.packet_id = :pacId"); + qDatabaseUsers.setParameter("pacId", pac.getId()); + if (qDatabaseUsers.getResultList().size() >= DBUSERS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) { + throw new HSAdminException("included database users exceeded"); + } user.setPac(pac); return super.add(newEntity); } diff --git a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseModuleImpl.java b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseModuleImpl.java index 841f090..c6e2de2 100644 --- a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseModuleImpl.java @@ -15,6 +15,8 @@ import de.hsadmin.mods.user.UnixUser; public class PgSqlDatabaseModuleImpl extends AbstractModuleImpl { + private static final int DBS_PER_MULTI_OPTION = 25; + @Override public List search(Class entityClass, String condition, String orderBy) throws HSAdminException { if (orderBy == null || orderBy.length() == 0) { @@ -51,6 +53,18 @@ public class PgSqlDatabaseModuleImpl extends AbstractModuleImpl { } if (!pac.getName().equals(pacPrefix)) { throw new HSAdminException("wrong database owner"); + + } + //TODO: Needs better implementation + String pacType = pac.getBasepac().getName(); + if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW)) { + throw new HSAdminException("not allowed for this packet type"); + } + //TODO: Needs better implementation + Query qDatabases = em.createQuery("SELECT obj FROM Databases obj WHERE obj.packet_id = :pacId"); + qDatabases.setParameter("pacId", pac.getId()); + if (qDatabases.getResultList().size() >= DBS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) { + throw new HSAdminException("included databases exceeded"); } database.setPac(pac); return super.add(newEntity); diff --git a/hsarback/src/de/hsadmin/mods/db/PgSqlUserModuleImpl.java b/hsarback/src/de/hsadmin/mods/db/PgSqlUserModuleImpl.java index c0c9835..09d96b4 100644 --- a/hsarback/src/de/hsadmin/mods/db/PgSqlUserModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/db/PgSqlUserModuleImpl.java @@ -14,6 +14,8 @@ import de.hsadmin.mods.user.UnixUser; public class PgSqlUserModuleImpl extends AbstractModuleImpl { + private static final int DBUSERS_PER_MULTI_OPTION = 5; + @Override public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException { UnixUser loginUser = getTransaction().getLoginUser(); @@ -30,6 +32,17 @@ public class PgSqlUserModuleImpl extends AbstractModuleImpl { if (pac == null || !pac.isReadAllowedFor(loginUser)) { throw new AuthorisationException(loginUser, "add", newEntity); } + //TODO: Needs better implementation + String pacType = pac.getBasepac().getName(); + if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW)) { + throw new HSAdminException("not allowed for this packet type"); + } + //TODO: Needs better implementation + Query qDatabaseUsers = em.createQuery("SELECT obj FROM DatabaseUsers obj WHERE obj.packet_id = :pacId"); + qDatabaseUsers.setParameter("pacId", pac.getId()); + if (qDatabaseUsers.getResultList().size() >= DBUSERS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) { + throw new HSAdminException("included database users exceeded"); + } user.setPac(pac); return super.add(newEntity); } diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java index 4fbdf54..badb88c 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java @@ -20,15 +20,15 @@ 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 DOMMULTIVIEWS = "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, + public static final String[] ALL_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMMULTIVIEWS, DOMOPT_INDEXES, DOMOPT_HTDOCSFALLBACK, DOMOPT_INCLUDES, DOMOPT_BACKUPFOREXTERNALMX }; - public static final String[] DEFAULT_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMOPT_MULTIVIEWS, + public static final String[] DEFAULT_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMMULTIVIEWS, DOMOPT_INDEXES, DOMOPT_HTDOCSFALLBACK, DOMOPT_INCLUDES }; @Override @@ -102,6 +102,11 @@ public class DomainModuleImpl extends AbstractModuleImpl { if (admin == null || admin.getName() == null || admin.getName().length() == 0) { throw new HSAdminException("domain admin required"); } + //TODO: Needs better implementation + String pacType = admin.getPac().getBasepac().getName(); + if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) { + throw new HSAdminException("not allowed for this packet type"); + } // Standard domainoptions setzen. TODO: Alle defaults über eigene Klasse aus der Datenbank holen. EntityManager em = getTransaction().getEntityManager(); UnixUser loginUser = getTransaction().getLoginUser(); diff --git a/hsarback/src/de/hsadmin/mods/email/EMailAddressModuleImpl.java b/hsarback/src/de/hsadmin/mods/email/EMailAddressModuleImpl.java index 175ef4e..4128e38 100644 --- a/hsarback/src/de/hsadmin/mods/email/EMailAddressModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/email/EMailAddressModuleImpl.java @@ -11,10 +11,13 @@ import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.model.HSAdminException; import de.hsadmin.core.model.Transaction; import de.hsadmin.mods.dom.Domain; +import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.user.UnixUser; public class EMailAddressModuleImpl extends AbstractModuleImpl { + private static final int EMAIL_PER_MULTI_OPTION = 250; + @Override public List search(Class entityClass, String condition, String orderBy) throws HSAdminException { @@ -51,6 +54,19 @@ public class EMailAddressModuleImpl extends AbstractModuleImpl { if (dom.isPacDomain() && !loginUser.hasHostmasterRole()) { throw new AuthorisationException(loginUser, "add", adr); } + //TODO: Needs better implementation + String pacType = dom.getUser().getPac().getBasepac().getName(); + if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) { + throw new HSAdminException("not allowed for this packet type"); + } + //TODO: Needs better implementation + Query qEmailAliases = em.createQuery("SELECT obj FROM EmailAliases obj WHERE obj.packet_id = :pacId"); + qEmailAliases.setParameter("pacId", dom.getUser().getPac().getId()); + Query qEmailAddresses = em.createQuery("SELECT obj FROM EmailAdresses obj WHERE obj.domain.user.pac.packet_id = :pacId"); + qEmailAddresses.setParameter("pacId", dom.getUser().getPac().getId()); + if (qEmailAliases.getResultList().size() + qEmailAddresses.getResultList().size() >= EMAIL_PER_MULTI_OPTION * dom.getUser().getPac().getQuantityByComponentName("MULTI")) { + throw new HSAdminException("included email addresses/aliases exceeded"); + } return super.add(newEntity); } diff --git a/hsarback/src/de/hsadmin/mods/email/EMailAliasModuleImpl.java b/hsarback/src/de/hsadmin/mods/email/EMailAliasModuleImpl.java index c7a1b4e..19297a0 100644 --- a/hsarback/src/de/hsadmin/mods/email/EMailAliasModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/email/EMailAliasModuleImpl.java @@ -15,6 +15,8 @@ import de.hsadmin.mods.user.UnixUser; public class EMailAliasModuleImpl extends AbstractModuleImpl { + private static final int UNIXUSERS_PER_MULTI_OPTION = 250; + @Override public List search(Class entityClass, String condition, String orderBy) throws HSAdminException { @@ -44,6 +46,19 @@ public class EMailAliasModuleImpl extends AbstractModuleImpl { if (!name.startsWith(pac.getName())) { throw new AuthorisationException(loginUser, "add", newEntity); } + //TODO: Needs better implementation + String pacType = pac.getBasepac().getName(); + if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) { + throw new HSAdminException("not allowed for this packet type"); + } + //TODO: Needs better implementation + Query qEmailAliases = em.createQuery("SELECT obj FROM EmailAliases obj WHERE obj.packet_id = :pacId"); + qEmailAliases.setParameter("pacId", pac.getId()); + Query qEmailAddresses = em.createQuery("SELECT obj FROM EmailAdresses obj WHERE obj.domain.user.pac.packet_id = :pacId"); + qEmailAddresses.setParameter("pacId", pac.getId()); + if (qEmailAliases.getResultList().size() + qEmailAddresses.getResultList().size() >= UNIXUSERS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) { + throw new HSAdminException("included email addresses/aliases exceeded"); + } alias.setPac(pac); return super.add(newEntity); } diff --git a/hsarback/src/de/hsadmin/mods/pac/Pac.java b/hsarback/src/de/hsadmin/mods/pac/Pac.java index 255b637..270c799 100644 --- a/hsarback/src/de/hsadmin/mods/pac/Pac.java +++ b/hsarback/src/de/hsadmin/mods/pac/Pac.java @@ -37,10 +37,10 @@ import de.hsadmin.mods.user.UnixUser; @AnnModuleImpl(de.hsadmin.mods.pac.PacModuleImpl.class) public class Pac extends AbstractEntity implements Serializable { - public static final String PAC_WEB_BASE = "WEB"; - public static final String PAC_HIVE = "HIVE"; - public static final String PAC_DW_BASE = "DW/B"; - public static final String PAC_SW_BASE = "SW/B"; + public static final String PAC_DW = "PAC/DW"; + public static final String PAC_SW = "PAC/SW"; + public static final String PAC_WEB = "PAC/WEB"; + public static final String PAC_SRV = "SRV/MGD"; private static final long serialVersionUID = 1L; @@ -293,4 +293,13 @@ public class Pac extends AbstractEntity implements Serializable { public void setFree(boolean free) { this.free = free; } + + public int getQuantityByComponentName(String componentName) { + PacComponent multi = getPacComponent(componentName); + if (multi == null) { + return 0; + } else { + return multi.getQuantity(); + } + } } diff --git a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java index b665e08..236bbb6 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java @@ -25,7 +25,7 @@ public class PacProcessorFactory implements EntityProcessorFactory { EntityManager em, T entity) throws ProcessorException { Pac pac = (Pac) entity; String basepacName = pac.getBasepac().getName(); - if (basepacName.equals(Pac.PAC_WEB_BASE) || basepacName.equals(Pac.PAC_DW_BASE) || basepacName.equals(Pac.PAC_SW_BASE)) { + if (basepacName.equals(Pac.PAC_WEB) || basepacName.equals(Pac.PAC_DW) || basepacName.equals(Pac.PAC_SW)) { String pacName = pac.getName(); Hive hive = pac.getHive(); UnixUser unixUser = getPacAdminUser(pac); @@ -79,7 +79,7 @@ public class PacProcessorFactory implements EntityProcessorFactory { throws ProcessorException { Pac pac = (Pac) entity; String basepacName = pac.getBasepac().getName(); - if (basepacName.equals(Pac.PAC_WEB_BASE) || basepacName.equals(Pac.PAC_DW_BASE) || basepacName.equals(Pac.PAC_SW_BASE)) { + if (basepacName.equals(Pac.PAC_WEB) || basepacName.equals(Pac.PAC_DW) || basepacName.equals(Pac.PAC_SW)) { return createSetQuotaProc(pac); } else { return new NullProcessor(); @@ -90,7 +90,7 @@ public class PacProcessorFactory implements EntityProcessorFactory { public Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException { Pac pac = (Pac) entity; String basepacName = pac.getBasepac().getName(); - if (basepacName.equals(Pac.PAC_WEB_BASE) || basepacName.equals(Pac.PAC_DW_BASE) || basepacName.equals(Pac.PAC_SW_BASE)) { + if (basepacName.equals(Pac.PAC_WEB) || basepacName.equals(Pac.PAC_DW) || basepacName.equals(Pac.PAC_SW)) { Hive hive = pac.getHive(); WaitingTasksProcessor waiting = new WaitingTasksProcessor(createDelUserProc(pac.getName())); waiting.appendProcessor(pac.getHiveName(), new CompoundProcessor( diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java b/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java index b677e54..28c014b 100644 --- a/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java @@ -15,6 +15,8 @@ import de.hsadmin.mods.pac.Pac; public class UnixUserModuleImpl extends AbstractModuleImpl { + private static final int UNIXUSERS_PER_MULTI_OPTION = 50; + public UnixUserModuleImpl() { } @@ -125,7 +127,17 @@ public class UnixUserModuleImpl extends AbstractModuleImpl { throw new AuthorisationException(loginUser, "add", newUnixUser, "userId"); } } - + //TODO: Needs better implementation + String pacType = pac.getBasepac().getName(); + if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) { + throw new HSAdminException("not allowed for this packet type"); + } + //TODO: Needs better implementation + Query qUnixUsers = em.createQuery("SELECT obj FROM UnixUsers obj WHERE obj.id = :pacId"); + qUnixUsers.setParameter("pacId", pac.getId()); + if (qUnixUsers.getResultList().size() >= UNIXUSERS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) { + throw new HSAdminException("included unix users exceeded"); + } // don't move this up, it will update the new entity still with wrong // userid! newUnixUser.setPac(pac); diff --git a/hsarback/test/de/hsadmin/remote/InitDataTest.java b/hsarback/test/de/hsadmin/remote/InitDataTest.java index 9e44124..392cb6e 100644 --- a/hsarback/test/de/hsadmin/remote/InitDataTest.java +++ b/hsarback/test/de/hsadmin/remote/InitDataTest.java @@ -79,7 +79,7 @@ public class InitDataTest { setParams.put("name", "aaa00"); setParams.put("hive", "h99"); setParams.put("customer", "hsh00-aaa"); - setParams.put("basepac", Pac.PAC_WEB_BASE); + setParams.put("basepac", Pac.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/PacTest.java b/hsarback/test/de/hsadmin/remote/PacTest.java index 9aeb055..2ac5c8e 100644 --- a/hsarback/test/de/hsadmin/remote/PacTest.java +++ b/hsarback/test/de/hsadmin/remote/PacTest.java @@ -93,7 +93,7 @@ public class PacTest { setParams.put("name", "aaa01"); setParams.put("hive", "h99"); setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa"); - setParams.put("basepac", Pac.PAC_WEB_BASE); + setParams.put("basepac", Pac.PAC_WEB); setParams.put("curinetaddr", "176.9.242.76"); HashMap components = new HashMap(); components.put("QUOTA", "512"); diff --git a/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java b/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java index 670cd62..065fa1e 100644 --- a/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java +++ b/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java @@ -47,7 +47,7 @@ public class SSLCertDomainTest { setParams.put("name", "aaa02"); setParams.put("hive", "h99"); setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa"); - setParams.put("basepac", Pac.PAC_WEB_BASE); + setParams.put("basepac", Pac.PAC_WEB); setParams.put("curinetaddr", "176.9.242.77"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), @@ -78,7 +78,7 @@ public class SSLCertDomainTest { setParams.put("name", "aaa03"); setParams.put("hive", "h99"); setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa"); - setParams.put("basepac", Pac.PAC_DW_BASE); + setParams.put("basepac", Pac.PAC_DW); setParams.put("curinetaddr", "176.9.242.78"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),