Light, fluffy, and always free - The AWS Local Emulator alternative
feat(iam): implement CreateLoginProfile, UpdateLoginProfile, DeleteLoginProfile (#3865)
Priamo Germosene190f7d340d1
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/IamTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/IamTest.javaindex c160346ea4..20a49a9da4 100644--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/IamTest.java+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/IamTest.java@@ -12,6 +12,8 @@ import software.amazon.awssdk.services.iam.model.CreateGroupRequest;import software.amazon.awssdk.services.iam.model.CreateGroupResponse;import software.amazon.awssdk.services.iam.model.CreateInstanceProfileRequest;import software.amazon.awssdk.services.iam.model.CreateInstanceProfileResponse;+import software.amazon.awssdk.services.iam.model.CreateLoginProfileRequest;+import software.amazon.awssdk.services.iam.model.CreateLoginProfileResponse;import software.amazon.awssdk.services.iam.model.CreatePolicyRequest;import software.amazon.awssdk.services.iam.model.CreatePolicyResponse;import software.amazon.awssdk.services.iam.model.CreateRoleRequest;@@ -21,6 +23,7 @@ import software.amazon.awssdk.services.iam.model.CreateUserResponse;import software.amazon.awssdk.services.iam.model.DeleteAccessKeyRequest;import software.amazon.awssdk.services.iam.model.DeleteGroupRequest;import software.amazon.awssdk.services.iam.model.DeleteInstanceProfileRequest;+import software.amazon.awssdk.services.iam.model.DeleteLoginProfileRequest;import software.amazon.awssdk.services.iam.model.DeletePolicyRequest;import software.amazon.awssdk.services.iam.model.DeleteRoleRequest;import software.amazon.awssdk.services.iam.model.DeleteRolePolicyRequest;@@ -33,6 +36,8 @@ import software.amazon.awssdk.services.iam.model.GetGroupRequest;import software.amazon.awssdk.services.iam.model.GetGroupResponse;import software.amazon.awssdk.services.iam.model.GetInstanceProfileRequest;import software.amazon.awssdk.services.iam.model.GetInstanceProfileResponse;+import software.amazon.awssdk.services.iam.model.GetLoginProfileRequest;+import software.amazon.awssdk.services.iam.model.GetLoginProfileResponse;import software.amazon.awssdk.services.iam.model.GetPolicyRequest;import software.amazon.awssdk.services.iam.model.GetPolicyResponse;import software.amazon.awssdk.services.iam.model.GetPolicyVersionRequest;@@ -69,6 +74,7 @@ import software.amazon.awssdk.services.iam.model.StatusType;import software.amazon.awssdk.services.iam.model.TagUserRequest;import software.amazon.awssdk.services.iam.model.UntagUserRequest;import software.amazon.awssdk.services.iam.model.UpdateAccessKeyRequest;+import software.amazon.awssdk.services.iam.model.UpdateLoginProfileRequest;import java.net.URLDecoder;import java.nio.charset.StandardCharsets;@@ -95,6 +101,7 @@ class IamTest {+ "\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";private static final String POLICY_DOCUMENT = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","+ "\"Action\":\"s3:GetObject\",\"Resource\":\"*\"}]}";+ private static final String LOGIN_PROFILE_PASSWORD = "Sdk-Test-P4ssword!";private static String policyArn;private static String accessKeyId;@@ -533,6 +540,54 @@ class IamTest {.anyMatch(p -> INSTANCE_PROFILE_NAME.equals(p.instanceProfileName()));}+ // ── Login Profile ──────────────────────────────────────────────────++ @Test+ @Order(39)+ void createLoginProfile() {+ CreateLoginProfileResponse response = iam.createLoginProfile(CreateLoginProfileRequest.builder()+ .userName(USER_NAME).password(LOGIN_PROFILE_PASSWORD).passwordResetRequired(false).build());++ assertThat(response.loginProfile().userName()).isEqualTo(USER_NAME);+ assertThat(response.loginProfile().passwordResetRequired()).isFalse();+ assertThat(response.loginProfile().createDate()).isNotNull();+ }++ @Test+ @Order(40)+ void getLoginProfile() {+ GetLoginProfileResponse response = iam.getLoginProfile(GetLoginProfileRequest.builder()+ .userName(USER_NAME).build());++ assertThat(response.loginProfile().userName()).isEqualTo(USER_NAME);+ assertThat(response.loginProfile().passwordResetRequired()).isFalse();+ }++ @Test+ @Order(41)+ void updateLoginProfile() {+ iam.updateLoginProfile(UpdateLoginProfileRequest.builder()+ .userName(USER_NAME).passwordResetRequired(true).build());++ GetLoginProfileResponse response = iam.getLoginProfile(GetLoginProfileRequest.builder()+ .userName(USER_NAME).build());+ assertThat(response.loginProfile().passwordResetRequired()).isTrue();+ }++ @Test+ @Order(42)+ void deleteLoginProfile() {+ iam.deleteLoginProfile(DeleteLoginProfileRequest.builder().userName(USER_NAME).build());+ }++ @Test+ @Order(43)+ void getLoginProfileAfterDeleteThrows() {+ assertThatThrownBy(() -> iam.getLoginProfile(GetLoginProfileRequest.builder()+ .userName(USER_NAME).build()))+ .isInstanceOf(NoSuchEntityException.class);+ }+// ── Error Cases ────────────────────────────────────────────────────@Testdiff --git a/docs/services/iam.md b/docs/services/iam.mdindex 7a2665bf28..96ed462100 100644--- a/docs/services/iam.md+++ b/docs/services/iam.md@@ -239,9 +239,31 @@ nothing here performs the TLS handshake they describe.| Action | Description ||--------|-------------|-| CreateLoginProfile | Creates a password login profile for a user. |+| CreateLoginProfile | Creates a console password login profile for a user. |+| GetLoginProfile | Returns a user's login profile. |+| UpdateLoginProfile | Updates a user's login profile password and/or reset-required flag. || DeleteLoginProfile | Deletes a user's login profile. |-| UpdateLoginProfile | Updates a user's login profile password settings. |++`UserName` is optional on `CreateLoginProfile`, `GetLoginProfile` and `DeleteLoginProfile`: it+defaults to the user resolved from the signing access key, the same fallback `GetUser` uses. It is+required on `UpdateLoginProfile`, matching the AWS API.++A user holds at most one login profile: `CreateLoginProfile` on a user that already has one+returns `EntityAlreadyExists`; `Get`/`Update`/`DeleteLoginProfile` on a user with none return+`NoSuchEntity`. `Password` is required on `CreateLoginProfile` and optional on+`UpdateLoginProfile`; an omitted field on `UpdateLoginProfile` (`Password` or+`PasswordResetRequired`) leaves that field unchanged, unlike `UpdateAccountPasswordPolicy`'s+wholesale replace. A password must be 1–128 characters from AWS's documented password character+class, and when the account has an [account password policy](#account-password-policy) set, it is+also checked against that policy's length and character-class requirements, with+`PasswordPolicyViolation` returned on either action if it doesn't comply. The password itself is never+echoed back by any of these actions, matching AWS.++`DeleteUser` on a user that still has a login profile returns `DeleteConflict`, as on AWS: delete+the profile first. Renaming a user with `UpdateUser` carries its login profile to the new name.+Floci still does not require access keys, inline policies, or other credentials to be removed+before `DeleteUser`; only attached managed policies, group membership, and the login profile block+it.### Policy Simulationdiff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.javaindex 5a2169115a..43b41b3a17 100644--- a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.services.iam.model.IamPolicy;import io.github.hectorvent.floci.services.iam.model.IamRole;import io.github.hectorvent.floci.services.iam.model.IamUser;import io.github.hectorvent.floci.services.iam.model.InstanceProfile;+import io.github.hectorvent.floci.services.iam.model.LoginProfile;import io.github.hectorvent.floci.services.iam.model.OpenIDConnectProvider;import io.github.hectorvent.floci.services.iam.model.SAMLProvider;import io.github.hectorvent.floci.services.iam.model.PolicyVersion;@@ -65,7 +66,10 @@ public class IamQueryHandler {case "UntagUser" -> handleUntagUser(params);case "ListUserTags" -> handleListUserTags(params);case "ListMFADevices" -> handleListMFADevices(params);- case "GetLoginProfile" -> handleGetLoginProfile(params);+ case "CreateLoginProfile" -> handleCreateLoginProfile(params, authorization);+ case "GetLoginProfile" -> handleGetLoginProfile(params, authorization);+ case "UpdateLoginProfile" -> handleUpdateLoginProfile(params);+ case "DeleteLoginProfile" -> handleDeleteLoginProfile(params, authorization);// Identity providers & server certificatescase "ListSAMLProviders" -> handleListSAMLProviders(authorization);@@ -305,16 +309,48 @@ public class IamQueryHandler {return Response.ok(AwsQueryResponse.envelope("ListMFADevices", AwsNamespaces.IAM, result)).build();}- private Response handleGetLoginProfile(MultivaluedMap<String, String> params) {- // Login profiles (console passwords) are not modeled. Per the IAM API,- // GetLoginProfile returns NoSuchEntity (HTTP 404) when a user has no console- // password — a documented, expected result that callers branch on. We must- // return that exact error, not an empty 200 or an UnsupportedOperation 400,- // which clients would treat as a real failure rather than "no profile".+ private Response handleCreateLoginProfile(MultivaluedMap<String, String> params, String authorization) {+ String userName = resolveUserName(params, authorization);+ String password = getParam(params, "Password");+ if (password == null) {+ throw new AwsException("ValidationError", "The request must contain the parameter Password.", 400);+ }+ boolean passwordResetRequired = getBooleanParam(params, "PasswordResetRequired", false);+ LoginProfile profile = iamService.createLoginProfile(userName, password, passwordResetRequired);+ String result = new XmlBuilder().start("LoginProfile").raw(loginProfileXml(profile)).end("LoginProfile").build();+ return Response.ok(AwsQueryResponse.envelope("CreateLoginProfile", AwsNamespaces.IAM, result)).build();+ }++ private Response handleGetLoginProfile(MultivaluedMap<String, String> params, String authorization) {+ String userName = resolveUserName(params, authorization);+ LoginProfile profile = iamService.getLoginProfile(userName);+ String result = new XmlBuilder().start("LoginProfile").raw(loginProfileXml(profile)).end("LoginProfile").build();+ return Response.ok(AwsQueryResponse.envelope("GetLoginProfile", AwsNamespaces.IAM, result)).build();+ }++ private Response handleUpdateLoginProfile(MultivaluedMap<String, String> params) {String userName = getParam(params, "UserName");- return AwsQueryResponse.error("NoSuchEntity",- "Login Profile for User " + (userName != null ? userName : "") + " cannot be found.",- AwsNamespaces.IAM, 404);+ if (userName == null) {+ throw new AwsException("ValidationError", "The request must contain the parameter UserName.", 400);+ }+ String password = getParam(params, "Password");+ Boolean passwordResetRequired = getOptionalBooleanParam(params, "PasswordResetRequired");+ iamService.updateLoginProfile(userName, password, passwordResetRequired);+ return Response.ok(AwsQueryResponse.envelopeNoResult("UpdateLoginProfile", AwsNamespaces.IAM)).build();+ }++ private Response handleDeleteLoginProfile(MultivaluedMap<String, String> params, String authorization) {+ String userName = resolveUserName(params, authorization);+ iamService.deleteLoginProfile(userName);+ return Response.ok(AwsQueryResponse.envelopeNoResult("DeleteLoginProfile", AwsNamespaces.IAM)).build();+ }++ private String loginProfileXml(LoginProfile profile) {+ return new XmlBuilder()+ .elem("PasswordResetRequired", profile.isPasswordResetRequired())+ .elem("UserName", profile.getUserName())+ .elem("CreateDate", isoDate(profile.getCreateDate()))+ .build();}private Response handleListSAMLProviders(String authorization) {@@ -565,6 +601,15 @@ public class IamQueryHandler {return parseStrictBoolean(name, value);}+ /** Unlike {@link #getBooleanParam}, absence is meaningful here: it must not collapse to a default. */+ private Boolean getOptionalBooleanParam(MultivaluedMap<String, String> params, String name) {+ String value = params.getFirst(name);+ if (value == null) {+ return null;+ }+ return parseStrictBoolean(name, value);+ }+private boolean parseStrictBoolean(String name, String value) {if ("true".equalsIgnoreCase(value)) {return true;diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamService.javaindex ffcd07c000..1e5ee601c1 100644--- a/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java+++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java@@ -19,6 +19,7 @@ import io.github.hectorvent.floci.services.iam.model.IamPolicy;import io.github.hectorvent.floci.services.iam.model.IamRole;import io.github.hectorvent.floci.services.iam.model.IamUser;import io.github.hectorvent.floci.services.iam.model.InstanceProfile;+import io.github.hectorvent.floci.services.iam.model.LoginProfile;import io.github.hectorvent.floci.services.iam.model.OpenIDConnectProvider;import io.github.hectorvent.floci.services.iam.model.OrganizationRootFeatures;import io.github.hectorvent.floci.services.iam.model.PolicyVersion;@@ -79,6 +80,12 @@ public class IamService implements SessionAccountLookup, ResourceProvider {private static final int MAX_PASSWORD_AGE_CEILING = 1095;private static final int PASSWORD_REUSE_PREVENTION_FLOOR = 1;private static final int PASSWORD_REUSE_PREVENTION_CEILING = 24;+ /**+ * AWS's documented {@code passwordType} pattern for Create/UpdateLoginProfile: printable+ * ASCII and Latin-1 Supplement (space through code point 0xFF), plus tab/LF/CR, 1-128 chars.+ */+ private static final Pattern LOGIN_PROFILE_PASSWORD_PATTERN =+ Pattern.compile("[\\t\\n\\r\\x20-\\xff]{1,128}");/** Guards the read-modify-write in the OIDC provider mutators. */private final Object oidcProviderLock = new Object();@@ -131,6 +138,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {* single-value-per-account shape as {@link #accountAliases}.*/private final StorageBackend<String, AccountPasswordPolicy> passwordPolicies;+ private final StorageBackend<String, LoginProfile> loginProfiles;private final StorageBackend<String, OpenIDConnectProvider> oidcProviders;/** Deletion is synchronous, so an issued task id is a completed one; the value is its role. */private final StorageBackend<String, String> serviceLinkedRoleDeletions;@@ -158,6 +166,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {storageFactory.create("iam", "iam-sessions.json", new TypeReference<>() {}),storageFactory.create("iam", "iam-account-aliases.json", new TypeReference<>() {}),storageFactory.create("iam", "iam-password-policy.json", new TypeReference<>() {}),+ storageFactory.create("iam", "iam-login-profiles.json", new TypeReference<>() {}),storageFactory.create("iam", "iam-oidc-providers.json", new TypeReference<>() {}),storageFactory.create("iam", "iam-slr-deletions.json", new TypeReference<>() {}),storageFactory.create("iam", "iam-org-root-features.json", new TypeReference<>() {}),@@ -189,7 +198,8 @@ public class IamService implements SessionAccountLookup, ResourceProvider {boolean seedDeployerPrincipal) {this(users, groups, roles, policies, accessKeys, instanceProfiles, sessions,new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),- new InMemoryStorage<>(), new InMemoryStorage<>(), regionResolver, seedDeployerPrincipal, null);+ new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),+ regionResolver, seedDeployerPrincipal, null);}// 8-backend constructor (no org-root-features): kept for existing callers/tests;@@ -209,8 +219,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {boolean seedDeployerPrincipal,String seededAccountAlias) {this(users, groups, roles, policies, accessKeys, instanceProfiles, sessions,- accountAliases, passwordPolicies, oidcProviders, serviceLinkedRoleDeletions,- new InMemoryStorage<>(), regionResolver, seedDeployerPrincipal, seededAccountAlias);+ accountAliases, passwordPolicies, new InMemoryStorage<>(), oidcProviders,+ serviceLinkedRoleDeletions, new InMemoryStorage<>(), regionResolver,+ seedDeployerPrincipal, seededAccountAlias);}// 9-backend constructor (no alias/OIDC/SLR backends): kept for existing callers/tests;@@ -228,7 +239,8 @@ public class IamService implements SessionAccountLookup, ResourceProvider {boolean seedDeployerPrincipal) {this(users, groups, roles, policies, accessKeys, instanceProfiles, sessions,new InMemoryStorage<>(), passwordPolicies, new InMemoryStorage<>(),- new InMemoryStorage<>(), orgRootFeatures, regionResolver, seedDeployerPrincipal, null);+ new InMemoryStorage<>(), new InMemoryStorage<>(), orgRootFeatures, regionResolver,+ seedDeployerPrincipal, null);}IamService(StorageBackend<String, IamUser> users,@@ -240,6 +252,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {StorageBackend<String, SessionCredential> sessions,StorageBackend<String, String> accountAliases,StorageBackend<String, AccountPasswordPolicy> passwordPolicies,+ StorageBackend<String, LoginProfile> loginProfiles,StorageBackend<String, OpenIDConnectProvider> oidcProviders,StorageBackend<String, String> serviceLinkedRoleDeletions,StorageBackend<String, OrganizationRootFeatures> orgRootFeatures,@@ -255,6 +268,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {this.sessions = sessions;this.accountAliases = accountAliases;this.passwordPolicies = passwordPolicies;+ this.loginProfiles = loginProfiles;this.oidcProviders = oidcProviders;this.serviceLinkedRoleDeletions = serviceLinkedRoleDeletions;this.orgRootFeatures = orgRootFeatures;@@ -393,6 +407,10 @@ public class IamService implements SessionAccountLookup, ResourceProvider {throw new AwsException("DeleteConflict","Cannot delete entity, must remove from all groups first.", 409);}+ if (loginProfiles.get(userName).isPresent()) {+ throw new AwsException("DeleteConflict",+ "Cannot delete entity, must delete login profile first.", 409);+ }users.delete(userName);LOG.infov("Deleted IAM user: {0}", userName);}@@ -430,6 +448,11 @@ public class IamService implements SessionAccountLookup, ResourceProvider {if (newPath != null) user.setPath(normalizePath(newPath));user.setArn(iamArn("user", user.getPath(), newUserName));users.put(newUserName, user);+ loginProfiles.get(userName).ifPresent(profile -> {+ loginProfiles.delete(userName);+ profile.setUserName(newUserName);+ loginProfiles.put(newUserName, profile);+ });} else {if (newPath != null) {user.setPath(normalizePath(newPath));@@ -1635,6 +1658,100 @@ public class IamService implements SessionAccountLookup, ResourceProvider {}}+ // =========================================================================+ // Login Profiles+ // =========================================================================++ /** A user holds at most one login profile: creating a second is EntityAlreadyExists. */+ public LoginProfile createLoginProfile(String userName, String password, boolean passwordResetRequired) {+ getUser(userName);+ if (loginProfiles.get(userName).isPresent()) {+ throw new AwsException("EntityAlreadyExists",+ "Login Profile for User " + userName + " already exists.", 409);+ }+ validateLoginProfilePassword(password);+ LoginProfile profile = new LoginProfile(userName, password, passwordResetRequired);+ loginProfiles.put(userName, profile);+ LOG.infov("Created IAM login profile for user: {0}", userName);+ return profile;+ }++ public LoginProfile getLoginProfile(String userName) {+ getUser(userName);+ return loginProfiles.get(userName)+ .orElseThrow(() -> new AwsException("NoSuchEntity",+ "Login Profile for User " + userName + " cannot be found.", 404));+ }++ /**+ * Replaces the fields the caller supplies; unlike {@link #updateAccountPasswordPolicy}, an+ * omitted field here carries over its previous value rather than resetting to a default.+ * {@code Password} and {@code PasswordResetRequired} are independently optional on AWS's+ * {@code UpdateLoginProfile}, so a caller rotating only the password must not accidentally+ * clear the reset-required flag, and vice versa.+ */+ public void updateLoginProfile(String userName, String password, Boolean passwordResetRequired) {+ LoginProfile profile = getLoginProfile(userName);+ if (password != null) {+ validateLoginProfilePassword(password);+ profile.setPassword(password);+ }+ if (passwordResetRequired != null) {+ profile.setPasswordResetRequired(passwordResetRequired);+ }+ loginProfiles.put(userName, profile);+ LOG.infov("Updated IAM login profile for user: {0}", userName);+ }++ public void deleteLoginProfile(String userName) {+ getUser(userName);+ if (loginProfiles.get(userName).isEmpty()) {+ throw new AwsException("NoSuchEntity",+ "Login Profile for User " + userName + " cannot be found.", 404);+ }+ loginProfiles.delete(userName);+ LOG.infov("Deleted IAM login profile for user: {0}", userName);+ }++ /**+ * Base wire validation shared by Create/UpdateLoginProfile, then, only when the account has+ * ever set one (matching {@link #getAccountPasswordPolicy}'s own NoSuchEntity-by-default+ * semantics), the account's password policy.+ */+ private void validateLoginProfilePassword(String password) {+ if (password == null || !LOGIN_PROFILE_PASSWORD_PATTERN.matcher(password).matches()) {+ throw new AwsException("ValidationError",+ "1 validation error detected: Value at 'password' failed to satisfy constraint: "+ + "Member must have length less than or equal to 128 and greater than or "+ + "equal to 1", 400);+ }+ getAccountPasswordPolicy().ifPresent(policy -> checkPasswordAgainstPolicy(password, policy));+ }++ private void checkPasswordAgainstPolicy(String password, AccountPasswordPolicy policy) {+ List<String> violations = new ArrayList<>();+ if (password.length() < policy.getMinimumPasswordLength()) {+ violations.add("a minimum length of " + policy.getMinimumPasswordLength());+ }+ if (policy.isRequireUppercaseCharacters() && password.chars().noneMatch(Character::isUpperCase)) {+ violations.add("at least one uppercase letter");+ }+ if (policy.isRequireLowercaseCharacters() && password.chars().noneMatch(Character::isLowerCase)) {+ violations.add("at least one lowercase letter");+ }+ if (policy.isRequireNumbers() && password.chars().noneMatch(Character::isDigit)) {+ violations.add("at least one number");+ }+ if (policy.isRequireSymbols() && password.chars().allMatch(Character::isLetterOrDigit)) {+ violations.add("at least one non-alphanumeric character");+ }+ if (!violations.isEmpty()) {+ throw new AwsException("PasswordPolicyViolation",+ "Password does not conform to the account password policy. It must contain: "+ + String.join(", ", violations) + ".", 400);+ }+ }+private void validateIamResourceName(String value, String paramName) {if (value == null || !IAM_RESOURCE_NAME_PATTERN.matcher(value).matches()) {throw new AwsException("ValidationError",diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/model/LoginProfile.java b/src/main/java/io/github/hectorvent/floci/services/iam/model/LoginProfile.javanew file mode 100644index 0000000000..dd9eb761a6--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/iam/model/LoginProfile.java@@ -0,0 +1,46 @@+package io.github.hectorvent.floci.services.iam.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.time.Instant;++/**+ * A user's console (password) login profile. At most one per user, mirroring AWS: creating+ * one when the user already has one is {@code EntityAlreadyExists}, and a user with no+ * console password simply has no entry here. The password is stored in plain text, matching+ * how {@link AccessKey} already stores its secret: this is an emulator, not a credential+ * store, and AWS itself never echoes the password back on any of these actions.+ */+@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+public class LoginProfile {++ private String userName;+ private String password;+ private boolean passwordResetRequired;+ private Instant createDate;++ public LoginProfile() {}++ public LoginProfile(String userName, String password, boolean passwordResetRequired) {+ this.userName = userName;+ this.password = password;+ this.passwordResetRequired = passwordResetRequired;+ this.createDate = Instant.now();+ }++ public String getUserName() { return userName; }+ public void setUserName(String userName) { this.userName = userName; }++ public String getPassword() { return password; }+ public void setPassword(String password) { this.password = password; }++ public boolean isPasswordResetRequired() { return passwordResetRequired; }+ public void setPasswordResetRequired(boolean passwordResetRequired) {+ this.passwordResetRequired = passwordResetRequired;+ }++ public Instant getCreateDate() { return createDate; }+ public void setCreateDate(Instant createDate) { this.createDate = createDate; }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamLoginProfileIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamLoginProfileIntegrationTest.javanew file mode 100644index 0000000000..ce4239d976--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamLoginProfileIntegrationTest.java@@ -0,0 +1,231 @@+package io.github.hectorvent.floci.services.iam;++import io.github.hectorvent.floci.core.common.AwsQueryController;+import io.quarkus.test.junit.QuarkusTest;+import org.junit.jupiter.api.MethodOrderer;+import org.junit.jupiter.api.Order;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.TestMethodOrder;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.notNullValue;++/**+ * Integration tests for the IAM login profile actions via the Query Protocol, covering the full+ * HTTP stack through {@link AwsQueryController} → {@link IamQueryHandler}.+ *+ * <p>Ordered: a login profile is a single per-user value, so these cases share state+ * deliberately: missing before create, create, duplicate create, get-after-create, update,+ * update against an unknown user, delete-user conflict, delete, missing after delete,+ * duplicate delete, delete the user.+ */+@QuarkusTest+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)+class IamLoginProfileIntegrationTest {++ private static final String IAM_CREDENTIAL =+ "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request";+ private static final String USER_NAME = "login-profile-user";++ @Test+ @Order(1)+ void createTheUser() {+ given()+ .formParam("Action", "CreateUser")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(200);+ }++ @Test+ @Order(2)+ void getBeforeAnyCreateIsNoSuchEntity() {+ given()+ .formParam("Action", "GetLoginProfile")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(404)+ .body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));+ }++ @Test+ @Order(3)+ void createSetsTheProfile() {+ given()+ .formParam("Action", "CreateLoginProfile")+ .formParam("UserName", USER_NAME)+ .formParam("Password", "Sup3r$ecret!")+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .contentType("application/xml")+ .body("CreateLoginProfileResponse.CreateLoginProfileResult.LoginProfile.UserName",+ equalTo(USER_NAME))+ .body("CreateLoginProfileResponse.CreateLoginProfileResult.LoginProfile.PasswordResetRequired",+ equalTo("false"))+ .body("CreateLoginProfileResponse.CreateLoginProfileResult.LoginProfile.CreateDate",+ notNullValue());+ }++ @Test+ @Order(4)+ void createAgainIsEntityAlreadyExists() {+ given()+ .formParam("Action", "CreateLoginProfile")+ .formParam("UserName", USER_NAME)+ .formParam("Password", "AnotherP4ss!")+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(409)+ .body("ErrorResponse.Error.Code", equalTo("EntityAlreadyExists"));+ }++ @Test+ @Order(5)+ void getReturnsTheProfileJustCreated() {+ given()+ .formParam("Action", "GetLoginProfile")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body("GetLoginProfileResponse.GetLoginProfileResult.LoginProfile.UserName", equalTo(USER_NAME))+ .body("GetLoginProfileResponse.GetLoginProfileResult.LoginProfile.PasswordResetRequired",+ equalTo("false"));+ }++ @Test+ @Order(6)+ void updateWithoutUserNameIsValidationError() {+ given()+ .formParam("Action", "UpdateLoginProfile")+ .formParam("Password", "NewP4ssword!")+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body("ErrorResponse.Error.Code", equalTo("ValidationError"));+ }++ @Test+ @Order(7)+ void updateAgainstAnUnknownUserIsNoSuchEntity() {+ given()+ .formParam("Action", "UpdateLoginProfile")+ .formParam("UserName", "no-such-user")+ .formParam("PasswordResetRequired", "true")+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(404)+ .body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));+ }++ @Test+ @Order(8)+ void updateFlagOnlyLeavesThePasswordInPlace() {+ given()+ .formParam("Action", "UpdateLoginProfile")+ .formParam("UserName", USER_NAME)+ .formParam("PasswordResetRequired", "true")+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(200);++ given()+ .formParam("Action", "GetLoginProfile")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body("GetLoginProfileResponse.GetLoginProfileResult.LoginProfile.PasswordResetRequired",+ equalTo("true"));+ }++ @Test+ @Order(9)+ void deleteUserWhileProfileExistsIsDeleteConflict() {+ given()+ .formParam("Action", "DeleteUser")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(409)+ .body("ErrorResponse.Error.Code", equalTo("DeleteConflict"));+ }++ @Test+ @Order(10)+ void deleteRemovesTheProfile() {+ given()+ .formParam("Action", "DeleteLoginProfile")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(200);+ }++ @Test+ @Order(11)+ void getAfterDeleteIsNoSuchEntity() {+ given()+ .formParam("Action", "GetLoginProfile")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(404)+ .body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));+ }++ @Test+ @Order(12)+ void deleteAgainIsNoSuchEntity() {+ given()+ .formParam("Action", "DeleteLoginProfile")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(404)+ .body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));+ }++ @Test+ @Order(13)+ void deleteTheUser() {+ given()+ .formParam("Action", "DeleteUser")+ .formParam("UserName", USER_NAME)+ .header("Authorization", IAM_CREDENTIAL)+ .when()+ .post("/")+ .then()+ .statusCode(200);+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamServiceTest.javaindex cf4396abb9..d9d388c2b5 100644--- a/src/test/java/io/github/hectorvent/floci/services/iam/IamServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamServiceTest.java@@ -7,11 +7,13 @@ import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;import io.github.hectorvent.floci.core.storage.InMemoryStorage;import io.github.hectorvent.floci.core.storage.StorageBackend;import io.github.hectorvent.floci.services.iam.model.AccessKey;+import io.github.hectorvent.floci.services.iam.model.AccountPasswordPolicy;import io.github.hectorvent.floci.services.iam.model.CallerContext;import io.github.hectorvent.floci.services.iam.model.IamGroup;import io.github.hectorvent.floci.services.iam.model.IamPolicy;import io.github.hectorvent.floci.services.iam.model.IamRole;import io.github.hectorvent.floci.services.iam.model.IamUser;+import io.github.hectorvent.floci.services.iam.model.LoginProfile;import io.github.hectorvent.floci.services.iam.model.OpenIDConnectProvider;import io.github.hectorvent.floci.services.iam.model.InstanceProfile;import io.github.hectorvent.floci.services.iam.model.PolicyVersion;@@ -205,6 +207,157 @@ class IamServiceTest {assertTrue(tags2.containsKey("env"));}+ // =========================================================================+ // Login Profiles+ // =========================================================================++ @Test+ void createGetUpdateAndDeleteLoginProfile() {+ iamService.createUser("alice", "/");++ LoginProfile created = iamService.createLoginProfile("alice", "Sup3r$ecret!", false);+ assertEquals("alice", created.getUserName());+ assertFalse(created.isPasswordResetRequired());++ LoginProfile fetched = iamService.getLoginProfile("alice");+ assertEquals("Sup3r$ecret!", fetched.getPassword());++ iamService.updateLoginProfile("alice", "NewP4ssword!", true);+ LoginProfile updated = iamService.getLoginProfile("alice");+ assertEquals("NewP4ssword!", updated.getPassword());+ assertTrue(updated.isPasswordResetRequired());++ iamService.deleteLoginProfile("alice");+ assertThrows(AwsException.class, () -> iamService.getLoginProfile("alice"));+ }++ @Test+ void createLoginProfileTwiceIsEntityAlreadyExists() {+ iamService.createUser("alice", "/");+ iamService.createLoginProfile("alice", "Sup3r$ecret!", false);++ AwsException ex = assertThrows(AwsException.class,+ () -> iamService.createLoginProfile("alice", "AnotherP4ss!", false));+ assertEquals("EntityAlreadyExists", ex.getErrorCode());+ }++ @Test+ void createLoginProfileForUnknownUserIsNoSuchEntity() {+ AwsException ex = assertThrows(AwsException.class,+ () -> iamService.createLoginProfile("ghost", "Sup3r$ecret!", false));+ assertEquals("NoSuchEntity", ex.getErrorCode());+ }++ @Test+ void getLoginProfileForUserWithNoneIsNoSuchEntity() {+ iamService.createUser("alice", "/");++ AwsException ex = assertThrows(AwsException.class, () -> iamService.getLoginProfile("alice"));+ assertEquals("NoSuchEntity", ex.getErrorCode());+ }++ @Test+ void deleteLoginProfileForUserWithNoneIsNoSuchEntity() {+ iamService.createUser("alice", "/");++ AwsException ex = assertThrows(AwsException.class, () -> iamService.deleteLoginProfile("alice"));+ assertEquals("NoSuchEntity", ex.getErrorCode());+ }++ @Test+ void updateLoginProfileLeavesAnOmittedFieldUnchanged() {+ iamService.createUser("alice", "/");+ iamService.createLoginProfile("alice", "Sup3r$ecret!", true);++ // Only PasswordResetRequired supplied: the stored password must survive untouched.+ iamService.updateLoginProfile("alice", null, false);+ LoginProfile afterFlagOnly = iamService.getLoginProfile("alice");+ assertEquals("Sup3r$ecret!", afterFlagOnly.getPassword());+ assertFalse(afterFlagOnly.isPasswordResetRequired());++ // Only Password supplied: the reset-required flag must survive untouched.+ iamService.updateLoginProfile("alice", "NewP4ssword!", null);+ LoginProfile afterPasswordOnly = iamService.getLoginProfile("alice");+ assertEquals("NewP4ssword!", afterPasswordOnly.getPassword());+ assertFalse(afterPasswordOnly.isPasswordResetRequired());+ }++ @Test+ void updateLoginProfileForUserWithNoneIsNoSuchEntity() {+ iamService.createUser("alice", "/");++ AwsException ex = assertThrows(AwsException.class,+ () -> iamService.updateLoginProfile("alice", "NewP4ssword!", null));+ assertEquals("NoSuchEntity", ex.getErrorCode());+ }++ @Test+ void createLoginProfileRejectsPasswordViolatingAccountPolicy() {+ iamService.createUser("alice", "/");+ AccountPasswordPolicy policy = new AccountPasswordPolicy();+ policy.setMinimumPasswordLength(12);+ policy.setRequireSymbols(true);+ policy.setRequireNumbers(true);+ iamService.updateAccountPasswordPolicy(policy);++ AwsException ex = assertThrows(AwsException.class,+ () -> iamService.createLoginProfile("alice", "short", false));+ assertEquals("PasswordPolicyViolation", ex.getErrorCode());+ }++ @Test+ void createLoginProfileAcceptsPasswordSatisfyingAccountPolicy() {+ iamService.createUser("alice", "/");+ AccountPasswordPolicy policy = new AccountPasswordPolicy();+ policy.setMinimumPasswordLength(12);+ policy.setRequireSymbols(true);+ policy.setRequireNumbers(true);+ iamService.updateAccountPasswordPolicy(policy);++ LoginProfile profile = iamService.createLoginProfile("alice", "Sup3r$ecret!", false);+ assertEquals("alice", profile.getUserName());+ }++ @Test+ void deleteUserWithLoginProfileIsDeleteConflict() {+ iamService.createUser("alice", "/");+ iamService.createLoginProfile("alice", "Sup3r$ecret!", false);++ AwsException ex = assertThrows(AwsException.class, () -> iamService.deleteUser("alice"));+ assertEquals("DeleteConflict", ex.getErrorCode());+ assertEquals("alice", iamService.getUser("alice").getUserName());++ iamService.deleteLoginProfile("alice");+ iamService.deleteUser("alice");+ iamService.createUser("alice", "/");+ assertThrows(AwsException.class, () -> iamService.getLoginProfile("alice"));+ }++ @Test+ void renamingAUserMovesItsLoginProfile() {+ iamService.createUser("alice", "/");+ iamService.createLoginProfile("alice", "Sup3r$ecret!", true);++ iamService.updateUser("alice", "alicia", null);++ LoginProfile moved = iamService.getLoginProfile("alicia");+ assertEquals("alicia", moved.getUserName());+ assertEquals("Sup3r$ecret!", moved.getPassword());+ assertTrue(moved.isPasswordResetRequired());+ iamService.createUser("alice", "/");+ AwsException ex = assertThrows(AwsException.class, () -> iamService.getLoginProfile("alice"));+ assertEquals("NoSuchEntity", ex.getErrorCode());+ }++ @Test+ void createLoginProfileRejectsPasswordOutsideWireCharacterSet() {+ iamService.createUser("alice", "/");++ AwsException ex = assertThrows(AwsException.class,+ () -> iamService.createLoginProfile("alice", "badpassword", false));+ assertEquals("ValidationError", ex.getErrorCode());+ }+// =========================================================================// Groups// =========================================================================