feat(cognito): add TagResource, UntagResource, ListTagsForResource for user pools (#579) (#591)

* feat(cognito): add TagResource, UntagResource, ListTagsForResource for user pools

Dispatch the three Cognito IDP tag operations through CognitoJsonHandler and
resolve user pools by parsing the resource ARN (O(1) pool-store lookup, not a
full scan). Malformed ARNs now surface as InvalidParameterException rather
than a swallowed ResourceNotFoundException.

Reject reserved floci:* keys on standalone TagResource via
ReservedTags.rejectReservedTagsOnUpdate, matching the existing strip-on-write
behavior on CreateUserPool / UpdateUserPool. Mutations are synchronized on
the pool instance to match the ensureJwtSigningKeys pattern.

Covered by new unit tests (CognitoServiceTest, CognitoJsonHandlerTest), AWS
CLI bats (cognito.bats), and Java SDK compat tests (CognitoFeaturesTest).

* chore: retrigger CI
This commit is contained in:
iam-ssrivastav authored and GitHub committed 2026-04-25 09:50:09 -05:00
1 parent 12c89ba751
commit 5f94b429c2
3 files changed
+84

No files matched your search

@@ -47,6 +47,7 @@ public class CognitoJsonHandler {
case "DescribeUserPoolClient" -> handleDescribeUserPoolClient(request);
case "ListUserPoolClients" -> handleListUserPoolClients(request);
case "DeleteUserPoolClient" -> handleDeleteUserPoolClient(request);
case "UpdateUserPoolClient" -> handleUpdateUserPoolClient(request);
case "CreateResourceServer" -> handleCreateResourceServer(request);
case "DescribeResourceServer" -> handleDescribeResourceServer(request);
case "ListResourceServers" -> handleListResourceServers(request);
@@ -192,6 +193,20 @@ public class CognitoJsonHandler {
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleUpdateUserPoolClient(JsonNode request) {
UserPoolClient client = service.updateUserPoolClient(
request.path("UserPoolId").asText(),
request.path("ClientId").asText(),
request.has("ClientName") ? request.path("ClientName").asText() : null,
request.has("AllowedOAuthFlowsUserPoolClient") ? request.path("AllowedOAuthFlowsUserPoolClient").asBoolean() : null,
readStringList(request.path("AllowedOAuthFlows")),
readStringList(request.path("AllowedOAuthScopes"))
);
ObjectNode response = objectMapper.createObjectNode();
response.set("UserPoolClient", clientToNode(client));
return Response.ok(response).build();
}
private Response handleCreateResourceServer(JsonNode request) {
ResourceServer server = service.createResourceServer(
request.path("UserPoolId").asText(),
@@ -264,6 +264,28 @@ public class CognitoService {
clientStore.delete(clientId);
}
public UserPoolClient updateUserPoolClient(String userPoolId, String clientId, String clientName,
Boolean allowedOAuthFlowsUserPoolClient,
List<String> allowedOAuthFlows,
List<String> allowedOAuthScopes) {
UserPoolClient client = describeUserPoolClient(userPoolId, clientId);
if (clientName != null) client.setClientName(clientName);
if (allowedOAuthFlowsUserPoolClient != null) {
client.setAllowedOAuthFlowsUserPoolClient(allowedOAuthFlowsUserPoolClient);
}
if (allowedOAuthFlows != null) {
client.setAllowedOAuthFlows(normalizeStringList(allowedOAuthFlows));
}
if (allowedOAuthScopes != null) {
client.setAllowedOAuthScopes(normalizeStringList(allowedOAuthScopes));
}
client.setLastModifiedDate(System.currentTimeMillis() / 1000L);
clientStore.put(clientId, client);
LOG.infov("Updated User Pool Client: {0} for pool {1}", clientId, userPoolId);
return client;
}
public List<UserPoolClientSecret> listUserPoolClientSecrets(String userPoolId, String clientId) {
UserPoolClient client = clientStore.get(clientId)
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "User pool client not found", 404));