Skip to content

Commit

Permalink
Fix for workflow failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Thendo20 committed Dec 3, 2024
1 parent 718a3a5 commit 9f1733d
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
package de.adorsys.keycloak.config.repository;

import de.adorsys.keycloak.config.exception.KeycloakRepositoryException;
import de.adorsys.keycloak.config.provider.KeycloakProvider;
import de.adorsys.keycloak.config.util.VersionUtil;
import org.keycloak.admin.client.CreatedResponseUtil;
import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
Expand All @@ -30,6 +32,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand All @@ -39,10 +42,12 @@
public class UserRepository {

private final RealmRepository realmRepository;
private final KeycloakProvider keycloakProvider;

@Autowired
public UserRepository(RealmRepository realmRepository) {
public UserRepository(RealmRepository realmRepository, KeycloakProvider keycloakProvider) {
this.realmRepository = realmRepository;
this.keycloakProvider = keycloakProvider;
}

public Optional<UserRepresentation> search(String realmName, String username) {
Expand All @@ -61,7 +66,11 @@ public Optional<UserRepresentation> search(String realmName, String username) {

public Optional<UserRepresentation> searchByEmail(String realmName, String email) {
UsersResource usersResource = realmRepository.getResource(realmName).users();
List<UserRepresentation> foundUsers = usersResource.searchByEmail(email, true);
List<UserRepresentation> foundUsers = new ArrayList<>();

if (VersionUtil.ge(keycloakProvider.getKeycloakVersion(), "20")) {
foundUsers = usersResource.searchByEmail(email, true);
}

Optional<UserRepresentation> user;
if (foundUsers.isEmpty()) {
Expand Down

0 comments on commit 9f1733d

Please sign in to comment.