add-domain-email-setup-validation (#74)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/74 Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
@ -8,9 +8,7 @@ public enum HsBookingItemType implements Node {
|
||||
PRIVATE_CLOUD,
|
||||
CLOUD_SERVER(PRIVATE_CLOUD),
|
||||
MANAGED_SERVER(PRIVATE_CLOUD),
|
||||
MANAGED_WEBSPACE(MANAGED_SERVER),
|
||||
DOMAIN_DNS_SETUP, // TODO.spec: experimental
|
||||
DOMAIN_EMAIL_SUBMISSION_SETUP; // TODO.spec: experimental
|
||||
MANAGED_WEBSPACE(MANAGED_SERVER);
|
||||
|
||||
private final HsBookingItemType parentItemType;
|
||||
|
||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_MBOX_SETUP;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ADDRESS;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_DATABASE;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_USER;
|
||||
@ -88,7 +88,7 @@ class HsManagedWebspaceBookingItemValidator extends HsBookingItemEntityValidator
|
||||
return (final HsBookingItemEntity entity, final IntegerProperty prop, final Integer factor) -> {
|
||||
final var unixUserCount = ofNullable(entity.getRelatedHostingAsset())
|
||||
.map(ha -> ha.getSubHostingAssets().stream()
|
||||
.filter(bi -> bi.getType() == DOMAIN_EMAIL_MAILBOX_SETUP)
|
||||
.filter(bi -> bi.getType() == DOMAIN_MBOX_SETUP)
|
||||
.flatMap(domainEMailSetup -> domainEMailSetup.getSubHostingAssets().stream()
|
||||
.filter(subAsset -> subAsset.getType()==EMAIL_ADDRESS))
|
||||
.count())
|
||||
|
@ -45,6 +45,10 @@ public enum HsHostingAssetType implements Node {
|
||||
inGroup("Webspace"),
|
||||
requiredParent(MANAGED_WEBSPACE)),
|
||||
|
||||
EMAIL_ALIAS( // named e.g. xyz00-abc
|
||||
inGroup("Webspace"),
|
||||
requiredParent(MANAGED_WEBSPACE)),
|
||||
|
||||
DOMAIN_SETUP( // named e.g. example.org
|
||||
inGroup("Domain"),
|
||||
optionalParent(SAME_TYPE)
|
||||
@ -52,32 +56,29 @@ public enum HsHostingAssetType implements Node {
|
||||
|
||||
DOMAIN_DNS_SETUP( // named e.g. example.org
|
||||
inGroup("Domain"),
|
||||
requiredParent(DOMAIN_SETUP)),
|
||||
requiredParent(DOMAIN_SETUP),
|
||||
assignedTo(MANAGED_WEBSPACE)),
|
||||
|
||||
DOMAIN_HTTP_SETUP( // named e.g. example.org
|
||||
inGroup("Domain"),
|
||||
requiredParent(DOMAIN_SETUP),
|
||||
assignedTo(UNIX_USER)),
|
||||
|
||||
DOMAIN_EMAIL_SUBMISSION_SETUP( // named e.g. example.org
|
||||
DOMAIN_SMTP_SETUP( // named e.g. example.org
|
||||
inGroup("Domain"),
|
||||
requiredParent(DOMAIN_SETUP),
|
||||
assignedTo(MANAGED_WEBSPACE)),
|
||||
|
||||
DOMAIN_EMAIL_MAILBOX_SETUP( // named e.g. example.org
|
||||
DOMAIN_MBOX_SETUP( // named e.g. example.org
|
||||
inGroup("Domain"),
|
||||
requiredParent(DOMAIN_SETUP),
|
||||
assignedTo(MANAGED_WEBSPACE)),
|
||||
|
||||
// TODO.spec: SECURE_MX
|
||||
|
||||
EMAIL_ALIAS( // named e.g. xyz00-abc
|
||||
inGroup("Webspace"),
|
||||
requiredParent(MANAGED_WEBSPACE)),
|
||||
|
||||
EMAIL_ADDRESS( // named e.g. sample@example.org
|
||||
inGroup("Domain"),
|
||||
requiredParent(DOMAIN_EMAIL_MAILBOX_SETUP)),
|
||||
requiredParent(DOMAIN_MBOX_SETUP)),
|
||||
|
||||
PGSQL_INSTANCE( // TODO.spec: identifier to be specified
|
||||
inGroup("PostgreSQL"),
|
||||
|
@ -23,6 +23,9 @@ public class HostingAssetEntityValidatorRegistry {
|
||||
register(DOMAIN_SETUP, new HsDomainSetupHostingAssetValidator());
|
||||
register(DOMAIN_DNS_SETUP, new HsDomainDnsSetupHostingAssetValidator());
|
||||
register(DOMAIN_HTTP_SETUP, new HsDomainHttpSetupHostingAssetValidator());
|
||||
register(DOMAIN_SMTP_SETUP, new HsDomainSmtpSetupHostingAssetValidator());
|
||||
register(DOMAIN_MBOX_SETUP, new HsDomainMboxSetupHostingAssetValidator());
|
||||
register(EMAIL_ADDRESS, new HsEMailAddressHostingAssetValidator());
|
||||
}
|
||||
|
||||
private static void register(final Enum<HsHostingAssetType> type, final HsEntityValidator<HsHostingAssetEntity> validator) {
|
||||
|
@ -60,7 +60,7 @@ class HsDomainDnsSetupHostingAssetValidator extends HostingAssetEntityValidator
|
||||
|
||||
@Override
|
||||
protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) {
|
||||
return Pattern.compile("^" + assetEntity.getParentAsset().getIdentifier() + Pattern.quote(IDENTIFIER_SUFFIX) + "$");
|
||||
return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,7 +43,7 @@ class HsDomainHttpSetupHostingAssetValidator extends HostingAssetEntityValidator
|
||||
|
||||
@Override
|
||||
protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) {
|
||||
return Pattern.compile("^" + assetEntity.getParentAsset().getIdentifier() + Pattern.quote(IDENTIFIER_SUFFIX) + "$");
|
||||
return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,34 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_MBOX_SETUP;
|
||||
|
||||
class HsDomainMboxSetupHostingAssetValidator extends HostingAssetEntityValidator {
|
||||
|
||||
public static final String IDENTIFIER_SUFFIX = "|MBOX";
|
||||
|
||||
HsDomainMboxSetupHostingAssetValidator() {
|
||||
super(
|
||||
DOMAIN_MBOX_SETUP,
|
||||
AlarmContact.isOptional(),
|
||||
|
||||
NO_EXTRA_PROPERTIES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) {
|
||||
return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessEntity(final HsHostingAssetEntity entity) {
|
||||
super.preprocessEntity(entity);
|
||||
if (entity.getIdentifier() == null) {
|
||||
ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX));
|
||||
}
|
||||
}
|
||||
}
|
@ -43,7 +43,6 @@ class HsDomainSetupHostingAssetValidator extends HostingAssetEntityValidator {
|
||||
// - user has Admin/Agent-role for all its sub-domains and the direct parent-Domain which are set up at at Hostsharing
|
||||
// - domain has DNS zone with TXT record approval
|
||||
// - parent-domain has DNS zone with TXT record approval
|
||||
// - dom
|
||||
//
|
||||
// TXT-Record check:
|
||||
// new InitialDirContext().getAttributes("dns:_netblocks.google.com", new String[] { "TXT"}).get("TXT").getAll();
|
||||
|
@ -0,0 +1,34 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP;
|
||||
|
||||
class HsDomainSmtpSetupHostingAssetValidator extends HostingAssetEntityValidator {
|
||||
|
||||
public static final String IDENTIFIER_SUFFIX = "|SMTP";
|
||||
|
||||
HsDomainSmtpSetupHostingAssetValidator() {
|
||||
super(
|
||||
DOMAIN_SMTP_SETUP,
|
||||
AlarmContact.isOptional(),
|
||||
|
||||
NO_EXTRA_PROPERTIES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) {
|
||||
return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessEntity(final HsHostingAssetEntity entity) {
|
||||
super.preprocessEntity(entity);
|
||||
if (entity.getIdentifier() == null) {
|
||||
ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.hs.validation.ArrayProperty.arrayOf;
|
||||
import static net.hostsharing.hsadminng.hs.validation.StringProperty.stringProperty;
|
||||
|
||||
class HsEMailAddressHostingAssetValidator extends HostingAssetEntityValidator {
|
||||
|
||||
private static final String UNIX_USER_REGEX = "^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9]+)?$"; // also accepts legacy pac-names
|
||||
private static final String EMAIL_ADDRESS_LOCAL_PART_REGEX = "[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+"; // RFC 5322
|
||||
private static final String EMAIL_ADDRESS_DOMAIN_PART_REGEX = "[a-zA-Z0-9.-]+";
|
||||
private static final String EMAIL_ADDRESS_FULL_REGEX = "^" + EMAIL_ADDRESS_LOCAL_PART_REGEX + "@" + EMAIL_ADDRESS_DOMAIN_PART_REGEX + "$";
|
||||
public static final int EMAIL_ADDRESS_MAX_LENGTH = 320; // according to RFC 5321 and RFC 5322
|
||||
|
||||
HsEMailAddressHostingAssetValidator() {
|
||||
super( HsHostingAssetType.EMAIL_ADDRESS,
|
||||
AlarmContact.isOptional(),
|
||||
|
||||
stringProperty("local-part").matchesRegEx("^" + EMAIL_ADDRESS_LOCAL_PART_REGEX + "$").required(),
|
||||
stringProperty("sub-domain").matchesRegEx("^" + EMAIL_ADDRESS_LOCAL_PART_REGEX + "$").optional(),
|
||||
arrayOf(
|
||||
stringProperty("target").maxLength(EMAIL_ADDRESS_MAX_LENGTH).matchesRegEx(UNIX_USER_REGEX, EMAIL_ADDRESS_FULL_REGEX)
|
||||
).required().minLength(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessEntity(final HsHostingAssetEntity entity) {
|
||||
super.preprocessEntity(entity);
|
||||
super.preprocessEntity(entity);
|
||||
if (entity.getIdentifier() == null) {
|
||||
entity.setIdentifier(combineIdentifier(entity));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) {
|
||||
return Pattern.compile("^"+ Pattern.quote(combineIdentifier(assetEntity)) + "$");
|
||||
}
|
||||
|
||||
private static String combineIdentifier(final HsHostingAssetEntity emailAddressAssetEntity) {
|
||||
return emailAddressAssetEntity.getDirectValue("local-part", String.class) +
|
||||
ofNullable(emailAddressAssetEntity.getDirectValue("sub-domain", String.class)).map(s -> "." + s).orElse("") +
|
||||
"@" +
|
||||
emailAddressAssetEntity.getParentAsset().getIdentifier();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user