diff --git a/services/src/main/java/org/keycloak/partialimport/AbstractPartialImport.java b/services/src/main/java/org/keycloak/partialimport/AbstractPartialImport.java index c748b47265..0e16787cc8 100644 --- a/services/src/main/java/org/keycloak/partialimport/AbstractPartialImport.java +++ b/services/src/main/java/org/keycloak/partialimport/AbstractPartialImport.java @@ -21,9 +21,9 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; import org.keycloak.representations.idm.PartialImportRepresentation; import org.keycloak.services.ErrorResponse; +import org.keycloak.services.ErrorResponseException; import org.keycloak.services.ServicesLogger; -import jakarta.ws.rs.core.Response; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -50,7 +50,7 @@ public abstract class AbstractPartialImport implements PartialImport { @Override public void prepare(PartialImportRepresentation partialImportRep, RealmModel realm, - KeycloakSession session) throws ErrorResponseException { + KeycloakSession session) { List repList = getRepList(partialImportRep); if ((repList == null) || repList.isEmpty()) return; @@ -89,7 +89,7 @@ public abstract class AbstractPartialImport implements PartialImport { } @Override - public PartialImportResults doImport(PartialImportRepresentation partialImportRep, RealmModel realm, KeycloakSession session) throws ErrorResponseException { + public PartialImportResults doImport(PartialImportRepresentation partialImportRep, RealmModel realm, KeycloakSession session) { PartialImportResults results = new PartialImportResults(); List repList = getRepList(partialImportRep); if ((repList == null) || repList.isEmpty()) return results; diff --git a/services/src/main/java/org/keycloak/partialimport/ClientRolesPartialImport.java b/services/src/main/java/org/keycloak/partialimport/ClientRolesPartialImport.java index d3aeb57ca3..b9b0ced5b3 100644 --- a/services/src/main/java/org/keycloak/partialimport/ClientRolesPartialImport.java +++ b/services/src/main/java/org/keycloak/partialimport/ClientRolesPartialImport.java @@ -26,6 +26,8 @@ import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.services.ErrorResponse; import jakarta.ws.rs.core.Response; +import org.keycloak.services.ErrorResponseException; + import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -108,7 +110,7 @@ public class ClientRolesPartialImport { client.removeRole(role); } - public void prepare(PartialImportRepresentation partialImportRep, RealmModel realm, KeycloakSession session) throws ErrorResponseException { + public void prepare(PartialImportRepresentation partialImportRep, RealmModel realm, KeycloakSession session) { Map> repList = getRepList(partialImportRep); if (repList == null || repList.isEmpty()) return; diff --git a/services/src/main/java/org/keycloak/partialimport/ErrorResponseException.java b/services/src/main/java/org/keycloak/partialimport/ErrorResponseException.java deleted file mode 100644 index 68e9f16e9d..0000000000 --- a/services/src/main/java/org/keycloak/partialimport/ErrorResponseException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.partialimport; - -import jakarta.ws.rs.core.Response; - - -/** - * An exception that can hold a Response object. - * - * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc. - */ -public class ErrorResponseException extends RuntimeException { - private final Response response; - - public ErrorResponseException(Response response) { - this.response = response; - } - - public Response getResponse() { - return response; - } -} diff --git a/services/src/main/java/org/keycloak/partialimport/PartialImport.java b/services/src/main/java/org/keycloak/partialimport/PartialImport.java index b189fe41e2..33c57dc383 100644 --- a/services/src/main/java/org/keycloak/partialimport/PartialImport.java +++ b/services/src/main/java/org/keycloak/partialimport/PartialImport.java @@ -35,12 +35,12 @@ public interface PartialImport { * @param rep Everything in the PartialImport request. * @param realm Realm to be imported into. * @param session The KeycloakSession. - * @throws ErrorResponseException If the PartialImport can not be performed, + * @ If the PartialImport can not be performed, * throw this exception. */ void prepare(PartialImportRepresentation rep, RealmModel realm, - KeycloakSession session) throws ErrorResponseException; + KeycloakSession session); /** * Delete resources that will be overwritten. This is done separately so @@ -61,9 +61,9 @@ public interface PartialImport { * @param realm Realm to be imported into. * @param session The KeycloakSession. * @return The final results of the PartialImport request. - * @throws ErrorResponseException if an error was detected trying to doImport a resource. + * @ if an error was detected trying to doImport a resource. */ PartialImportResults doImport(PartialImportRepresentation rep, RealmModel realm, - KeycloakSession session) throws ErrorResponseException; + KeycloakSession session); } diff --git a/services/src/main/java/org/keycloak/partialimport/PartialImportManager.java b/services/src/main/java/org/keycloak/partialimport/PartialImportManager.java index fa6178abaa..faec1057a0 100644 --- a/services/src/main/java/org/keycloak/partialimport/PartialImportManager.java +++ b/services/src/main/java/org/keycloak/partialimport/PartialImportManager.java @@ -51,7 +51,7 @@ public class PartialImportManager { partialImports.add(new UsersPartialImport()); } - public PartialImportResults saveResources() throws ErrorResponseException { + public PartialImportResults saveResources() { PartialImportResults results = new PartialImportResults(); for (PartialImport partialImport : partialImports) { diff --git a/services/src/main/java/org/keycloak/partialimport/RolesPartialImport.java b/services/src/main/java/org/keycloak/partialimport/RolesPartialImport.java index 2356d109cc..bbd127feb5 100644 --- a/services/src/main/java/org/keycloak/partialimport/RolesPartialImport.java +++ b/services/src/main/java/org/keycloak/partialimport/RolesPartialImport.java @@ -59,12 +59,12 @@ public class RolesPartialImport implements PartialImport { private RoleRepresentation newDefaultRole; @Override - public void prepare(PartialImportRepresentation rep, RealmModel realm, KeycloakSession session) throws ErrorResponseException { + public void prepare(PartialImportRepresentation rep, RealmModel realm, KeycloakSession session) { prepareRealmRoles(rep, realm, session); prepareClientRoles(rep, realm, session); } - private void prepareRealmRoles(PartialImportRepresentation rep, RealmModel realm, KeycloakSession session) throws ErrorResponseException { + private void prepareRealmRoles(PartialImportRepresentation rep, RealmModel realm, KeycloakSession session) { if (!rep.hasRealmRoles()) return; realmRolesPI.prepare(rep, realm, session); @@ -82,7 +82,7 @@ public class RolesPartialImport implements PartialImport { this.realmRolesToSkip = realmRolesPI.getToSkip(); } - private void prepareClientRoles(PartialImportRepresentation rep, RealmModel realm, KeycloakSession session) throws ErrorResponseException { + private void prepareClientRoles(PartialImportRepresentation rep, RealmModel realm, KeycloakSession session) { if (!rep.hasClientRoles()) return; clientRolesPI.prepare(rep, realm, session); @@ -97,7 +97,7 @@ public class RolesPartialImport implements PartialImport { } @Override - public PartialImportResults doImport(PartialImportRepresentation rep, RealmModel realm, KeycloakSession session) throws ErrorResponseException { + public PartialImportResults doImport(PartialImportRepresentation rep, RealmModel realm, KeycloakSession session) { PartialImportResults results = new PartialImportResults(); if (!rep.hasRealmRoles() && !rep.hasClientRoles()) return results; diff --git a/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java b/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java index d04db2dad6..b734e6be75 100644 --- a/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java @@ -92,7 +92,6 @@ import org.keycloak.models.UserSessionModel; import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.ModelToRepresentation; import org.keycloak.models.utils.RepresentationToModel; -import org.keycloak.partialimport.ErrorResponseException; import org.keycloak.partialimport.PartialImportResult; import org.keycloak.partialimport.PartialImportResults; import org.keycloak.representations.adapters.action.GlobalRequestResult; @@ -1120,10 +1119,6 @@ public class RealmAdminResource { ).build(); } catch (ModelDuplicateException e) { throw ErrorResponse.exists(e.getLocalizedMessage()); - } catch (ErrorResponseException error) { - return error.getResponse(); - } catch (Exception e) { - throw ErrorResponse.error(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } }