fix(ses): serve the POST list bindings and Filter of ListEmailIdentities and ListConfigurationSets (#5010)

* fix(ses): serve the POST list bindings and Filter of ListEmailIdentities and ListConfigurationSets

Since AWS SDK for Java 2.55.8 and botocore 1.43.105 the SES v2 model sends
ListEmailIdentities as POST /v2/email/list-identities and ListConfigurationSets
as POST /v2/email/list-configuration-sets, each with a new Filter member.
Floci only served the GET bindings, so these lists failed for current SDKs.

Both lists now answer on both bindings. The filter follows real SES, probed
on 2026-10-03: what it matches, its validation messages and their precedence,
and a NextToken that continues only the filter it was taken with. The filter
is applied before the page is cut, so filtered pages are exact.

* fix(ses): bind identity list tokens to an unambiguous filter scope

A name filter of "null" produced the same token scope as an absent name, so a
token from one filter continued the other. The scope now leads with the type
and status, which never hold the separator, and ends with the name. The name
filter also runs before the status refresh, so domains it excludes are not
checked against Route 53.

* docs(ses): mark the GET list bindings as the pre-Filter ones
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-03 15:52:01 -04:00
1 parent 9c49ecf255
commit 32f2788c9c
10 files changed
+722 -9

No files matched your search

@@ -35,14 +35,18 @@ import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
import java.util.List;
import java.util.Map;
import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse;
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseOptionString;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseSuppressedReasons;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
/**
* SES V2 configuration-set endpoints ({@code /v2/email/configuration-sets}), including the event
@@ -141,14 +145,41 @@ public class SesConfigurationSetController {
}
}
/**
* The binding SDKs sent before the Filter member moved this operation to POST (AWS SDK for Java
* 2.55.8, botocore 1.43.105). It is gone from the model, but SES still answers it (probed
* 2026-10-03), so it stays for older SDKs and takes no filter.
*/
@GET
@Path("/configuration-sets")
public Response listConfigurationSets(@Context HttpHeaders headers,
@QueryParam("PageSize") String pageSize,
@QueryParam("NextToken") String nextToken) {
String region = regionResolver.resolveRegion(headers);
PaginatedResult<ConfigurationSet> page = configSetService.list(region,
SesListPaging.V2_LIST_CONFIGURATION_SETS, SesListPaging.parseQueryPageSize(pageSize), nextToken);
return configurationSetsPage(configSetService.listV2(region, null,
SesListPaging.parseQueryPageSize(pageSize), nextToken));
}
/**
* The binding SDKs use since the Filter member was added. Unlike ListEmailIdentities, SES
* ignores a key it does not know and treats an empty name as no filter (probed 2026-10-03).
*/
@POST
@Path("/list-configuration-sets")
public Response listConfigurationSetsWithFilter(@Context HttpHeaders headers, String body) {
String region = regionResolver.resolveRegion(headers);
JsonNode request = readOptionBody(objectMapper, body);
Map<String, String> filter = stringMapMemberOrAbsent(request, "Filter");
Integer pageSize = intMemberOrAbsent(request, "PageSize");
String nextToken = stringMemberOrAbsent(request, "NextToken");
String nameContains = filter == null ? null : filter.get("CONFIGURATION_SET_NAME_CONTAINS");
if (nameContains != null && nameContains.isEmpty()) {
nameContains = null;
}
return configurationSetsPage(configSetService.listV2(region, nameContains, pageSize, nextToken));
}
private Response configurationSetsPage(PaginatedResult<ConfigurationSet> page) {
ObjectNode result = objectMapper.createObjectNode();
ArrayNode arr = result.putArray("ConfigurationSets");
for (ConfigurationSet cs : page.items()) {
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -142,6 +143,31 @@ public class SesConfigurationSetService {
.toList();
}
/**
* ListConfigurationSets with a name filter, probed 2026-10-03: SES checks the page size, the
* name, then the token. The name is not trimmed and is found anywhere in a set's name without
* regard to case, and a token is bound to it. A null name lists every set.
*/
public PaginatedResult<ConfigurationSet> listV2(String region, String nameContains, Integer pageSize,
String nextToken) {
SesListPaging paging = SesListPaging.V2_LIST_CONFIGURATION_SETS;
if (nameContains == null) {
return list(region, paging, pageSize, nextToken);
}
// Validated here as well as in page() so the size error wins over the name's length.
paging.pageSize(pageSize);
int length = nameContains.codePointCount(0, nameContains.length());
if (length < 3 || length > 64) {
throw new AwsException("BadRequestException",
"CONFIGURATION_SET_NAME_CONTAINS must be between 3 and 64 characters", 400);
}
String name = nameContains.toLowerCase(Locale.ROOT);
List<ConfigurationSet> matching = list(region).stream()
.filter(cs -> cs.getName().toLowerCase(Locale.ROOT).contains(name))
.toList();
return paging.page(region, name, matching, ConfigurationSet::getName, pageSize, nextToken);
}
/** The raw removal; existence and the tenant delete-guard are the facade's orchestration. */
public void remove(String name, String region) {
configSetStore.delete(configSetKey(region, name));
@@ -26,16 +26,21 @@ import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse;
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireFilterKeysAndValues;
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireObjectOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
/**
* SES V2 email-identity endpoints ({@code /v2/email/identities}), including the sending
@@ -52,6 +57,10 @@ public class SesIdentityController {
private static final Logger LOG = Logger.getLogger(SesIdentityController.class);
/** In the order SES prints them when it refuses a key. */
private static final List<String> IDENTITY_FILTER_KEYS =
List.of("IDENTITY_NAME_CONTAINS", "VERIFICATION_STATUS", "IDENTITY_TYPE");
private final SesIdentityService identityService;
private final SesService sesService;
private final RegionResolver regionResolver;
@@ -123,14 +132,44 @@ public class SesIdentityController {
}
}
/**
* The binding SDKs sent before the Filter member moved this operation to POST (AWS SDK for Java
* 2.55.8, botocore 1.43.105). It is gone from the model, but SES still answers it (probed
* 2026-10-03), so it stays for older SDKs and takes no filter.
*/
@GET
@Path("/identities")
public Response listEmailIdentities(@Context HttpHeaders headers,
@QueryParam("PageSize") String pageSize,
@QueryParam("NextToken") String nextToken) {
String region = regionResolver.resolveRegion(headers);
PaginatedResult<Identity> page = identityService.listIdentities(null, region,
SesListPaging.V2_LIST_EMAIL_IDENTITIES, SesListPaging.parseQueryPageSize(pageSize), nextToken);
return emailIdentitiesPage(region, Map.of(), SesListPaging.parseQueryPageSize(pageSize), nextToken);
}
/** The binding SDKs use since the Filter member was added. */
@POST
@Path("/list-identities")
public Response listEmailIdentitiesWithFilter(@Context HttpHeaders headers, String body) {
String region = regionResolver.resolveRegion(headers);
JsonNode request = readOptionBody(objectMapper, body);
Map<String, String> filter = stringMapMemberOrAbsent(request, "Filter");
Integer pageSize = intMemberOrAbsent(request, "PageSize");
String nextToken = stringMemberOrAbsent(request, "NextToken");
Map<String, String> present = new LinkedHashMap<>();
if (filter != null) {
requireFilterKeysAndValues(filter, IDENTITY_FILTER_KEYS);
filter.forEach((key, value) -> {
if (value != null) {
present.put(key, value);
}
});
}
return emailIdentitiesPage(region, present, pageSize, nextToken);
}
private Response emailIdentitiesPage(String region, Map<String, String> filter, Integer pageSize,
String nextToken) {
PaginatedResult<Identity> page = identityService.listV2Identities(region, filter, pageSize, nextToken);
ObjectNode result = objectMapper.createObjectNode();
ArrayNode items = result.putArray("EmailIdentities");
@@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -207,6 +208,90 @@ public class SesIdentityService {
.toList();
}
/**
* ListEmailIdentities, probed 2026-10-03. The controller has already checked the filter's keys
* and values; SES then checks the page size, the name, the type and the status, and last the
* token. The name is trimmed and found anywhere in the identity without regard to case, the keys
* combine, and a token is bound to the filter it came from, though not to the name's case.
*/
public PaginatedResult<Identity> listV2Identities(String region, Map<String, String> filter,
Integer pageSize, String nextToken) {
SesListPaging paging = filter.isEmpty()
? SesListPaging.V2_LIST_EMAIL_IDENTITIES
: SesListPaging.V2_LIST_EMAIL_IDENTITIES_FILTERED;
// Validated here as well as in page() so the size error wins over the filter's values.
paging.pageSize(pageSize);
String name = v2FilterName(filter.get("IDENTITY_NAME_CONTAINS"));
String type = v2FilterType(filter.get("IDENTITY_TYPE"));
String status = v2FilterStatus(filter.get("VERIFICATION_STATUS"));
List<Identity> matching = listIdentities(type, region).stream()
.filter(i -> name == null || i.getIdentity().toLowerCase(Locale.ROOT).contains(name))
.map(i -> status == null ? i : withCurrentStatus(i, region))
.filter(i -> status == null || status.equals(i.getVerificationStatus()))
.toList();
// The name goes last: the type and status values never hold the separator, so no name can
// pass for another filter.
String scope = filter.isEmpty() ? ""
: Objects.toString(type, "") + "/" + Objects.toString(status, "") + "/" + Objects.toString(name, "");
return paging.page(region, scope, matching, Identity::getIdentity, pageSize, nextToken);
}
/** Only a domain that is not yet verified can still change status, through its DKIM records. */
private Identity withCurrentStatus(Identity identity, String region) {
if ("Domain".equals(identity.getIdentityType()) && !"Success".equals(identity.getVerificationStatus())) {
Identity refreshed = refreshIdentityState(identity, region);
return refreshed == null ? identity : refreshed;
}
return identity;
}
private static String v2FilterName(String value) {
if (value == null) {
return null;
}
String name = value.trim();
int length = name.codePointCount(0, name.length());
if (length < 3) {
throw new AwsException("BadRequestException",
"Filter IDENTITY_NAME_CONTAINS must be at least 3 characters.", 400);
}
if (length > 320) {
throw new AwsException("BadRequestException",
"Filter IDENTITY_NAME_CONTAINS must be at most 320 characters.", 400);
}
return name.toLowerCase(Locale.ROOT);
}
/** MANAGED_DOMAIN is in the model's enum, but SES refuses it as a filter. */
private static String v2FilterType(String value) {
if (value == null) {
return null;
}
return switch (value) {
case "EMAIL_ADDRESS" -> "EmailAddress";
case "DOMAIN" -> "Domain";
default -> throw new AwsException("BadRequestException",
"Invalid identity type <" + value + "> in filter.", 400);
};
}
/** SES maps NOT_STARTED to its own name before refusing it, and words that refusal differently. */
private static String v2FilterStatus(String value) {
if (value == null) {
return null;
}
return switch (value) {
case "PENDING" -> "Pending";
case "SUCCESS" -> "Success";
case "FAILED" -> "Failed";
case "TEMPORARY_FAILURE" -> "TemporaryFailure";
case "NOT_STARTED" -> throw new AwsException("BadRequestException",
"Invalid verification status <NotStarted>.", 400);
default -> throw new AwsException("BadRequestException",
"Invalid verification status <" + value + "> in filter.", 400);
};
}
public List<String> getVerifiedEmailAddresses(String region) {
List<Identity> all = identityStore.scan(k -> k.startsWith(keyPrefix(region)));
List<String> emails = new ArrayList<>();
@@ -32,11 +32,20 @@ public enum SesListPaging {
false),
V2_LIST_EMAIL_IDENTITIES(Namespace.IDENTITY, 25, 1000,
size -> badRequest("Value " + size + " for parameter PageSize is invalid. "
+ "PageSize must be between 1 and 1000."),
SesListPaging::emailIdentitiesPageSizeError,
token -> badRequest("Invalid NextToken <" + token + ">."),
false),
/**
* ListEmailIdentities with a Filter (probed 2026-10-03): the same list, but a token SES refuses
* is answered without echoing it. Only a token from another filter could be observed; a token
* that is not one at all is taken to be refused the same way.
*/
V2_LIST_EMAIL_IDENTITIES_FILTERED(Namespace.IDENTITY, 25, 1000,
SesListPaging::emailIdentitiesPageSizeError,
token -> badRequest("Invalid NextToken."),
false),
/** 195 identities came back whole without a MaxItems, so the default is taken to be the bound. */
V1_LIST_IDENTITIES(Namespace.IDENTITY, 1000, 1000,
size -> invalidParameterValue("Value " + size + " for parameter MaxItems is invalid. "
@@ -311,6 +320,11 @@ public enum SesListPaging {
}
}
private static AwsException emailIdentitiesPageSizeError(int size) {
return badRequest("Value " + size + " for parameter PageSize is invalid. "
+ "PageSize must be between 1 and 1000.");
}
private static AwsException badRequest(String message) {
return new AwsException("BadRequestException", message, 400);
}
@@ -9,8 +9,10 @@ import io.github.hectorvent.floci.services.ses.model.Tag;
import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* Helpers shared by the SES v2 REST JSON controllers: body and member shape checks that answer
@@ -181,6 +183,41 @@ final class SesV2Json {
throw unexpectedStartError(node);
}
/**
* A string-to-string map member, such as a list operation's {@code Filter}: absent or null is
* null, a null value is kept as null so a key check still sees its key, and a value of another
* JSON type gets the deserializer's message for it.
*/
static Map<String, String> stringMapMemberOrAbsent(JsonNode parent, String field) {
JsonNode node = structureMemberOrAbsent(parent, field);
if (node.isMissingNode() || node.isNull()) {
return null;
}
Map<String, String> values = new LinkedHashMap<>();
for (Map.Entry<String, JsonNode> entry : node.properties()) {
values.put(entry.getKey(), typedStringMemberOrAbsent(node, entry.getKey()));
}
return values;
}
/**
* The model's own constraints on a {@code Filter} map, as the SES validation layer reports them:
* every key in the enum, listed in the order SES prints it, and no empty value. A key is checked
* before a value.
*/
static void requireFilterKeysAndValues(Map<String, String> filter, List<String> keys) {
if (!keys.containsAll(filter.keySet())) {
throw new AwsException("BadRequestException", "1 validation error detected: Value at 'filter' "
+ "failed to satisfy constraint: Map keys must satisfy constraint: "
+ "[Member must satisfy enum value set: [" + String.join(", ", keys) + "]]", 400);
}
if (filter.containsValue("")) {
throw new AwsException("BadRequestException", "1 validation error detected: Value at 'filter' "
+ "failed to satisfy constraint: Map value must satisfy constraint: "
+ "[Member must have length greater than or equal to 1]", 400);
}
}
static AwsException unexpectedStartError(JsonNode node) {
if (node.isArray()) {
return new AwsException("SerializationException",