From b648c35cf1ed3e11d14799d67c85454c67f70c8f Mon Sep 17 00:00:00 2001 From: Peter Zaoral Date: Fri, 9 Aug 2024 18:07:31 +0200 Subject: [PATCH] Final adjustments Signed-off-by: Peter Zaoral --- js/apps/admin-ui/cypress/e2e/clients_test.spec.ts | 8 +++++++- .../support/pages/admin-ui/components/TablePage.ts | 4 ++-- js/apps/admin-ui/src/Banners.tsx | 2 +- .../keycloak/admin/ui/rest/BruteForceUsersResource.java | 3 --- .../src/main/java/org/keycloak/models/Constants.java | 3 +++ .../org/keycloak/models/utils/ModelToRepresentation.java | 2 ++ .../log/TemporaryAdminAccountEventListenerProvider.java | 2 +- .../keycloak/services/managers/ApplianceBootstrap.java | 3 ++- .../keycloak/services/resources/admin/AdminConsole.java | 2 +- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/js/apps/admin-ui/cypress/e2e/clients_test.spec.ts b/js/apps/admin-ui/cypress/e2e/clients_test.spec.ts index 4ff45dfb88e2..2f86e8f7d54c 100644 --- a/js/apps/admin-ui/cypress/e2e/clients_test.spec.ts +++ b/js/apps/admin-ui/cypress/e2e/clients_test.spec.ts @@ -115,7 +115,7 @@ describe("Clients test", () => { ); }); - it("Should check temporary admin service existence", () => { + it("Should check temporary admin service label (non)existence", () => { commonPage.sidebar().goToRealm("master"); commonPage.sidebar().goToClients(); commonPage @@ -125,6 +125,12 @@ describe("Clients test", () => { commonPage .tableUtils() .checkTemporaryAdminLabelExists("temporary-admin-label"); + + commonPage.tableToolbarUtils().searchItem("admin-cli", false); + commonPage.tableUtils().checkRowItemExists("admin-cli"); + commonPage + .tableUtils() + .checkTemporaryAdminLabelExists("temporary-admin-label", false); }); it("Should list client scopes", () => { diff --git a/js/apps/admin-ui/cypress/support/pages/admin-ui/components/TablePage.ts b/js/apps/admin-ui/cypress/support/pages/admin-ui/components/TablePage.ts index b8a21db5ac46..c4c6f56d7a1b 100644 --- a/js/apps/admin-ui/cypress/support/pages/admin-ui/components/TablePage.ts +++ b/js/apps/admin-ui/cypress/support/pages/admin-ui/components/TablePage.ts @@ -148,13 +148,13 @@ export default class TablePage extends CommonElements { return this; } - checkTemporaryAdminLabelExists(labelId: string) { + checkTemporaryAdminLabelExists(labelId: string, exist = true) { cy.get( (this.#tableInModal ? ".pf-v5-c-modal-box.pf-m-md " : "") + this.#tableRowItem, ) .find(`#${labelId}`) - .should("exist"); + .should((!exist ? "not." : "") + "exist"); return this; } diff --git a/js/apps/admin-ui/src/Banners.tsx b/js/apps/admin-ui/src/Banners.tsx index 03aabccb65a1..9ec4c914b141 100644 --- a/js/apps/admin-ui/src/Banners.tsx +++ b/js/apps/admin-ui/src/Banners.tsx @@ -7,7 +7,7 @@ const WarnBanner = (msg: string) => { const { t } = useTranslation(); return ( - + diff --git a/rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java b/rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java index 923b89ea0491..12c70a8a4b16 100644 --- a/rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java +++ b/rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java @@ -29,8 +29,6 @@ import org.keycloak.services.resources.admin.permissions.UserPermissionEvaluator; import org.keycloak.utils.SearchQueryUtils; -import static org.keycloak.services.managers.ApplianceBootstrap.TEMP_ADMIN_ATTR_NAME; - public class BruteForceUsersResource { private static final Logger logger = Logger.getLogger(BruteForceUsersResource.class); private static final String SEARCH_ID_PARAMETER = "id:"; @@ -169,7 +167,6 @@ private Stream toRepresentation(RealmModel realm, UserPermissionEvalu ModelToRepresentation.toBriefRepresentation(user) : ModelToRepresentation.toRepresentation(session, realm, user); userRep.setAccess(usersEvaluator.getAccess(user)); - ModelToRepresentation.addAttributeToBriefRep(user, userRep, TEMP_ADMIN_ATTR_NAME); return userRep; }).map(this::getBruteForceStatus); } diff --git a/server-spi-private/src/main/java/org/keycloak/models/Constants.java b/server-spi-private/src/main/java/org/keycloak/models/Constants.java index 11838d6f283c..c7513e7f30b1 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/Constants.java +++ b/server-spi-private/src/main/java/org/keycloak/models/Constants.java @@ -184,4 +184,7 @@ public final class Constants { //attribute name used to mark a client as realm client public static final String REALM_CLIENT = "realm_client"; + + //attribute name used to mark a temporary admin user/service account as temporary + public static final String TEMP_ADMIN_ATTR_NAME = "temporary_admin"; } diff --git a/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java b/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java index 8b292c442175..fa2afd203433 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java +++ b/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java @@ -68,6 +68,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import static org.keycloak.models.light.LightweightUserAdapter.isLightweightUser; +import static org.keycloak.models.Constants.TEMP_ADMIN_ATTR_NAME; /** * @author Bill Burke @@ -265,6 +266,7 @@ public static UserRepresentation toBriefRepresentation(UserModel user) { rep.setEnabled(user.isEnabled()); rep.setEmailVerified(user.isEmailVerified()); rep.setFederationLink(user.getFederationLink()); + addAttributeToBriefRep(user, rep, TEMP_ADMIN_ATTR_NAME); return rep; } diff --git a/services/src/main/java/org/keycloak/events/log/TemporaryAdminAccountEventListenerProvider.java b/services/src/main/java/org/keycloak/events/log/TemporaryAdminAccountEventListenerProvider.java index fc4092b20b0c..2d2dba478be7 100644 --- a/services/src/main/java/org/keycloak/events/log/TemporaryAdminAccountEventListenerProvider.java +++ b/services/src/main/java/org/keycloak/events/log/TemporaryAdminAccountEventListenerProvider.java @@ -11,7 +11,7 @@ import org.keycloak.models.RealmProvider; import org.keycloak.models.UserModel; -import static org.keycloak.services.managers.ApplianceBootstrap.TEMP_ADMIN_ATTR_NAME; +import static org.keycloak.models.Constants.TEMP_ADMIN_ATTR_NAME; public class TemporaryAdminAccountEventListenerProvider implements EventListenerProvider { diff --git a/services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java b/services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java index 7ed2f29482eb..478ae1291fbe 100755 --- a/services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java +++ b/services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java @@ -37,6 +37,8 @@ import org.keycloak.userprofile.UserProfileProvider; import org.keycloak.utils.StringUtil; +import static org.keycloak.models.Constants.TEMP_ADMIN_ATTR_NAME; + /** * @author Bill Burke * @version $Revision: 1 $ @@ -46,7 +48,6 @@ public class ApplianceBootstrap { public static final String DEFAULT_TEMP_ADMIN_USERNAME = "temp-admin"; public static final String DEFAULT_TEMP_ADMIN_SERVICE = "temp-admin"; public static final int DEFAULT_TEMP_ADMIN_EXPIRATION = 120; - public static final String TEMP_ADMIN_ATTR_NAME = "temporary_admin"; private final KeycloakSession session; diff --git a/services/src/main/java/org/keycloak/services/resources/admin/AdminConsole.java b/services/src/main/java/org/keycloak/services/resources/admin/AdminConsole.java index 2733900f4487..e7c8a47123ee 100644 --- a/services/src/main/java/org/keycloak/services/resources/admin/AdminConsole.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/AdminConsole.java @@ -68,7 +68,7 @@ import java.util.Set; import java.util.stream.Collectors; -import static org.keycloak.services.managers.ApplianceBootstrap.TEMP_ADMIN_ATTR_NAME; +import static org.keycloak.models.Constants.TEMP_ADMIN_ATTR_NAME; /** * @author Bill Burke