Skip to content
Snippets Groups Projects
Commit 3dd24775 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-6472 upgrade to keycloak admin lib 24' (#120) from...

Merge pull request 'OZG-6472 upgrade to keycloak admin lib 24' (#120) from OZG-6472-upgrade-to-keycloak24 into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/user-manager/pulls/120


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents e2b5e58e f7557721
Branches
Tags
No related merge requests found
...@@ -42,6 +42,11 @@ ...@@ -42,6 +42,11 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>24.0.5</version>
</dependency>
<dependency>
<groupId>de.ozgcloud.user</groupId> <groupId>de.ozgcloud.user</groupId>
<artifactId>user-manager-interface</artifactId> <artifactId>user-manager-interface</artifactId>
</dependency> </dependency>
......
...@@ -108,7 +108,7 @@ class KeycloakApiService { ...@@ -108,7 +108,7 @@ class KeycloakApiService {
void tryUpdateUserResource(UserResource userResource, UserRepresentation userRepresentation, String attributeName) { void tryUpdateUserResource(UserResource userResource, UserRepresentation userRepresentation, String attributeName) {
try { try {
userResource.update(new OlderUserRepresentation(userRepresentation)); userResource.update(userRepresentation);
} catch (BadRequestException e) { } catch (BadRequestException e) {
LOG.warn("Could not update user attribute {} in Keycloak.", attributeName, e); LOG.warn("Could not update user attribute {} in Keycloak.", attributeName, e);
} }
......
package de.ozgcloud.user.keycloak;
import org.keycloak.representations.idm.UserProfileMetadata;
import org.keycloak.representations.idm.UserRepresentation;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* This is a user representation which works with currently used Keycloak version 20.0.3 Because of Quarkus upgrade to 3.5.0 the keycloak admin client
* was updated to 22.0.5. The reason for that is the new resteasy client based on Jakarata EE 10 (jakarta.ws.rs-api). Keycloak admin client 20 .0.3 is
* based on Jersey (javax.ws.rs-api). What we do here is simple ignoring one field added in the newer version of Keycloak in order for entity to be
* processable by the older version. Once Keycloak will be upgraded we can remove this class.
*
* The workaround was discussed with Quarkus team https://github.com/quarkusio/quarkus/discussions/36766
*/
class OlderUserRepresentation extends UserRepresentation {
@JsonIgnore
private UserProfileMetadata userProfileMetadata;
public OlderUserRepresentation(UserRepresentation origin) {
setAttributes(origin.getAttributes());
setClientRoles(origin.getClientRoles());
setEmail(origin.getEmail());
setId(origin.getId());
setCreatedTimestamp(origin.getCreatedTimestamp());
setFirstName(origin.getFirstName());
setLastName(origin.getLastName());
setUsername(origin.getUsername());
setAccess(origin.getAccess());
setClientConsents(origin.getClientConsents());
setCredentials(origin.getCredentials());
setDisableableCredentialTypes(origin.getDisableableCredentialTypes());
setEmailVerified(origin.isEmailVerified());
setEnabled(origin.isEnabled());
setFederatedIdentities(origin.getFederatedIdentities());
setFederationLink(origin.getFederationLink());
setGroups(origin.getGroups());
setNotBefore(origin.getNotBefore());
setOrigin(origin.getOrigin());
setRealmRoles(origin.getRealmRoles());
setRequiredActions(origin.getRequiredActions());
setSelf(origin.getSelf());
setServiceAccountClientId(origin.getServiceAccountClientId());
setSocialLinks(origin.getSocialLinks());
setTotp(origin.isEmailVerified());
}
}
...@@ -272,4 +272,19 @@ class UserResourceStub implements UserResource { ...@@ -272,4 +272,19 @@ class UserResourceStub implements UserResource {
public Map<String, Object> impersonate() { public Map<String, Object> impersonate() {
return null; return null;
} }
@Override
public void sendVerifyEmail(String clientId, String redirectUri) {
// not implemented
}
@Override
public void sendVerifyEmail(Integer lifespan) {
// not implemented
}
@Override
public void sendVerifyEmail(String clientId, String redirectUri, Integer lifespan) {
// not implemented
}
} }
...@@ -276,7 +276,7 @@ class KeycloakApiServiceTest { ...@@ -276,7 +276,7 @@ class KeycloakApiServiceTest {
@Test @Test
void shouldCatchBadRequestException() { void shouldCatchBadRequestException() {
when(userRepresentation.firstAttribute(ATTRIBUTE_NAME_USER_ID)).thenReturn(NEW_USER_ID); when(userRepresentation.firstAttribute(ATTRIBUTE_NAME_USER_ID)).thenReturn(NEW_USER_ID);
doThrow(new BadRequestException("error message")).when(userResource).update(any(OlderUserRepresentation.class)); doThrow(new BadRequestException("error message")).when(userResource).update(any(UserRepresentation.class));
assertThatCode( assertThatCode(
() -> service.updateAttribute(KEYCLOAK_USER_ID, ATTRIBUTE_NAME_USER_ID, ATTRIBUTE_VALUE_USER_ID)).doesNotThrowAnyException(); () -> service.updateAttribute(KEYCLOAK_USER_ID, ATTRIBUTE_NAME_USER_ID, ATTRIBUTE_VALUE_USER_ID)).doesNotThrowAnyException();
...@@ -298,7 +298,7 @@ class KeycloakApiServiceTest { ...@@ -298,7 +298,7 @@ class KeycloakApiServiceTest {
void shouldUpdateUserResource() { void shouldUpdateUserResource() {
service.tryUpdateUserResource(userResource, userRepresentation, ATTRIBUTE_NAME_USER_ID); service.tryUpdateUserResource(userResource, userRepresentation, ATTRIBUTE_NAME_USER_ID);
verify(userResource).update(any(OlderUserRepresentation.class)); verify(userResource).update(any(UserRepresentation.class));
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment