software.amazon.awssdk
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index 44c8a6d25a..1c5505333d 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -28,6 +28,7 @@ import software.amazon.awssdk.services.neptune.NeptuneClient;
import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.guardduty.GuardDutyClient;
import software.amazon.awssdk.services.fis.FisClient;
+import software.amazon.awssdk.services.organizations.OrganizationsClient;
import software.amazon.awssdk.services.rum.RumClient;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.endpoints.Endpoint;
@@ -259,6 +260,14 @@ public final class TestFixtures {
.build();
}
+ public static OrganizationsClient organizationsClient() {
+ return OrganizationsClient.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(CREDENTIALS)
+ .build();
+ }
+
public static SsmClient ssmClient() {
return SsmClient.builder()
.endpointOverride(ENDPOINT)
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/OrganizationsTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/OrganizationsTest.java
new file mode 100644
index 0000000000..7c89977d5d
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/OrganizationsTest.java
@@ -0,0 +1,268 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.organizations.OrganizationsClient;
+import software.amazon.awssdk.services.organizations.model.Account;
+import software.amazon.awssdk.services.organizations.model.AccessDeniedException;
+import software.amazon.awssdk.services.organizations.model.AwsOrganizationsNotInUseException;
+import software.amazon.awssdk.services.organizations.model.ChildType;
+import software.amazon.awssdk.services.organizations.model.ConstraintViolationException;
+import software.amazon.awssdk.services.organizations.model.CreateAccountState;
+import software.amazon.awssdk.services.organizations.model.CreateAccountStatus;
+import software.amazon.awssdk.services.organizations.model.Handshake;
+import software.amazon.awssdk.services.organizations.model.HandshakeState;
+import software.amazon.awssdk.services.organizations.model.Organization;
+import software.amazon.awssdk.services.organizations.model.OrganizationFeatureSet;
+import software.amazon.awssdk.services.organizations.model.OrganizationalUnit;
+import software.amazon.awssdk.services.organizations.model.OrganizationalUnitNotEmptyException;
+import software.amazon.awssdk.services.organizations.model.Policy;
+import software.amazon.awssdk.services.organizations.model.PolicyInUseException;
+import software.amazon.awssdk.services.organizations.model.PolicyType;
+import software.amazon.awssdk.services.organizations.model.Root;
+import software.amazon.awssdk.services.organizations.model.TargetType;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * Drives the whole Organizations surface through the real AWS SDK, which is the check that
+ * matters for wire compatibility: the SDK does its own request marshalling, response parsing,
+ * id/ARN validation and typed-exception mapping.
+ *
+ * The test tears the organization down at the end so it can be re-run against the same
+ * Floci instance.
+ */
+public class OrganizationsTest {
+
+ private static final String SCP_CONTENT =
+ "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Deny\",\"Action\":\"ec2:*\",\"Resource\":\"*\"}]}";
+ private static final String TAG_POLICY_CONTENT =
+ "{\"tags\":{\"CostCenter\":{\"tag_key\":{\"@@assign\":\"CostCenter\"}}}}";
+
+ private static final String INVITED_ACCOUNT = "987654321098";
+
+ private final OrganizationsClient client = TestFixtures.organizationsClient();
+
+ /** A client whose 12-digit access key id makes Floci treat the caller as that account. */
+ private static OrganizationsClient clientFor(String accountId) {
+ return OrganizationsClient.builder()
+ .endpointOverride(TestFixtures.endpoint())
+ .region(Region.US_EAST_1)
+ .credentialsProvider(StaticCredentialsProvider.create(
+ AwsBasicCredentials.create(accountId, "test")))
+ .build();
+ }
+
+ @Test
+ public void testFullLifecycle() {
+ // 1. Create the organization.
+ Organization organization = client.createOrganization(r -> r.featureSet(OrganizationFeatureSet.ALL))
+ .organization();
+ assertThat(organization.id()).matches("o-[a-z0-9]{10}");
+ assertThat(organization.featureSet()).isEqualTo(OrganizationFeatureSet.ALL);
+ assertThat(organization.arn()).startsWith("arn:aws:organizations::");
+ assertThat(organization.masterAccountId()).isNotBlank();
+
+ String managementAccountId = organization.masterAccountId();
+
+ try {
+ assertThat(client.describeOrganization().organization().id()).isEqualTo(organization.id());
+
+ // 2. The root exists and carries the AWS-managed FullAWSAccess SCP.
+ Root root = client.listRoots().roots().get(0);
+ assertThat(root.id()).matches("r-[a-z0-9]{4}");
+ assertThat(root.name()).isEqualTo("Root");
+ assertThat(root.policyTypes()).anyMatch(p -> p.type() == PolicyType.SERVICE_CONTROL_POLICY);
+
+ assertThat(client.listPoliciesForTarget(r -> r.targetId(root.id())
+ .filter(PolicyType.SERVICE_CONTROL_POLICY)).policies())
+ .anyMatch(p -> p.id().equals("p-FullAWSAccess") && Boolean.TRUE.equals(p.awsManaged()));
+
+ // 3. Build an OU tree.
+ OrganizationalUnit workloads = client.createOrganizationalUnit(r -> r
+ .parentId(root.id()).name("Workloads")).organizationalUnit();
+ assertThat(workloads.id()).matches("ou-[a-z0-9]{4}-[a-z0-9]{8}");
+
+ OrganizationalUnit production = client.createOrganizationalUnit(r -> r
+ .parentId(workloads.id()).name("Production")).organizationalUnit();
+
+ assertThat(client.listOrganizationalUnitsForParent(r -> r.parentId(root.id()))
+ .organizationalUnits()).extracting(OrganizationalUnit::id).containsExactly(workloads.id());
+ assertThat(client.listChildren(r -> r.parentId(workloads.id())
+ .childType(ChildType.ORGANIZATIONAL_UNIT)).children())
+ .singleElement().satisfies(child -> assertThat(child.id()).isEqualTo(production.id()));
+ assertThat(client.listParents(r -> r.childId(production.id())).parents())
+ .singleElement().satisfies(parent -> assertThat(parent.id()).isEqualTo(workloads.id()));
+
+ // 4. Create a member account and move it into the OU.
+ CreateAccountStatus status = client.createAccount(r -> r
+ .email("compat-dev@example.com").accountName("CompatDev")).createAccountStatus();
+ assertThat(status.id()).startsWith("car-");
+ assertThat(status.state()).isEqualTo(CreateAccountState.SUCCEEDED);
+ assertThat(status.accountId()).matches("\\d{12}");
+
+ String memberAccountId = status.accountId();
+ assertThat(client.describeCreateAccountStatus(r -> r.createAccountRequestId(status.id()))
+ .createAccountStatus().accountId()).isEqualTo(memberAccountId);
+
+ Account member = client.describeAccount(r -> r.accountId(memberAccountId)).account();
+ assertThat(member.email()).isEqualTo("compat-dev@example.com");
+ assertThat(member.name()).isEqualTo("CompatDev");
+ assertThat(member.joinedTimestamp()).isNotNull();
+
+ assertThat(client.listAccounts().accounts()).extracting(Account::id)
+ .contains(managementAccountId, memberAccountId);
+
+ client.moveAccount(r -> r.accountId(memberAccountId)
+ .sourceParentId(root.id()).destinationParentId(workloads.id()));
+ assertThat(client.listAccountsForParent(r -> r.parentId(workloads.id())).accounts())
+ .extracting(Account::id).containsExactly(memberAccountId);
+
+ assertThatThrownBy(() -> client.deleteOrganizationalUnit(r -> r
+ .organizationalUnitId(workloads.id())))
+ .isInstanceOf(OrganizationalUnitNotEmptyException.class);
+
+ // 5. Service control policies.
+ Policy scp = client.createPolicy(r -> r.name("CompatDenyEc2").description("Deny EC2")
+ .type(PolicyType.SERVICE_CONTROL_POLICY).content(SCP_CONTENT)).policy();
+ assertThat(scp.policySummary().id()).matches("p-[a-z0-9]{8}");
+ assertThat(scp.content()).isEqualTo(SCP_CONTENT);
+
+ String scpId = scp.policySummary().id();
+ client.attachPolicy(r -> r.policyId(scpId).targetId(workloads.id()));
+
+ assertThat(client.listTargetsForPolicy(r -> r.policyId(scpId)).targets())
+ .singleElement().satisfies(target -> {
+ assertThat(target.targetId()).isEqualTo(workloads.id());
+ assertThat(target.type()).isEqualTo(TargetType.ORGANIZATIONAL_UNIT);
+ assertThat(target.name()).isEqualTo("Workloads");
+ });
+
+ assertThatThrownBy(() -> client.deletePolicy(r -> r.policyId(scpId)))
+ .isInstanceOf(PolicyInUseException.class);
+
+ client.detachPolicy(r -> r.policyId(scpId).targetId(workloads.id()));
+ assertThatThrownBy(() -> client.detachPolicy(r -> r
+ .policyId("p-FullAWSAccess").targetId(workloads.id())))
+ .isInstanceOf(ConstraintViolationException.class);
+ client.deletePolicy(r -> r.policyId(scpId));
+
+ // 6. Tag policies and effective-policy inheritance.
+ client.enablePolicyType(r -> r.rootId(root.id()).policyType(PolicyType.TAG_POLICY));
+ Policy tagPolicy = client.createPolicy(r -> r.name("CompatCostCenter")
+ .type(PolicyType.TAG_POLICY).content(TAG_POLICY_CONTENT)).policy();
+ String tagPolicyId = tagPolicy.policySummary().id();
+ client.attachPolicy(r -> r.policyId(tagPolicyId).targetId(root.id()));
+
+ assertThat(client.describeEffectivePolicy(r -> r
+ .policyType("TAG_POLICY").targetId(memberAccountId)).effectivePolicy())
+ .satisfies(effective -> {
+ assertThat(effective.policyContent()).isEqualTo(TAG_POLICY_CONTENT);
+ assertThat(effective.targetId()).isEqualTo(memberAccountId);
+ assertThat(effective.lastUpdatedTimestamp()).isNotNull();
+ });
+
+ client.detachPolicy(r -> r.policyId(tagPolicyId).targetId(root.id()));
+ client.deletePolicy(r -> r.policyId(tagPolicyId));
+ client.disablePolicyType(r -> r.rootId(root.id()).policyType(PolicyType.TAG_POLICY));
+
+ // 7. Tags.
+ client.tagResource(r -> r.resourceId(memberAccountId)
+ .tags(t -> t.key("team").value("platform")));
+ assertThat(client.listTagsForResource(r -> r.resourceId(memberAccountId)).tags())
+ .singleElement().satisfies(tag -> {
+ assertThat(tag.key()).isEqualTo("team");
+ assertThat(tag.value()).isEqualTo("platform");
+ });
+ client.untagResource(r -> r.resourceId(memberAccountId).tagKeys("team"));
+ assertThat(client.listTagsForResource(r -> r.resourceId(memberAccountId)).tags()).isEmpty();
+
+ // 8. Trusted access and delegated administrators.
+ client.enableAWSServiceAccess(r -> r.servicePrincipal("config.amazonaws.com"));
+ assertThat(client.listAWSServiceAccessForOrganization().enabledServicePrincipals())
+ .singleElement().satisfies(principal -> {
+ assertThat(principal.servicePrincipal()).isEqualTo("config.amazonaws.com");
+ assertThat(principal.dateEnabled()).isNotNull();
+ });
+
+ client.registerDelegatedAdministrator(r -> r.accountId(memberAccountId)
+ .servicePrincipal("config.amazonaws.com"));
+ assertThat(client.listDelegatedAdministrators(r -> r
+ .servicePrincipal("config.amazonaws.com")).delegatedAdministrators())
+ .singleElement().satisfies(admin -> {
+ assertThat(admin.id()).isEqualTo(memberAccountId);
+ assertThat(admin.delegationEnabledDate()).isNotNull();
+ });
+ assertThat(client.listDelegatedServicesForAccount(r -> r.accountId(memberAccountId))
+ .delegatedServices()).singleElement()
+ .satisfies(svc -> assertThat(svc.servicePrincipal()).isEqualTo("config.amazonaws.com"));
+
+ client.deregisterDelegatedAdministrator(r -> r.accountId(memberAccountId)
+ .servicePrincipal("config.amazonaws.com"));
+ client.disableAWSServiceAccess(r -> r.servicePrincipal("config.amazonaws.com"));
+
+ // 9. Resource policy.
+ String resourcePolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ + "\"Principal\":{\"AWS\":\"*\"},\"Action\":\"organizations:Describe*\",\"Resource\":\"*\"}]}";
+ assertThat(client.putResourcePolicy(r -> r.content(resourcePolicy)).resourcePolicy())
+ .satisfies(policy -> {
+ assertThat(policy.resourcePolicySummary().id()).startsWith("rp-");
+ assertThat(policy.content()).isEqualTo(resourcePolicy);
+ });
+ assertThat(client.describeResourcePolicy(r -> { }).resourcePolicy().content())
+ .isEqualTo(resourcePolicy);
+ client.deleteResourcePolicy(r -> { });
+
+ // 10. The invitation handshake, driven from both sides.
+ try (OrganizationsClient invitedClient = clientFor(INVITED_ACCOUNT)) {
+ assertThatThrownBy(invitedClient::describeOrganization)
+ .isInstanceOf(AwsOrganizationsNotInUseException.class);
+
+ Handshake invitation = client.inviteAccountToOrganization(r -> r
+ .target(t -> t.id(INVITED_ACCOUNT).type("ACCOUNT"))
+ .notes("compat suite")).handshake();
+ assertThat(invitation.state()).isEqualTo(HandshakeState.REQUESTED);
+ assertThat(invitation.expirationTimestamp()).isNotNull();
+
+ Handshake accepted = invitedClient.acceptHandshake(r -> r
+ .handshakeId(invitation.id())).handshake();
+ assertThat(accepted.state()).isEqualTo(HandshakeState.ACCEPTED);
+
+ // The member account can now read the organization it belongs to, but not mutate it.
+ assertThat(invitedClient.describeOrganization().organization().id())
+ .isEqualTo(organization.id());
+ assertThatThrownBy(() -> invitedClient.createOrganizationalUnit(r -> r
+ .parentId(root.id()).name("Nope")))
+ .isInstanceOf(AccessDeniedException.class);
+
+ assertThat(client.listHandshakesForOrganization().handshakes())
+ .extracting(Handshake::id).contains(invitation.id());
+
+ invitedClient.leaveOrganization();
+ assertThat(client.listAccounts().accounts())
+ .extracting(Account::id).doesNotContain(INVITED_ACCOUNT);
+ }
+
+ // 11. Tear the organization down.
+ client.removeAccountFromOrganization(r -> r.accountId(memberAccountId));
+ client.deleteOrganizationalUnit(r -> r.organizationalUnitId(production.id()));
+ client.deleteOrganizationalUnit(r -> r.organizationalUnitId(workloads.id()));
+ } finally {
+ // Best effort: if an assertion above failed, the organization may still hold accounts
+ // or OUs and DeleteOrganization will refuse. Swallowing that here keeps the original
+ // assertion failure visible instead of replacing it with a cleanup error.
+ try {
+ client.deleteOrganization();
+ } catch (RuntimeException e) {
+ System.err.println("[WARN] Organizations cleanup failed, leaving the organization "
+ + "in place: " + e.getMessage());
+ }
+ }
+
+ assertThatThrownBy(client::describeOrganization)
+ .isInstanceOf(AwsOrganizationsNotInUseException.class);
+ }
+}
diff --git a/docs/index.md b/docs/index.md
index 3cc3033b45..816cad8925 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -34,6 +34,7 @@ Floci emulates 73 AWS services. See the [Services Overview](services/index.md) f
| Step Functions | JSON 1.1 |
| IAM | Query |
| STS | Query |
+| Organizations | JSON 1.1 |
| ElastiCache (Redis / Valkey) | Query + RESP proxy |
| RDS (PostgreSQL / MySQL) | Query + wire proxy |
| RDS Data API | REST JSON |
diff --git a/docs/services/index.md b/docs/services/index.md
index a79ab8b991..982f3aeba5 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -25,6 +25,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [IAM](iam.md) | `POST /` with `Action=` param | Query | 76 |
| [STS](sts.md) | `POST /` with `Action=` param | Query | 7 |
| [AWS Sign-In](iam.md#aws-sign-in-login-credentials) | `/v1/authorize`, `/v1/token` | REST JSON | 2 |
+| [Organizations](organizations.md) | `POST /` + `X-Amz-Target: AWSOrganizationsV20161128.*` | JSON 1.1 | 55 |
| [Cognito](cognito.md) | `POST /` + `X-Amz-Target: AWSCognitoIdentityProviderService.*` | JSON 1.1 | 43 |
| [KMS](kms.md) | `POST /` + `X-Amz-Target: TrentService.*` | JSON 1.1 | 34 |
| [CloudHSM v2](cloudhsmv2.md) | `POST /` + `X-Amz-Target: BaldrApiService.*` | JSON 1.1 | 18 |
diff --git a/docs/services/organizations.md b/docs/services/organizations.md
new file mode 100644
index 0000000000..70725faf16
--- /dev/null
+++ b/docs/services/organizations.md
@@ -0,0 +1,113 @@
+# Organizations
+
+**Protocol:** JSON 1.1 (`X-Amz-Target: AWSOrganizationsV20161128.*`)
+**Endpoint:** `POST http://localhost:4566/`
+
+Floci emulates the full AWS Organizations control plane: the organization and its root,
+the organizational-unit tree, member accounts, policies of every type, tags, trusted
+service access, delegated administrators, the organization resource policy, and the
+invitation/handshake flow.
+
+## Accounts are real Floci accounts
+
+Floci resolves any 12-digit access key id straight to an AWS account, so an account created
+by `CreateAccount` is immediately usable as a caller identity against every other service:
+
+```bash
+aws --endpoint-url http://localhost:4566 organizations create-organization --feature-set ALL
+aws --endpoint-url http://localhost:4566 organizations create-account \
+ --email dev@example.com --account-name Dev
+# ... then call as that account
+AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY=x \
+ aws --endpoint-url http://localhost:4566 organizations describe-organization
+```
+
+## Management account vs member accounts
+
+Authorization mirrors AWS. Every mutating action is restricted to the **management account**
+— the account that called `CreateOrganization` — and returns `AccessDeniedException` otherwise.
+Member accounts can read the organization they belong to (`DescribeOrganization`, `ListRoots`,
+`ListParents`, `DescribeAccount`, `DescribePolicy`), act on handshakes addressed to them, and
+call `LeaveOrganization`. An account in no organization gets
+`AWSOrganizationsNotInUseException`.
+
+## Behaviour notes
+
+- The AWS-managed `p-FullAWSAccess` SCP is created with the organization and attached to the
+ root, every new OU and every new account. Detaching the last service control policy from a
+ target is rejected with `ConstraintViolationException`, as on AWS.
+- A `CONSOLIDATED_BILLING` organization has no available policy types. `EnableAllFeatures`
+ promotes it to `ALL`; with no member accounts the handshake completes immediately. With member
+ accounts it stays `REQUESTED` until one of them calls `AcceptHandshake` — AWS requires *every*
+ member to approve, which Floci simplifies to the first acceptance.
+- `CreateAccount` returns a `CreateAccountStatus` you can poll with
+ `DescribeCreateAccountStatus`, matching the asynchronous AWS contract. A duplicate email
+ produces `State=FAILED` with `FailureReason=EMAIL_ALREADY_EXISTS` rather than an error.
+- `DescribeEffectivePolicy` merges every policy of the requested type down the
+ root → OU → target chain, with the closest ancestor winning on conflicting keys. As on AWS,
+ the access-control types (`SERVICE_CONTROL_POLICY`, `RESOURCE_CONTROL_POLICY`) are rejected.
+- Handshakes expire 15 days after they are created and report `EXPIRED` from then on.
+- Organizations ARNs are global and carry no region:
+ `arn:aws:organizations::123456789012:organization/o-abc1234567`.
+
+## Supported Actions
+
+
+| Action | Description |
+| --- | --- |
+| `CreateOrganization` | Creates an organization with the calling account as the management account. |
+| `DescribeOrganization` | Returns information about the organization the calling account belongs to. |
+| `DeleteOrganization` | Deletes the organization; only the management account may remain in it. |
+| `EnableAllFeatures` | Upgrades a consolidated-billing organization to all features via a handshake. |
+| `ListRoots` | Lists the roots defined in the organization. |
+| `CreateOrganizationalUnit` | Creates an OU under the specified root or parent OU. |
+| `UpdateOrganizationalUnit` | Renames the specified organizational unit. |
+| `DeleteOrganizationalUnit` | Deletes an organizational unit that contains no accounts or child OUs. |
+| `DescribeOrganizationalUnit` | Returns information about the specified organizational unit. |
+| `ListOrganizationalUnitsForParent` | Lists the OUs directly under the specified root or parent OU. |
+| `ListParents` | Lists the parent of the specified account or organizational unit. |
+| `ListChildren` | Lists the accounts or OUs directly under the specified root or parent OU. |
+| `CreateAccount` | Creates a member account in the organization and returns its request status. |
+| `CreateGovCloudAccount` | Creates a member account together with a linked AWS GovCloud (US) account. |
+| `DescribeCreateAccountStatus` | Returns the status of an account-creation request. |
+| `ListCreateAccountStatus` | Lists account-creation requests, optionally filtered by state. |
+| `DescribeAccount` | Returns information about the specified member account. |
+| `ListAccounts` | Lists every account in the organization. |
+| `ListAccountsForParent` | Lists the accounts directly under the specified root or OU. |
+| `MoveAccount` | Moves an account from one root or OU to another. |
+| `RemoveAccountFromOrganization` | Removes a member account from the organization. |
+| `LeaveOrganization` | Removes the calling member account from its organization. |
+| `CloseAccount` | Closes a member account, moving it to PENDING_CLOSURE. |
+| `CreatePolicy` | Creates a policy of the specified type in the organization. |
+| `UpdatePolicy` | Updates the name, description or content of a customer-managed policy. |
+| `DeletePolicy` | Deletes a policy that is not attached to any target. |
+| `DescribePolicy` | Returns a policy's summary and content. |
+| `ListPolicies` | Lists the policies of the specified type in the organization. |
+| `AttachPolicy` | Attaches a policy to a root, organizational unit or account. |
+| `DetachPolicy` | Detaches a policy from a root, organizational unit or account. |
+| `ListPoliciesForTarget` | Lists the policies of a given type attached directly to a target. |
+| `ListTargetsForPolicy` | Lists the roots, OUs and accounts a policy is attached to. |
+| `EnablePolicyType` | Enables a policy type on the specified root. |
+| `DisablePolicyType` | Disables a policy type on the specified root. |
+| `DescribeEffectivePolicy` | Returns the merged policy of the given type that applies to a target. |
+| `TagResource` | Adds or overwrites tags on a root, OU, account or policy. |
+| `UntagResource` | Removes the specified tags from a root, OU, account or policy. |
+| `ListTagsForResource` | Lists the tags on a root, OU, account or policy. |
+| `EnableAWSServiceAccess` | Enables trusted access for an AWS service principal. |
+| `DisableAWSServiceAccess` | Disables trusted access for an AWS service principal. |
+| `ListAWSServiceAccessForOrganization` | Lists the service principals with trusted access enabled. |
+| `RegisterDelegatedAdministrator` | Registers a member account as a delegated administrator for a service. |
+| `DeregisterDelegatedAdministrator` | Removes a member account's delegated administrator role for a service. |
+| `ListDelegatedAdministrators` | Lists the delegated administrators in the organization. |
+| `ListDelegatedServicesForAccount` | Lists the services a member account is a delegated administrator for. |
+| `PutResourcePolicy` | Creates or updates the organization's resource policy. |
+| `DescribeResourcePolicy` | Returns the organization's resource policy. |
+| `DeleteResourcePolicy` | Deletes the organization's resource policy. |
+| `InviteAccountToOrganization` | Sends an invitation handshake to an account or email address. |
+| `AcceptHandshake` | Accepts a handshake, joining the organization for an invitation. |
+| `DeclineHandshake` | Declines a handshake addressed to the calling account. |
+| `CancelHandshake` | Cancels an open handshake the calling account originated. |
+| `DescribeHandshake` | Returns information about the specified handshake. |
+| `ListHandshakesForAccount` | Lists the handshakes that involve the calling account. |
+| `ListHandshakesForOrganization` | Lists the handshakes associated with the organization. |
+
diff --git a/mkdocs.yml b/mkdocs.yml
index cc4925c3d9..a5c9fdc9b6 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -97,6 +97,7 @@ nav:
- SWF: services/swf.md
- IAM: services/iam.md
- STS: services/sts.md
+ - Organizations: services/organizations.md
- ElastiCache: services/elasticache.md
- MemoryDB: services/memorydb.md
- RDS: services/rds.md
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index d6ef0b2241..734958b721 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -634,6 +634,7 @@ public interface EmulatorConfig {
IotServiceConfig iot();
IotDataServiceConfig iotdata();
CloudHsmV2ServiceConfig cloudhsmv2();
+ OrganizationsServiceConfig organizations();
RumServiceConfig rum();
GuardDutyServiceConfig guardduty();
EmrServerlessServiceConfig emrserverless();
@@ -1205,6 +1206,11 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface OrganizationsServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface AthenaServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
index 4f0e470f52..3d368eccf9 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
@@ -40,6 +40,7 @@ import io.github.hectorvent.floci.services.kinesis.KinesisJsonHandler;
import io.github.hectorvent.floci.services.kinesisanalytics.KinesisAnalyticsV2JsonHandler;
import io.github.hectorvent.floci.services.kms.KmsJsonHandler;
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerJsonHandler;
+import io.github.hectorvent.floci.services.organizations.OrganizationsJsonHandler;
import io.github.hectorvent.floci.services.ssm.Ec2MessagesJsonHandler;
import io.github.hectorvent.floci.services.ssm.SsmJsonHandler;
import jakarta.inject.Inject;
@@ -105,6 +106,7 @@ public class AwsJson11Controller {
private final CloudControlJsonHandler cloudControlJsonHandler;
private final ApplicationAutoScalingJsonHandler applicationAutoScalingJsonHandler;
private final CloudHsmV2JsonHandler cloudHsmV2JsonHandler;
+ private final OrganizationsJsonHandler organizationsJsonHandler;
@Inject
public AwsJson11Controller(ObjectMapper objectMapper, ResolvedServiceCatalog catalog,
@@ -141,7 +143,8 @@ public class AwsJson11Controller {
LightsailJsonHandler lightsailJsonHandler,
CloudControlJsonHandler cloudControlJsonHandler,
ApplicationAutoScalingJsonHandler applicationAutoScalingJsonHandler,
- CloudHsmV2JsonHandler cloudHsmV2JsonHandler){
+ CloudHsmV2JsonHandler cloudHsmV2JsonHandler,
+ OrganizationsJsonHandler organizationsJsonHandler){
this.objectMapper = objectMapper;
this.strictBodyReader = objectMapper.reader().with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
this.catalog = catalog;
@@ -183,6 +186,7 @@ public class AwsJson11Controller {
this.cloudControlJsonHandler = cloudControlJsonHandler;
this.applicationAutoScalingJsonHandler = applicationAutoScalingJsonHandler;
this.cloudHsmV2JsonHandler = cloudHsmV2JsonHandler;
+ this.organizationsJsonHandler = organizationsJsonHandler;
}
@POST
@@ -255,6 +259,10 @@ public class AwsJson11Controller {
case "lightsail" -> lightsailJsonHandler.handle(action, request, region);
case "cloudcontrol" -> cloudControlJsonHandler.handle(action, request, region);
case "cloudhsmv2" -> cloudHsmV2JsonHandler.handle(action, request, region);
+ // Organizations is global and account-scoped rather than region-scoped: every
+ // action is authorized against the calling account, so pass that instead of region.
+ case "organizations" ->
+ organizationsJsonHandler.handle(action, request, regionResolver.getAccountId());
default -> null;
};
// catalog.matchTarget is protocol-agnostic: a JSON 1.0 target
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index ca6ee2b7ca..65162ed85b 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -476,6 +476,10 @@ public class ResolvedServiceCatalog {
"cloudhsmv2", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
Set.of("BaldrApiService."), Set.of("cloudhsm"), Set.of(), Set.of()),
+ descriptor("organizations", "organizations", config.services().organizations().enabled(), true,
+ "organizations", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
+ protocols(ServiceProtocol.JSON),
+ Set.of("AWSOrganizationsV20161128."), Set.of("organizations"), Set.of(), Set.of()),
descriptor("rum", "rum", config.services().rum().enabled(), true,
"rum", storageMode(config.storage().services().rum().mode(), config.storage().mode()),
config.storage().services().rum().flushIntervalMs(), null, ServiceProtocol.REST_JSON,
diff --git a/src/main/java/io/github/hectorvent/floci/services/organizations/OrganizationsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/organizations/OrganizationsJsonHandler.java
new file mode 100644
index 0000000000..fd4ab3926e
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/organizations/OrganizationsJsonHandler.java
@@ -0,0 +1,756 @@
+package io.github.hectorvent.floci.services.organizations;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.JsonErrorResponseUtils;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.Pagination;
+import io.github.hectorvent.floci.services.organizations.model.CreateAccountStatus;
+import io.github.hectorvent.floci.services.organizations.model.Handshake;
+import io.github.hectorvent.floci.services.organizations.model.HandshakeParty;
+import io.github.hectorvent.floci.services.organizations.model.HandshakeResource;
+import io.github.hectorvent.floci.services.organizations.model.Organization;
+import io.github.hectorvent.floci.services.organizations.model.OrganizationAccount;
+import io.github.hectorvent.floci.services.organizations.model.OrganizationPolicy;
+import io.github.hectorvent.floci.services.organizations.model.OrganizationalUnit;
+import io.github.hectorvent.floci.services.organizations.model.PolicyTypeSummary;
+import io.github.hectorvent.floci.services.organizations.model.Root;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Response;
+import org.jboss.logging.Logger;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+/**
+ * AWS Organizations JSON 1.1 handler. Dispatched from
+ * {@link io.github.hectorvent.floci.core.common.AwsJson11Controller} under the
+ * {@code AWSOrganizationsV20161128.} target prefix.
+ *
+ * The handler is deliberately thin: it parses the request, delegates to
+ * {@link OrganizationsService}, and renders the AWS response shape. All validation and
+ * authorization lives in the service.
+ */
+@ApplicationScoped
+public class OrganizationsJsonHandler {
+
+ private static final Logger LOG = Logger.getLogger(OrganizationsJsonHandler.class);
+
+ /** AWS caps MaxResults at 20 across the Organizations list operations. */
+ private static final int MAX_PAGE = 20;
+
+ private static final String PAGINATION_ERROR = "InvalidInputException";
+
+ private final OrganizationsService service;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public OrganizationsJsonHandler(OrganizationsService service, ObjectMapper objectMapper) {
+ this.service = service;
+ this.objectMapper = objectMapper;
+ }
+
+ public Response handle(String action, JsonNode request, String callerAccountId) {
+ LOG.debugv("Organizations action: {0}", action);
+ try {
+ return switch (action) {
+ case "CreateOrganization" -> createOrganization(request, callerAccountId);
+ case "DescribeOrganization" -> describeOrganization(callerAccountId);
+ case "DeleteOrganization" -> deleteOrganization(callerAccountId);
+ case "EnableAllFeatures" -> enableAllFeatures(callerAccountId);
+ case "ListRoots" -> listRoots(request, callerAccountId);
+ case "CreateOrganizationalUnit" -> createOrganizationalUnit(request, callerAccountId);
+ case "UpdateOrganizationalUnit" -> updateOrganizationalUnit(request, callerAccountId);
+ case "DeleteOrganizationalUnit" -> deleteOrganizationalUnit(request, callerAccountId);
+ case "DescribeOrganizationalUnit" -> describeOrganizationalUnit(request, callerAccountId);
+ case "ListOrganizationalUnitsForParent" -> listOrganizationalUnitsForParent(request, callerAccountId);
+ case "ListParents" -> listParents(request, callerAccountId);
+ case "ListChildren" -> listChildren(request, callerAccountId);
+ case "CreateAccount" -> createAccount(request, callerAccountId, false);
+ case "CreateGovCloudAccount" -> createAccount(request, callerAccountId, true);
+ case "DescribeCreateAccountStatus" -> describeCreateAccountStatus(request, callerAccountId);
+ case "ListCreateAccountStatus" -> listCreateAccountStatus(request, callerAccountId);
+ case "DescribeAccount" -> describeAccount(request, callerAccountId);
+ case "ListAccounts" -> listAccounts(request, callerAccountId);
+ case "ListAccountsForParent" -> listAccountsForParent(request, callerAccountId);
+ case "MoveAccount" -> moveAccount(request, callerAccountId);
+ case "RemoveAccountFromOrganization" -> removeAccountFromOrganization(request, callerAccountId);
+ case "LeaveOrganization" -> leaveOrganization(callerAccountId);
+ case "CloseAccount" -> closeAccount(request, callerAccountId);
+ case "CreatePolicy" -> createPolicy(request, callerAccountId);
+ case "UpdatePolicy" -> updatePolicy(request, callerAccountId);
+ case "DeletePolicy" -> deletePolicy(request, callerAccountId);
+ case "DescribePolicy" -> describePolicy(request, callerAccountId);
+ case "ListPolicies" -> listPolicies(request, callerAccountId);
+ case "AttachPolicy" -> attachPolicy(request, callerAccountId);
+ case "DetachPolicy" -> detachPolicy(request, callerAccountId);
+ case "ListPoliciesForTarget" -> listPoliciesForTarget(request, callerAccountId);
+ case "ListTargetsForPolicy" -> listTargetsForPolicy(request, callerAccountId);
+ case "EnablePolicyType" -> enablePolicyType(request, callerAccountId);
+ case "DisablePolicyType" -> disablePolicyType(request, callerAccountId);
+ case "DescribeEffectivePolicy" -> describeEffectivePolicy(request, callerAccountId);
+ case "TagResource" -> tagResource(request, callerAccountId);
+ case "UntagResource" -> untagResource(request, callerAccountId);
+ case "ListTagsForResource" -> listTagsForResource(request, callerAccountId);
+ case "EnableAWSServiceAccess" -> enableAwsServiceAccess(request, callerAccountId);
+ case "DisableAWSServiceAccess" -> disableAwsServiceAccess(request, callerAccountId);
+ case "ListAWSServiceAccessForOrganization" ->
+ listAwsServiceAccessForOrganization(request, callerAccountId);
+ case "RegisterDelegatedAdministrator" -> registerDelegatedAdministrator(request, callerAccountId);
+ case "DeregisterDelegatedAdministrator" -> deregisterDelegatedAdministrator(request, callerAccountId);
+ case "ListDelegatedAdministrators" -> listDelegatedAdministrators(request, callerAccountId);
+ case "ListDelegatedServicesForAccount" -> listDelegatedServicesForAccount(request, callerAccountId);
+ case "PutResourcePolicy" -> putResourcePolicy(request, callerAccountId);
+ case "DescribeResourcePolicy" -> describeResourcePolicy(callerAccountId);
+ case "DeleteResourcePolicy" -> deleteResourcePolicy(callerAccountId);
+ case "InviteAccountToOrganization" -> inviteAccountToOrganization(request, callerAccountId);
+ case "AcceptHandshake" -> acceptHandshake(request, callerAccountId);
+ case "DeclineHandshake" -> declineHandshake(request, callerAccountId);
+ case "CancelHandshake" -> cancelHandshake(request, callerAccountId);
+ case "DescribeHandshake" -> describeHandshake(request, callerAccountId);
+ case "ListHandshakesForAccount" -> listHandshakesForAccount(request, callerAccountId);
+ case "ListHandshakesForOrganization" -> listHandshakesForOrganization(request, callerAccountId);
+ default -> JsonErrorResponseUtils.createUnknownOperationErrorResponse(
+ "AWSOrganizationsV20161128." + action);
+ };
+ } catch (AwsException e) {
+ return JsonErrorResponseUtils.createErrorResponse(e);
+ } catch (Exception e) {
+ LOG.errorf(e, "Organizations error processing action %s", action);
+ return JsonErrorResponseUtils.createErrorResponse(e);
+ }
+ }
+
+ // ──────────────────────────── Organization lifecycle ────────────────────────────
+
+ private Response createOrganization(JsonNode request, String caller) {
+ Organization organization = service.createOrganization(caller, text(request, "FeatureSet"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Organization", organizationNode(organization));
+ return Response.ok(response).build();
+ }
+
+ private Response describeOrganization(String caller) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Organization", organizationNode(service.describeOrganization(caller)));
+ return Response.ok(response).build();
+ }
+
+ private Response deleteOrganization(String caller) {
+ service.deleteOrganization(caller);
+ return empty();
+ }
+
+ private Response enableAllFeatures(String caller) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Handshake", handshakeNode(service.enableAllFeatures(caller)));
+ return Response.ok(response).build();
+ }
+
+ private Response listRoots(JsonNode request, String caller) {
+ PaginatedResult page = page(service.listRoots(caller), Root::getId, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode roots = response.putArray("Roots");
+ page.items().forEach(root -> roots.add(rootNode(root)));
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Organizational units ────────────────────────────
+
+ private Response createOrganizationalUnit(JsonNode request, String caller) {
+ OrganizationalUnit unit = service.createOrganizationalUnit(caller,
+ text(request, "ParentId"), text(request, "Name"), parseTags(request.path("Tags")));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("OrganizationalUnit", organizationalUnitNode(unit));
+ return Response.ok(response).build();
+ }
+
+ private Response updateOrganizationalUnit(JsonNode request, String caller) {
+ OrganizationalUnit unit = service.updateOrganizationalUnit(caller,
+ text(request, "OrganizationalUnitId"), text(request, "Name"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("OrganizationalUnit", organizationalUnitNode(unit));
+ return Response.ok(response).build();
+ }
+
+ private Response deleteOrganizationalUnit(JsonNode request, String caller) {
+ service.deleteOrganizationalUnit(caller, text(request, "OrganizationalUnitId"));
+ return empty();
+ }
+
+ private Response describeOrganizationalUnit(JsonNode request, String caller) {
+ OrganizationalUnit unit = service.describeOrganizationalUnit(caller, text(request, "OrganizationalUnitId"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("OrganizationalUnit", organizationalUnitNode(unit));
+ return Response.ok(response).build();
+ }
+
+ private Response listOrganizationalUnitsForParent(JsonNode request, String caller) {
+ List all = service.listOrganizationalUnitsForParent(caller, text(request, "ParentId"));
+ PaginatedResult page = page(all, OrganizationalUnit::getId, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode units = response.putArray("OrganizationalUnits");
+ page.items().forEach(unit -> units.add(organizationalUnitNode(unit)));
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ private Response listParents(JsonNode request, String caller) {
+ List all = service.listParents(caller, text(request, "ChildId"));
+ PaginatedResult page =
+ page(all, OrganizationsService.ParentRef::id, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode parents = response.putArray("Parents");
+ page.items().forEach(parent -> {
+ ObjectNode node = parents.addObject();
+ node.put("Id", parent.id());
+ node.put("Type", parent.type());
+ });
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ private Response listChildren(JsonNode request, String caller) {
+ List all =
+ service.listChildren(caller, text(request, "ParentId"), text(request, "ChildType"));
+ PaginatedResult page = page(all, OrganizationsService.ChildRef::id, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode children = response.putArray("Children");
+ page.items().forEach(child -> {
+ ObjectNode node = children.addObject();
+ node.put("Id", child.id());
+ node.put("Type", child.type());
+ });
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Accounts ────────────────────────────
+
+ private Response createAccount(JsonNode request, String caller, boolean govCloud) {
+ CreateAccountStatus status = service.createAccount(caller,
+ text(request, "Email"), text(request, "AccountName"), parseTags(request.path("Tags")), govCloud);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("CreateAccountStatus", createAccountStatusNode(status));
+ return Response.ok(response).build();
+ }
+
+ private Response describeCreateAccountStatus(JsonNode request, String caller) {
+ CreateAccountStatus status =
+ service.describeCreateAccountStatus(caller, text(request, "CreateAccountRequestId"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("CreateAccountStatus", createAccountStatusNode(status));
+ return Response.ok(response).build();
+ }
+
+ private Response listCreateAccountStatus(JsonNode request, String caller) {
+ List all = service.listCreateAccountStatus(caller, parseStringList(request.path("States")));
+ PaginatedResult page = page(all, CreateAccountStatus::getId, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode statuses = response.putArray("CreateAccountStatuses");
+ page.items().forEach(status -> statuses.add(createAccountStatusNode(status)));
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ private Response describeAccount(JsonNode request, String caller) {
+ OrganizationAccount account = service.describeAccount(caller, text(request, "AccountId"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Account", accountNode(account));
+ return Response.ok(response).build();
+ }
+
+ private Response listAccounts(JsonNode request, String caller) {
+ PaginatedResult page =
+ page(service.listAccounts(caller), OrganizationAccount::getId, request);
+ return accountsResponse(page);
+ }
+
+ private Response listAccountsForParent(JsonNode request, String caller) {
+ List all = service.listAccountsForParent(caller, text(request, "ParentId"));
+ return accountsResponse(page(all, OrganizationAccount::getId, request));
+ }
+
+ private Response accountsResponse(PaginatedResult page) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode accounts = response.putArray("Accounts");
+ page.items().forEach(account -> accounts.add(accountNode(account)));
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ private Response moveAccount(JsonNode request, String caller) {
+ service.moveAccount(caller, text(request, "AccountId"),
+ text(request, "SourceParentId"), text(request, "DestinationParentId"));
+ return empty();
+ }
+
+ private Response removeAccountFromOrganization(JsonNode request, String caller) {
+ service.removeAccountFromOrganization(caller, text(request, "AccountId"));
+ return empty();
+ }
+
+ private Response leaveOrganization(String caller) {
+ service.leaveOrganization(caller);
+ return empty();
+ }
+
+ private Response closeAccount(JsonNode request, String caller) {
+ service.closeAccount(caller, text(request, "AccountId"));
+ return empty();
+ }
+
+ // ──────────────────────────── Policies ────────────────────────────
+
+ private Response createPolicy(JsonNode request, String caller) {
+ OrganizationPolicy policy = service.createPolicy(caller,
+ text(request, "Content"), text(request, "Description"), text(request, "Name"),
+ text(request, "Type"), parseTags(request.path("Tags")));
+ return policyResponse(policy);
+ }
+
+ private Response updatePolicy(JsonNode request, String caller) {
+ OrganizationPolicy policy = service.updatePolicy(caller, text(request, "PolicyId"),
+ text(request, "Name"), text(request, "Description"), text(request, "Content"));
+ return policyResponse(policy);
+ }
+
+ private Response deletePolicy(JsonNode request, String caller) {
+ service.deletePolicy(caller, text(request, "PolicyId"));
+ return empty();
+ }
+
+ private Response describePolicy(JsonNode request, String caller) {
+ return policyResponse(service.describePolicy(caller, text(request, "PolicyId")));
+ }
+
+ private Response policyResponse(OrganizationPolicy policy) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ObjectNode node = response.putObject("Policy");
+ node.set("PolicySummary", policySummaryNode(policy));
+ node.put("Content", policy.getContent());
+ return Response.ok(response).build();
+ }
+
+ private Response listPolicies(JsonNode request, String caller) {
+ List all = service.listPolicies(caller, text(request, "Filter"));
+ return policiesResponse(page(all, OrganizationPolicy::getId, request));
+ }
+
+ private Response listPoliciesForTarget(JsonNode request, String caller) {
+ List all =
+ service.listPoliciesForTarget(caller, text(request, "TargetId"), text(request, "Filter"));
+ return policiesResponse(page(all, OrganizationPolicy::getId, request));
+ }
+
+ private Response policiesResponse(PaginatedResult page) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode policies = response.putArray("Policies");
+ page.items().forEach(policy -> policies.add(policySummaryNode(policy)));
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ private Response attachPolicy(JsonNode request, String caller) {
+ service.attachPolicy(caller, text(request, "PolicyId"), text(request, "TargetId"));
+ return empty();
+ }
+
+ private Response detachPolicy(JsonNode request, String caller) {
+ service.detachPolicy(caller, text(request, "PolicyId"), text(request, "TargetId"));
+ return empty();
+ }
+
+ private Response listTargetsForPolicy(JsonNode request, String caller) {
+ List all =
+ service.listTargetsForPolicy(caller, text(request, "PolicyId"));
+ PaginatedResult page =
+ page(all, OrganizationsService.PolicyTarget::targetId, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode targets = response.putArray("Targets");
+ page.items().forEach(target -> {
+ ObjectNode node = targets.addObject();
+ node.put("TargetId", target.targetId());
+ node.put("Arn", target.arn());
+ node.put("Name", target.name());
+ node.put("Type", target.type());
+ });
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ private Response enablePolicyType(JsonNode request, String caller) {
+ Root root = service.enablePolicyType(caller, text(request, "RootId"), text(request, "PolicyType"));
+ return rootResponse(root);
+ }
+
+ private Response disablePolicyType(JsonNode request, String caller) {
+ Root root = service.disablePolicyType(caller, text(request, "RootId"), text(request, "PolicyType"));
+ return rootResponse(root);
+ }
+
+ private Response rootResponse(Root root) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Root", rootNode(root));
+ return Response.ok(response).build();
+ }
+
+ private Response describeEffectivePolicy(JsonNode request, String caller) {
+ OrganizationsService.EffectivePolicy effective =
+ service.describeEffectivePolicy(caller, text(request, "PolicyType"), text(request, "TargetId"));
+ ObjectNode response = objectMapper.createObjectNode();
+ ObjectNode node = response.putObject("EffectivePolicy");
+ node.put("PolicyContent", effective.policyContent());
+ node.put("PolicyType", effective.policyType());
+ node.put("TargetId", effective.targetId());
+ putTimestamp(node, "LastUpdatedTimestamp", effective.lastUpdatedTimestamp());
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Tags ────────────────────────────
+
+ private Response tagResource(JsonNode request, String caller) {
+ service.tagResource(caller, text(request, "ResourceId"), parseTags(request.path("Tags")));
+ return empty();
+ }
+
+ private Response untagResource(JsonNode request, String caller) {
+ service.untagResource(caller, text(request, "ResourceId"), parseStringList(request.path("TagKeys")));
+ return empty();
+ }
+
+ private Response listTagsForResource(JsonNode request, String caller) {
+ Map tags = service.listTagsForResource(caller, text(request, "ResourceId"));
+ List> entries = new ArrayList<>(tags.entrySet());
+ PaginatedResult> page = page(entries, Map.Entry::getKey, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode array = response.putArray("Tags");
+ page.items().forEach(entry -> {
+ ObjectNode node = array.addObject();
+ node.put("Key", entry.getKey());
+ node.put("Value", entry.getValue());
+ });
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Trusted access and delegation ────────────────────────────
+
+ private Response enableAwsServiceAccess(JsonNode request, String caller) {
+ service.enableAWSServiceAccess(caller, text(request, "ServicePrincipal"));
+ return empty();
+ }
+
+ private Response disableAwsServiceAccess(JsonNode request, String caller) {
+ service.disableAWSServiceAccess(caller, text(request, "ServicePrincipal"));
+ return empty();
+ }
+
+ private Response listAwsServiceAccessForOrganization(JsonNode request, String caller) {
+ List all =
+ service.listAWSServiceAccessForOrganization(caller);
+ PaginatedResult page =
+ page(all, OrganizationsService.EnabledServicePrincipal::servicePrincipal, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode principals = response.putArray("EnabledServicePrincipals");
+ page.items().forEach(principal -> {
+ ObjectNode node = principals.addObject();
+ node.put("ServicePrincipal", principal.servicePrincipal());
+ putTimestamp(node, "DateEnabled", principal.dateEnabled());
+ });
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ private Response registerDelegatedAdministrator(JsonNode request, String caller) {
+ service.registerDelegatedAdministrator(caller, text(request, "AccountId"), text(request, "ServicePrincipal"));
+ return empty();
+ }
+
+ private Response deregisterDelegatedAdministrator(JsonNode request, String caller) {
+ service.deregisterDelegatedAdministrator(caller, text(request, "AccountId"), text(request, "ServicePrincipal"));
+ return empty();
+ }
+
+ private Response listDelegatedAdministrators(JsonNode request, String caller) {
+ String servicePrincipal = text(request, "ServicePrincipal");
+ List all = service.listDelegatedAdministrators(caller, servicePrincipal);
+ PaginatedResult page = page(all, OrganizationAccount::getId, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode administrators = response.putArray("DelegatedAdministrators");
+ page.items().forEach(account -> {
+ ObjectNode node = accountNode(account);
+ Instant enabled = servicePrincipal != null
+ ? account.getDelegatedServices().get(servicePrincipal)
+ : account.getDelegatedServices().values().stream().findFirst().orElse(null);
+ putTimestamp(node, "DelegationEnabledDate", enabled);
+ administrators.add(node);
+ });
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ private Response listDelegatedServicesForAccount(JsonNode request, String caller) {
+ List all =
+ service.listDelegatedServicesForAccount(caller, text(request, "AccountId"));
+ PaginatedResult page =
+ page(all, OrganizationsService.DelegatedService::servicePrincipal, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode services = response.putArray("DelegatedServices");
+ page.items().forEach(delegated -> {
+ ObjectNode node = services.addObject();
+ node.put("ServicePrincipal", delegated.servicePrincipal());
+ putTimestamp(node, "DelegationEnabledDate", delegated.delegationEnabledDate());
+ });
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Resource policy ────────────────────────────
+
+ private Response putResourcePolicy(JsonNode request, String caller) {
+ OrganizationsService.ResourcePolicyView policy =
+ service.putResourcePolicy(caller, text(request, "Content"), parseTags(request.path("Tags")));
+ return resourcePolicyResponse(policy);
+ }
+
+ private Response describeResourcePolicy(String caller) {
+ return resourcePolicyResponse(service.describeResourcePolicy(caller));
+ }
+
+ private Response deleteResourcePolicy(String caller) {
+ service.deleteResourcePolicy(caller);
+ return empty();
+ }
+
+ private Response resourcePolicyResponse(OrganizationsService.ResourcePolicyView policy) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ObjectNode node = response.putObject("ResourcePolicy");
+ ObjectNode summary = node.putObject("ResourcePolicySummary");
+ summary.put("Id", policy.id());
+ summary.put("Arn", policy.arn());
+ node.put("Content", policy.content());
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Handshakes ────────────────────────────
+
+ private Response inviteAccountToOrganization(JsonNode request, String caller) {
+ JsonNode target = request.path("Target");
+ Handshake handshake = service.inviteAccountToOrganization(caller,
+ text(target, "Id"), text(target, "Type"), text(request, "Notes"));
+ return handshakeResponse(handshake);
+ }
+
+ private Response acceptHandshake(JsonNode request, String caller) {
+ return handshakeResponse(service.acceptHandshake(caller, text(request, "HandshakeId")));
+ }
+
+ private Response declineHandshake(JsonNode request, String caller) {
+ return handshakeResponse(service.declineHandshake(caller, text(request, "HandshakeId")));
+ }
+
+ private Response cancelHandshake(JsonNode request, String caller) {
+ return handshakeResponse(service.cancelHandshake(caller, text(request, "HandshakeId")));
+ }
+
+ private Response describeHandshake(JsonNode request, String caller) {
+ return handshakeResponse(service.describeHandshake(caller, text(request, "HandshakeId")));
+ }
+
+ private Response handshakeResponse(Handshake handshake) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Handshake", handshakeNode(handshake));
+ return Response.ok(response).build();
+ }
+
+ private Response listHandshakesForAccount(JsonNode request, String caller) {
+ JsonNode filter = request.path("Filter");
+ List all = service.listHandshakesForAccount(caller,
+ parseStringList(filter.path("States")), text(filter, "ActionType"));
+ return handshakesResponse(page(all, Handshake::getId, request));
+ }
+
+ private Response listHandshakesForOrganization(JsonNode request, String caller) {
+ JsonNode filter = request.path("Filter");
+ List all = service.listHandshakesForOrganization(caller,
+ parseStringList(filter.path("States")), text(filter, "ActionType"));
+ return handshakesResponse(page(all, Handshake::getId, request));
+ }
+
+ private Response handshakesResponse(PaginatedResult page) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode handshakes = response.putArray("Handshakes");
+ page.items().forEach(handshake -> handshakes.add(handshakeNode(handshake)));
+ putNextToken(response, page.nextToken());
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Response shapes ────────────────────────────
+
+ private ObjectNode organizationNode(Organization organization) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", organization.getId());
+ node.put("Arn", organization.getArn());
+ node.put("FeatureSet", organization.getFeatureSet());
+ node.put("MasterAccountArn", organization.getMasterAccountArn());
+ node.put("MasterAccountId", organization.getMasterAccountId());
+ node.put("MasterAccountEmail", organization.getMasterAccountEmail());
+ ArrayNode policyTypes = node.putArray("AvailablePolicyTypes");
+ organization.getRoot().getPolicyTypes().forEach(summary -> policyTypes.add(policyTypeNode(summary)));
+ return node;
+ }
+
+ private ObjectNode rootNode(Root root) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", root.getId());
+ node.put("Arn", root.getArn());
+ node.put("Name", root.getName());
+ ArrayNode policyTypes = node.putArray("PolicyTypes");
+ root.getPolicyTypes().forEach(summary -> policyTypes.add(policyTypeNode(summary)));
+ return node;
+ }
+
+ private ObjectNode policyTypeNode(PolicyTypeSummary summary) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Type", summary.getType());
+ node.put("Status", summary.getStatus());
+ return node;
+ }
+
+ private ObjectNode organizationalUnitNode(OrganizationalUnit unit) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", unit.getId());
+ node.put("Arn", unit.getArn());
+ node.put("Name", unit.getName());
+ return node;
+ }
+
+ private ObjectNode accountNode(OrganizationAccount account) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", account.getId());
+ node.put("Arn", account.getArn());
+ node.put("Email", account.getEmail());
+ node.put("Name", account.getName());
+ node.put("Status", account.getStatus());
+ node.put("JoinedMethod", account.getJoinedMethod());
+ putTimestamp(node, "JoinedTimestamp", account.getJoinedTimestamp());
+ return node;
+ }
+
+ private ObjectNode policySummaryNode(OrganizationPolicy policy) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", policy.getId());
+ node.put("Arn", policy.getArn());
+ node.put("Name", policy.getName());
+ node.put("Description", policy.getDescription() == null ? "" : policy.getDescription());
+ node.put("Type", policy.getType());
+ node.put("AwsManaged", policy.isAwsManaged());
+ return node;
+ }
+
+ private ObjectNode createAccountStatusNode(CreateAccountStatus status) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", status.getId());
+ node.put("AccountName", status.getAccountName());
+ node.put("State", status.getState());
+ putTimestamp(node, "RequestedTimestamp", status.getRequestedTimestamp());
+ putTimestamp(node, "CompletedTimestamp", status.getCompletedTimestamp());
+ if (status.getAccountId() != null) {
+ node.put("AccountId", status.getAccountId());
+ }
+ if (status.getGovCloudAccountId() != null) {
+ node.put("GovCloudAccountId", status.getGovCloudAccountId());
+ }
+ if (status.getFailureReason() != null) {
+ node.put("FailureReason", status.getFailureReason());
+ }
+ return node;
+ }
+
+ private ObjectNode handshakeNode(Handshake handshake) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", handshake.getId());
+ node.put("Arn", handshake.getArn());
+ node.put("State", handshake.getState());
+ node.put("Action", handshake.getAction());
+ putTimestamp(node, "RequestedTimestamp", handshake.getRequestedTimestamp());
+ putTimestamp(node, "ExpirationTimestamp", handshake.getExpirationTimestamp());
+ ArrayNode parties = node.putArray("Parties");
+ for (HandshakeParty party : handshake.getParties()) {
+ ObjectNode partyNode = parties.addObject();
+ partyNode.put("Id", party.getId());
+ partyNode.put("Type", party.getType());
+ }
+ ArrayNode resources = node.putArray("Resources");
+ handshake.getResources().forEach(resource -> resources.add(handshakeResourceNode(resource)));
+ return node;
+ }
+
+ private ObjectNode handshakeResourceNode(HandshakeResource resource) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Value", resource.getValue());
+ node.put("Type", resource.getType());
+ if (!resource.getResources().isEmpty()) {
+ ArrayNode nested = node.putArray("Resources");
+ resource.getResources().forEach(child -> nested.add(handshakeResourceNode(child)));
+ }
+ return node;
+ }
+
+ // ──────────────────────────── Parsing helpers ────────────────────────────
+
+ private PaginatedResult page(List all, Function cursorOf, JsonNode request) {
+ Integer maxResults = request.hasNonNull("MaxResults") ? request.get("MaxResults").asInt() : null;
+ return Pagination.paginate(all, cursorOf, maxResults, text(request, "NextToken"), MAX_PAGE, PAGINATION_ERROR);
+ }
+
+ private void putNextToken(ObjectNode response, String nextToken) {
+ if (nextToken != null) {
+ response.put("NextToken", nextToken);
+ }
+ }
+
+ private void putTimestamp(ObjectNode node, String field, Instant timestamp) {
+ if (timestamp != null) {
+ node.put(field, timestamp.toEpochMilli() / 1000.0);
+ }
+ }
+
+ private Response empty() {
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private static String text(JsonNode node, String field) {
+ JsonNode value = node.path(field);
+ return value.isMissingNode() || value.isNull() ? null : value.asText();
+ }
+
+ /** Organizations sends tags as a list of {@code {Key, Value}} objects, not a map. */
+ private static Map parseTags(JsonNode node) {
+ if (node == null || !node.isArray()) {
+ return null;
+ }
+ Map tags = new LinkedHashMap<>();
+ node.forEach(entry -> tags.put(entry.path("Key").asText(), entry.path("Value").asText("")));
+ return tags;
+ }
+
+ private static List parseStringList(JsonNode node) {
+ if (node == null || !node.isArray()) {
+ return null;
+ }
+ List values = new ArrayList<>();
+ node.forEach(entry -> values.add(entry.asText()));
+ return values;
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/organizations/OrganizationsService.java b/src/main/java/io/github/hectorvent/floci/services/organizations/OrganizationsService.java
new file mode 100644
index 0000000000..346954b096
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/organizations/OrganizationsService.java
@@ -0,0 +1,1667 @@
+package io.github.hectorvent.floci.services.organizations;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.organizations.model.CreateAccountStatus;
+import io.github.hectorvent.floci.services.organizations.model.Handshake;
+import io.github.hectorvent.floci.services.organizations.model.HandshakeParty;
+import io.github.hectorvent.floci.services.organizations.model.HandshakeResource;
+import io.github.hectorvent.floci.services.organizations.model.Organization;
+import io.github.hectorvent.floci.services.organizations.model.OrganizationAccount;
+import io.github.hectorvent.floci.services.organizations.model.OrganizationPolicy;
+import io.github.hectorvent.floci.services.organizations.model.OrganizationalUnit;
+import io.github.hectorvent.floci.services.organizations.model.PolicyTypeSummary;
+import io.github.hectorvent.floci.services.organizations.model.Root;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.security.SecureRandom;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.regex.Pattern;
+
+/**
+ * AWS Organizations service implementation for the local emulator.
+ *
+ * Organizations is a global, inherently cross-account service, which shapes how state is
+ * stored here. Every record lives under the management account's storage prefix via the
+ * explicit {@code *ForAccount} methods on {@link AccountAwareStorageBackend}, never via the
+ * request-context-derived {@code get}/{@code put}. That is deliberate: a member account calling
+ * {@code DescribeOrganization} has a different request account than the one that owns the data,
+ * so binding reads to the caller's prefix would make the organization invisible to exactly the
+ * callers AWS expects to see it. The caller's account id is used for authorization
+ * ({@link #requireManagementAccount} vs {@link #requireOrganizationForCaller}) rather than for
+ * addressing storage.
+ *
+ * @see AWS Organizations API Reference
+ */
+@ApplicationScoped
+public class OrganizationsService {
+
+ private static final Logger LOG = Logger.getLogger(OrganizationsService.class);
+
+ private static final String ID_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
+
+ static final String FULL_AWS_ACCESS_POLICY_ID = "p-FullAWSAccess";
+ private static final String FULL_AWS_ACCESS_CONTENT =
+ "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}]}";
+
+ static final String SERVICE_CONTROL_POLICY = "SERVICE_CONTROL_POLICY";
+ private static final String RESOURCE_CONTROL_POLICY = "RESOURCE_CONTROL_POLICY";
+
+ /**
+ * Policy types AWS accepts on CreatePolicy and Enable/DisablePolicyType.
+ *
+ *
Declared as an ordered {@link List} because the validation error message renders it:
+ * {@code Set.of}'s iteration order is unspecified and salted per JVM run, so joining a set
+ * would make the same rejection read differently from one run to the next. The companion
+ * {@code *_SET} keeps membership checks O(1).
+ */
+ private static final List POLICY_TYPES = List.of(
+ SERVICE_CONTROL_POLICY,
+ RESOURCE_CONTROL_POLICY,
+ "TAG_POLICY",
+ "BACKUP_POLICY",
+ "AISERVICES_OPT_OUT_POLICY",
+ "CHATBOT_POLICY",
+ "DECLARATIVE_POLICY_EC2",
+ "SECURITYHUB_POLICY");
+
+ private static final Set POLICY_TYPE_SET = Set.copyOf(POLICY_TYPES);
+
+ /**
+ * {@code DescribeEffectivePolicy} is defined only for the inheritable policy types. AWS
+ * rejects the two access-control types outright — they are evaluated as a deny-by-intersection
+ * chain rather than merged into a single effective document, so there is nothing to return.
+ */
+ private static final List EFFECTIVE_POLICY_TYPES = List.of(
+ "TAG_POLICY",
+ "BACKUP_POLICY",
+ "AISERVICES_OPT_OUT_POLICY",
+ "CHATBOT_POLICY",
+ "DECLARATIVE_POLICY_EC2",
+ "SECURITYHUB_POLICY");
+
+ private static final Set EFFECTIVE_POLICY_TYPE_SET = Set.copyOf(EFFECTIVE_POLICY_TYPES);
+
+ private static final String FEATURE_SET_ALL = "ALL";
+ private static final String FEATURE_SET_CONSOLIDATED_BILLING = "CONSOLIDATED_BILLING";
+
+ private static final String STATUS_ACTIVE = "ACTIVE";
+ private static final String STATUS_PENDING_CLOSURE = "PENDING_CLOSURE";
+
+ private static final String HANDSHAKE_REQUESTED = "REQUESTED";
+ private static final String HANDSHAKE_ACCEPTED = "ACCEPTED";
+ private static final String HANDSHAKE_DECLINED = "DECLINED";
+ private static final String HANDSHAKE_CANCELED = "CANCELED";
+ private static final String HANDSHAKE_EXPIRED = "EXPIRED";
+ private static final String HANDSHAKE_INVITE = "INVITE";
+ private static final String HANDSHAKE_ENABLE_ALL_FEATURES = "ENABLE_ALL_FEATURES";
+
+ /** AWS holds an unaccepted handshake open for 15 days. */
+ private static final int HANDSHAKE_TTL_DAYS = 15;
+
+ private static final Pattern ACCOUNT_ID_PATTERN = Pattern.compile("\\d{12}");
+ private static final Pattern ROOT_ID_PATTERN = Pattern.compile("r-[0-9a-z]{4,32}");
+ private static final Pattern OU_ID_PATTERN = Pattern.compile("ou-[0-9a-z]{4,32}-[0-9a-z]{8,32}");
+ private static final Pattern POLICY_ID_PATTERN = Pattern.compile("p-[0-9a-zA-Z_]{8,128}");
+ private static final Pattern EMAIL_PATTERN = Pattern.compile("[^\\s@]+@[^\\s@]+\\.[^\\s@]+");
+ private static final Pattern SERVICE_PRINCIPAL_PATTERN = Pattern.compile("[\\w+=,.@-]{1,128}");
+
+ private static final int MAX_ACCOUNT_NAME_LENGTH = 50;
+ private static final int MAX_OU_NAME_LENGTH = 128;
+ private static final int MAX_POLICY_NAME_LENGTH = 128;
+ private static final int MAX_POLICY_DESCRIPTION_LENGTH = 512;
+ private static final int MAX_TAG_KEY_LENGTH = 128;
+ private static final int MAX_TAG_VALUE_LENGTH = 256;
+
+ private final SecureRandom random = new SecureRandom();
+ private final ObjectMapper objectMapper;
+
+ private final AccountAwareStorageBackend organizations;
+ private final AccountAwareStorageBackend accounts;
+ private final AccountAwareStorageBackend organizationalUnits;
+ private final AccountAwareStorageBackend policies;
+ private final AccountAwareStorageBackend createAccountStatuses;
+ private final AccountAwareStorageBackend handshakes;
+
+ @Inject
+ public OrganizationsService(StorageFactory storageFactory, ObjectMapper objectMapper) {
+ this.objectMapper = objectMapper;
+ this.organizations = storageFactory.create("organizations", "organizations-organizations.json",
+ new TypeReference