Fix adding social link in mongo. Fixed export/import of federationProviders. Enhanced ExportImportTest
This commit is contained in:
parent
5214fe2a55
commit
5673fb34b1
8 changed files with 31 additions and 18 deletions
|
@ -71,6 +71,7 @@ public class ExportUtils {
|
|||
List<OAuthClientRepresentation> oauthClientReps = new ArrayList<OAuthClientRepresentation>();
|
||||
for (OAuthClientModel oauthClient : oauthClients) {
|
||||
OAuthClientRepresentation clientRep = ModelToRepresentation.toRepresentation(oauthClient);
|
||||
clientRep.setSecret(oauthClient.getSecret());
|
||||
oauthClientReps.add(clientRep);
|
||||
}
|
||||
rep.setOauthClients(oauthClientReps);
|
||||
|
|
|
@ -182,7 +182,7 @@ public class ImportUtils {
|
|||
parser.nextToken();
|
||||
String currRealmName = parser.getText();
|
||||
if (!currRealmName.equals(realmName)) {
|
||||
throw new IllegalStateException("Trying to import users into invalid realm. Realm name: " + realmName + ", Expected realm name: " + realmName);
|
||||
throw new IllegalStateException("Trying to import users into invalid realm. Realm name: " + realmName + ", Expected realm name: " + currRealmName);
|
||||
}
|
||||
} else if ("users".equals(parser.getText())) {
|
||||
parser.nextToken();
|
||||
|
|
|
@ -5,9 +5,6 @@ import java.io.FileInputStream;
|
|||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -86,7 +83,7 @@ public class DirImportProvider implements ImportProvider {
|
|||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return (name.startsWith(realmName)) && (name.endsWith(".json")) && (name.substring(realmName.length()).contains("-users-") );
|
||||
return name.matches(realmName + "-users-[0-9]+\\.json");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ public class ZipImportProvider implements ImportProvider {
|
|||
// Import users
|
||||
for (ExtZipEntry entry : this.decrypter.getEntryList()) {
|
||||
String name = entry.getName();
|
||||
if ( (name.startsWith(realmName)) && (name.endsWith(".json")) && (name.substring(realmName.length()).contains("-users-")) ) {
|
||||
if (name.matches(realmName + "-users-[0-9]+\\.json")) {
|
||||
bos = new ByteArrayOutputStream();
|
||||
this.decrypter.extractEntry(entry, bos, this.password);
|
||||
final ByteArrayInputStream bis2 = new ByteArrayInputStream(bos.toByteArray());
|
||||
|
|
|
@ -134,10 +134,7 @@ public class ModelToRepresentation {
|
|||
if (fedProviderModels.size() > 0) {
|
||||
List<UserFederationProviderRepresentation> fedProviderReps = new ArrayList<UserFederationProviderRepresentation>();
|
||||
for (UserFederationProviderModel model : fedProviderModels) {
|
||||
UserFederationProviderRepresentation fedProvRep = new UserFederationProviderRepresentation();
|
||||
fedProvRep.setId(model.getId());
|
||||
fedProvRep.setProviderName(model.getProviderName());
|
||||
fedProvRep.setConfig(model.getConfig());
|
||||
UserFederationProviderRepresentation fedProvRep = toRepresentation(model);
|
||||
fedProviderReps.add(fedProvRep);
|
||||
}
|
||||
rep.setUserFederationProviders(fedProviderReps);
|
||||
|
|
|
@ -297,6 +297,7 @@ public class MongoUserProvider implements UserProvider {
|
|||
|
||||
@Override
|
||||
public void addSocialLink(RealmModel realm, UserModel user, SocialLinkModel socialLink) {
|
||||
user = getUserById(user.getId(), realm);
|
||||
MongoUserEntity userEntity = ((UserAdapter) user).getUser();
|
||||
SocialLinkEntity socialLinkEntity = new SocialLinkEntity();
|
||||
socialLinkEntity.setSocialProvider(socialLink.getSocialProvider());
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package org.keycloak.testsuite.exportimport;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
@ -26,10 +28,14 @@ import org.keycloak.models.KeycloakSession;
|
|||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.UserProvider;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.testsuite.model.AbstractModelTest;
|
||||
import org.keycloak.testsuite.model.ImportTest;
|
||||
import org.keycloak.testsuite.rule.KeycloakRule;
|
||||
|
||||
/**
|
||||
|
@ -92,14 +98,22 @@ public class ExportImportTest {
|
|||
|
||||
@Override
|
||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||
// Create some users in "test" and "master" realms
|
||||
addUser(manager.getSession().users(), appRealm, "user1", "password");
|
||||
addUser(manager.getSession().users(), appRealm, "user2", "password");
|
||||
addUser(manager.getSession().users(), appRealm, "user3", "password");
|
||||
addUser(manager.getSession().users(), adminstrationRealm, "admin2", "admin2");
|
||||
|
||||
// Import "test-realm" realm
|
||||
try {
|
||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm.json");
|
||||
RealmModel demoRealm = manager.createRealm("test-realm", rep.getRealm());
|
||||
manager.importRealm(rep, demoRealm);
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}) {
|
||||
@Override
|
||||
protected void after() {
|
||||
|
@ -137,8 +151,8 @@ public class ExportImportTest {
|
|||
|
||||
testFullExportImport();
|
||||
|
||||
// There should be 4 files in target directory (2 realm, 2 user)
|
||||
Assert.assertEquals(4, new File(targetDirPath).listFiles().length);
|
||||
// There should be 6 files in target directory (3 realm, 3 user)
|
||||
Assert.assertEquals(6, new File(targetDirPath).listFiles().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -210,7 +224,7 @@ public class ExportImportTest {
|
|||
RealmProvider realmProvider = session.realms();
|
||||
UserProvider userProvider = session.users();
|
||||
new RealmManager(session).removeRealm(realmProvider.getRealmByName("test"));
|
||||
Assert.assertEquals(1, realmProvider.getRealms().size());
|
||||
Assert.assertEquals(2, realmProvider.getRealms().size());
|
||||
|
||||
RealmModel master = realmProvider.getRealmByName(Config.getAdminRealm());
|
||||
UserModel admin2 = session.users().getUserByUsername("admin2", master);
|
||||
|
@ -235,7 +249,7 @@ public class ExportImportTest {
|
|||
try {
|
||||
RealmProvider model = session.realms();
|
||||
UserProvider userProvider = session.users();
|
||||
Assert.assertEquals(2, model.getRealms().size());
|
||||
Assert.assertEquals(3, model.getRealms().size());
|
||||
|
||||
assertAuthenticated(userProvider, model, Config.getAdminRealm(), "admin2", "admin2");
|
||||
assertAuthenticated(userProvider, model, "test", "test-user@localhost", "password");
|
||||
|
@ -243,6 +257,8 @@ public class ExportImportTest {
|
|||
assertAuthenticated(userProvider, model, "test", "user2", "password");
|
||||
assertAuthenticated(userProvider, model, "test", "user3", "password");
|
||||
|
||||
RealmModel testRealmRealm = model.getRealm("test-realm");
|
||||
ImportTest.assertDataImportedInRealm(session, testRealmRealm);
|
||||
} finally {
|
||||
keycloakRule.stopSession(session, true);
|
||||
}
|
||||
|
@ -261,7 +277,7 @@ public class ExportImportTest {
|
|||
RealmProvider realmProvider = session.realms();
|
||||
UserProvider userProvider = session.users();
|
||||
new RealmManager(session).removeRealm(realmProvider.getRealmByName("test"));
|
||||
Assert.assertEquals(1, realmProvider.getRealms().size());
|
||||
Assert.assertEquals(2, realmProvider.getRealms().size());
|
||||
|
||||
RealmModel master = realmProvider.getRealmByName(Config.getAdminRealm());
|
||||
UserModel admin2 = session.users().getUserByUsername("admin2", master);
|
||||
|
@ -287,7 +303,7 @@ public class ExportImportTest {
|
|||
try {
|
||||
RealmProvider realmProvider = session.realms();
|
||||
UserProvider userProvider = session.users();
|
||||
Assert.assertEquals(2, realmProvider.getRealms().size());
|
||||
Assert.assertEquals(3, realmProvider.getRealms().size());
|
||||
|
||||
assertNotAuthenticated(userProvider, realmProvider, Config.getAdminRealm(), "admin2", "admin2");
|
||||
assertAuthenticated(userProvider, realmProvider, "test", "test-user@localhost", "password");
|
||||
|
|
|
@ -185,6 +185,7 @@ public class ImportTest extends AbstractModelTest {
|
|||
Assert.assertTrue(session.users().removeSocialLink(realm, socialUser, "facebook"));
|
||||
Assert.assertNull(session.users().getSocialLink(socialUser, "facebook", realm));
|
||||
Assert.assertFalse(session.users().removeSocialLink(realm, socialUser, "facebook"));
|
||||
session.users().addSocialLink(realm, socialUser, new SocialLinkModel("facebook", "facebook1", "fbuser1"));
|
||||
|
||||
// Test smtp config
|
||||
Map<String, String> smtpConfig = realm.getSmtpConfig();
|
||||
|
|
Loading…
Reference in a new issue