From 93f00ecd137b3d4781d2366504ae0fefeafeec24 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 24 Nov 2022 08:36:36 -0500 Subject: [PATCH] removed the use of @Context (#3867) as this is no longer supported in keycloak --- .../ui/rest/AuthenticationManagementProvider.java | 2 +- .../ui/rest/AuthenticationManagementResource.java | 7 +++---- .../admin/ui/rest/AvailableRoleMappingProvider.java | 2 +- .../admin/ui/rest/AvailableRoleMappingResource.java | 7 +++---- .../admin/ui/rest/BruteForceUsersProvider.java | 2 +- .../admin/ui/rest/BruteForceUsersResource.java | 9 +++------ .../admin/ui/rest/EffectiveRoleMappingProvider.java | 2 +- .../admin/ui/rest/EffectiveRoleMappingResource.java | 5 ++--- .../org/keycloak/admin/ui/rest/GroupsResource.java | 11 +++++------ .../admin/ui/rest/GroupsResourceProvider.java | 2 +- 10 files changed, 21 insertions(+), 28 deletions(-) diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AuthenticationManagementProvider.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AuthenticationManagementProvider.java index ec96ac1fa8..1ec3760495 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AuthenticationManagementProvider.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AuthenticationManagementProvider.java @@ -28,6 +28,6 @@ public final class AuthenticationManagementProvider implements AdminRealmResourc } public Object getResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent) { - return new AuthenticationManagementResource(realm, auth); + return new AuthenticationManagementResource(session, realm, auth); } } diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AuthenticationManagementResource.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AuthenticationManagementResource.java index 3191095c7d..fdd0c14413 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AuthenticationManagementResource.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AuthenticationManagementResource.java @@ -11,7 +11,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; import org.eclipse.microprofile.openapi.annotations.media.Content; @@ -32,16 +31,16 @@ import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluato @Consumes({"application/json"}) @Produces({"application/json"}) public class AuthenticationManagementResource extends RoleMappingResource { - @Context - private KeycloakSession session; + private final KeycloakSession session; private RealmModel realm; private AdminPermissionEvaluator auth; - public AuthenticationManagementResource(RealmModel realm, AdminPermissionEvaluator auth) { + public AuthenticationManagementResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth) { super(realm, auth); this.realm = realm; this.auth = auth; + this.session = session; } @GET diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AvailableRoleMappingProvider.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AvailableRoleMappingProvider.java index 2531384411..d5ad193da4 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AvailableRoleMappingProvider.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AvailableRoleMappingProvider.java @@ -30,6 +30,6 @@ public final class AvailableRoleMappingProvider implements AdminRealmResourcePro } public Object getResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent) { - return new AvailableRoleMappingResource(realm, auth); + return new AvailableRoleMappingResource(session, realm, auth); } } diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AvailableRoleMappingResource.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AvailableRoleMappingResource.java index 20c7b17300..6f85dd81eb 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AvailableRoleMappingResource.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/AvailableRoleMappingResource.java @@ -12,7 +12,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; import org.eclipse.microprofile.openapi.annotations.media.Content; @@ -30,15 +29,15 @@ import org.keycloak.models.UserProvider; import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator; public class AvailableRoleMappingResource extends RoleMappingResource { - @Context - private KeycloakSession session; + private final KeycloakSession session; private final RealmModel realm; private final AdminPermissionEvaluator auth; - public AvailableRoleMappingResource(RealmModel realm, AdminPermissionEvaluator auth) { + public AvailableRoleMappingResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth) { super(realm, auth); this.realm = realm; this.auth = auth; + this.session = session; } @GET diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersProvider.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersProvider.java index 8f7e97c581..4e9bd03ec2 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersProvider.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersProvider.java @@ -30,6 +30,6 @@ public final class BruteForceUsersProvider implements AdminRealmResourceProvider } public Object getResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent) { - return new BruteForceUsersResource(realm, auth); + return new BruteForceUsersResource(session, realm, auth); } } diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java index 1166ffb6c9..61d6bbc49c 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java @@ -2,7 +2,6 @@ package org.keycloak.admin.ui.rest; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Stream; @@ -12,7 +11,6 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; import org.eclipse.microprofile.openapi.annotations.media.Content; @@ -28,7 +26,6 @@ import org.keycloak.models.UserLoginFailureModel; import org.keycloak.models.UserModel; import org.keycloak.models.utils.ModelToRepresentation; import org.keycloak.representations.idm.UserRepresentation; -import org.keycloak.services.managers.BruteForceProtector; import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator; import org.keycloak.services.resources.admin.permissions.UserPermissionEvaluator; import org.keycloak.utils.SearchQueryUtils; @@ -37,14 +34,14 @@ import org.keycloak.utils.SearchQueryUtils; public class BruteForceUsersResource { private static final Logger logger = Logger.getLogger(BruteForceUsersResource.class); private static final String SEARCH_ID_PARAMETER = "id:"; - @Context - private KeycloakSession session; + private final KeycloakSession session; private final RealmModel realm; private final AdminPermissionEvaluator auth; - public BruteForceUsersResource(RealmModel realm, AdminPermissionEvaluator auth) { + public BruteForceUsersResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth) { this.realm = realm; this.auth = auth; + this.session = session; } @GET diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/EffectiveRoleMappingProvider.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/EffectiveRoleMappingProvider.java index 38c4d3a448..479a75fd6b 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/EffectiveRoleMappingProvider.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/EffectiveRoleMappingProvider.java @@ -30,6 +30,6 @@ public final class EffectiveRoleMappingProvider implements AdminRealmResourcePro } public Object getResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent) { - return new EffectiveRoleMappingResource(realm, auth); + return new EffectiveRoleMappingResource(session, realm, auth); } } diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/EffectiveRoleMappingResource.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/EffectiveRoleMappingResource.java index 4496dbd8f8..2c4528e2fd 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/EffectiveRoleMappingResource.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/EffectiveRoleMappingResource.java @@ -9,7 +9,6 @@ import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; import org.eclipse.microprofile.openapi.annotations.media.Content; @@ -25,15 +24,15 @@ import org.keycloak.models.UserModel; import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator; public class EffectiveRoleMappingResource extends RoleMappingResource { - @Context private KeycloakSession session; private RealmModel realm; private AdminPermissionEvaluator auth; - public EffectiveRoleMappingResource(RealmModel realm, AdminPermissionEvaluator auth) { + public EffectiveRoleMappingResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth) { super(realm, auth); this.realm = realm; this.auth = auth; + this.session = session; } @GET diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/GroupsResource.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/GroupsResource.java index 9a12d8124a..ef3fe85f53 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/GroupsResource.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/GroupsResource.java @@ -9,7 +9,6 @@ import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; @@ -25,15 +24,15 @@ import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluato import org.keycloak.utils.StringUtil; public class GroupsResource { - @Context - private KeycloakSession session; - private RealmModel realm; - private AdminPermissionEvaluator auth; + private final KeycloakSession session; + private final RealmModel realm; + private final AdminPermissionEvaluator auth; - public GroupsResource(RealmModel realm, AdminPermissionEvaluator auth) { + public GroupsResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth) { super(); this.realm = realm; this.auth = auth; + this.session = session; } @GET diff --git a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/GroupsResourceProvider.java b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/GroupsResourceProvider.java index ac9ed3172c..d0947c7393 100644 --- a/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/GroupsResourceProvider.java +++ b/keycloak-theme/src/main/java/org/keycloak/admin/ui/rest/GroupsResourceProvider.java @@ -30,6 +30,6 @@ public final class GroupsResourceProvider implements AdminRealmResourceProviderF } public Object getResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent) { - return new GroupsResource(realm, auth); + return new GroupsResource(session, realm, auth); } }