From e7dd49b45346fd325263471c548c2cefd8a7d6c0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 1 Dec 2016 19:42:06 -0200 Subject: [PATCH] [KEYCLOAK-4011] - Integrity constraint error when try to delete SSSD Federation Provider --- .../keycloak/models/jpa/JpaUserProvider.java | 4 +++ .../org/keycloak/testsuite/sssd/SSSDTest.java | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java index d69e021228..8e1d2eb5a1 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java @@ -405,6 +405,10 @@ public class JpaUserProvider implements UserProvider, UserCredentialStore { .setParameter("realmId", realm.getId()) .setParameter("link", linkId) .executeUpdate(); + num = em.createNamedQuery("deleteUserGroupMembershipsByRealmAndLink") + .setParameter("realmId", realm.getId()) + .setParameter("link", linkId) + .executeUpdate(); num = em.createNamedQuery("deleteUsersByRealmAndLink") .setParameter("realmId", realm.getId()) .setParameter("link", linkId) diff --git a/testsuite/integration-arquillian/tests/other/sssd/src/test/java/org/keycloak/testsuite/sssd/SSSDTest.java b/testsuite/integration-arquillian/tests/other/sssd/src/test/java/org/keycloak/testsuite/sssd/SSSDTest.java index 56fe43a0d7..91858c929c 100644 --- a/testsuite/integration-arquillian/tests/other/sssd/src/test/java/org/keycloak/testsuite/sssd/SSSDTest.java +++ b/testsuite/integration-arquillian/tests/other/sssd/src/test/java/org/keycloak/testsuite/sssd/SSSDTest.java @@ -2,27 +2,24 @@ package org.keycloak.testsuite.sssd; import org.jboss.arquillian.graphene.page.Page; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.keycloak.common.util.MultivaluedHashMap; import org.keycloak.representations.idm.ComponentRepresentation; import org.keycloak.representations.idm.GroupRepresentation; import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.representations.idm.UserFederationProviderFactoryRepresentation; -import org.keycloak.representations.idm.UserFederationProviderRepresentation; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.storage.UserStorageProvider; import org.keycloak.testsuite.AbstractKeycloakTest; import org.keycloak.testsuite.Assert; import org.keycloak.testsuite.AssertEvents; +import org.keycloak.testsuite.admin.ApiUtil; import org.keycloak.testsuite.pages.AccountPasswordPage; import org.keycloak.testsuite.pages.AccountUpdateProfilePage; import org.keycloak.testsuite.pages.LoginPage; -import java.util.HashMap; +import javax.ws.rs.core.Response; import java.util.List; -import java.util.Map; public class SSSDTest extends AbstractKeycloakTest { @@ -52,6 +49,8 @@ public class SSSDTest extends AbstractKeycloakTest { @Rule public AssertEvents events = new AssertEvents(this); + private String SSSDFederationID; + @Override public void addTestRealms(List testRealms) { RealmRepresentation realm = new RealmRepresentation(); @@ -74,7 +73,9 @@ public class SSSDTest extends AbstractKeycloakTest { userFederation.setProviderType(UserStorageProvider.class.getName()); userFederation.setProviderId(PROVIDER_NAME); - adminClient.realm(REALM_NAME).components().add(userFederation); + Response response = adminClient.realm(REALM_NAME).components().add(userFederation); + SSSDFederationID = ApiUtil.getCreatedId(response); + response.close(); } @Test @@ -120,6 +121,21 @@ public class SSSDTest extends AbstractKeycloakTest { testUserGroups(); } + @Test + public void testDeleteSSSDFederationProvider() { + log.debug("Testing correct password"); + + driver.navigate().to(getAccountUrl()); + Assert.assertEquals("Browser should be on login page now", "Log in to " + REALM_NAME, driver.getTitle()); + accountLoginPage.login(USERNAME, PASSWORD); + Assert.assertTrue(profilePage.isCurrent()); + testUserGroups(); + int componentsListSize = adminClient.realm(REALM_NAME).components().query().size(); + adminClient.realm(REALM_NAME).components().component(SSSDFederationID).remove(); + Assert.assertEquals(componentsListSize - 1, adminClient.realm(REALM_NAME).components().query().size()); + } + + @Test public void changeReadOnlyProfile() throws Exception {