+
Skip to content

fix: resolve ProxyBuilderImpl ClassNotFoundException in parallel import #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [6.4.1] - 2025-03-11
### Added
- Explicitly set the class loader in parallel forEach consumers

### Fixed
- Fix `ClassNotFoundException: org.jboss.resteasy.client.jaxrs.internal.proxy.ProxyBuilderImpl` exception when using parallel imports [#1107](https://github.com/adorsys/keycloak-config-cli/issues/1107)

## [6.4.0] - 2025-02-21
### Added
- Allow a user's username to be updated through the config [#810](https://github.com/adorsys/keycloak-config-cli/issues/810)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import de.adorsys.keycloak.config.util.ClientScopeUtil;
import de.adorsys.keycloak.config.util.CloneUtil;
import de.adorsys.keycloak.config.util.KeycloakUtil;
import de.adorsys.keycloak.config.util.ParallelUtil;
import de.adorsys.keycloak.config.util.ProtocolMapperUtil;
import de.adorsys.keycloak.config.util.ResponseUtil;
import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -111,7 +112,7 @@ private void createOrUpdateClients(
) {
Consumer<ClientRepresentation> loop = client -> createOrUpdateClient(realmImport, client);
if (importConfigProperties.isParallel()) {
clients.parallelStream().forEach(loop);
ParallelUtil.forEach(clients, loop);
} else {
clients.forEach(loop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import de.adorsys.keycloak.config.repository.ClientScopeRepository;
import de.adorsys.keycloak.config.repository.RealmRepository;
import de.adorsys.keycloak.config.util.CloneUtil;
import de.adorsys.keycloak.config.util.ParallelUtil;
import de.adorsys.keycloak.config.util.ProtocolMapperUtil;
import org.keycloak.representations.idm.ClientScopeRepresentation;
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
Expand Down Expand Up @@ -172,7 +173,7 @@ private void createOrUpdateClientScopes(
) {
Consumer<ClientScopeRepresentation> loop = clientScope -> createOrUpdateClientScope(realmName, clientScope);
if (importConfigProperties.isParallel()) {
clientScopes.parallelStream().forEach(loop);
ParallelUtil.forEach(clientScopes, loop);
} else {
clientScopes.forEach(loop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.adorsys.keycloak.config.properties.ImportConfigProperties.ImportManagedProperties.ImportManagedPropertiesValues;
import de.adorsys.keycloak.config.repository.GroupRepository;
import de.adorsys.keycloak.config.util.CloneUtil;
import de.adorsys.keycloak.config.util.ParallelUtil;
import org.keycloak.representations.idm.GroupRepresentation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void importGroups(RealmImport realmImport) {
public void createOrUpdateGroups(List<GroupRepresentation> groups, String realmName) {
Consumer<GroupRepresentation> loop = group -> createOrUpdateRealmGroup(realmName, group);
if (importConfigProperties.isParallel()) {
groups.parallelStream().forEach(loop);
ParallelUtil.forEach(groups, loop);
} else {
groups.forEach(loop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import de.adorsys.keycloak.config.service.state.StateService;
import de.adorsys.keycloak.config.util.CloneUtil;
import de.adorsys.keycloak.config.util.KeycloakUtil;
import de.adorsys.keycloak.config.util.ParallelUtil;
import org.keycloak.representations.idm.RoleRepresentation;
import org.keycloak.representations.idm.RolesRepresentation;
import org.slf4j.Logger;
Expand Down Expand Up @@ -124,7 +125,7 @@ private void createOrUpdateRealmRoles(
) {
Consumer<RoleRepresentation> loop = role -> createOrUpdateRealmRole(realmName, role, existingRealmRoles);
if (importConfigProperties.isParallel()) {
rolesToImport.parallelStream().forEach(loop);
ParallelUtil.forEach(rolesToImport, loop);
} else {
rolesToImport.forEach(loop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import de.adorsys.keycloak.config.repository.UserRepository;
import de.adorsys.keycloak.config.util.CloneUtil;
import de.adorsys.keycloak.config.util.KeycloakUtil;
import de.adorsys.keycloak.config.util.ParallelUtil;
import org.keycloak.representations.idm.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -87,7 +88,7 @@ public void doImport(RealmImport realmImport) {

Consumer<UserRepresentation> loop = user -> importUser(realmImport.getRealm(), user);
if (importConfigProperties.isParallel()) {
users.parallelStream().forEach(loop);
ParallelUtil.forEach(users, loop);
} else {
users.forEach(loop);
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/de/adorsys/keycloak/config/util/ParallelUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*-
* ---license-start
* keycloak-config-cli
* ---
* Copyright (C) 2017 - 2021 adorsys GmbH & Co. KG @ https://adorsys.com
* ---
* 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.
* ---license-end
*/

package de.adorsys.keycloak.config.util;

import java.util.List;
import java.util.function.Consumer;

// Override the default implementation of the forEach method in the ParallelUtil class
// Found that the class loader in threads is different from the application class loader,
// leading to [this issue](https://github.com/adorsys/keycloak-config-cli/issues/1107)
public class ParallelUtil {
public static <T> void forEach(List<T> list, Consumer<T> consumer) {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
list.parallelStream()
.forEach(x -> {
Thread.currentThread().setContextClassLoader(originalClassLoader);
consumer.accept(x);
});
}
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载