|
|
|
@ -40,6 +40,11 @@ import org.xml.sax.SAXException;
|
|
|
|
|
|
|
|
|
|
public class ClientsCreatorFromExport {
|
|
|
|
|
|
|
|
|
|
private static final boolean DELETE_CLIENTS = false;
|
|
|
|
|
private static final boolean CREATE_CLIENTS = true;
|
|
|
|
|
private static final boolean MAP_ROLES = true;
|
|
|
|
|
private static final boolean SHOW_STATS = true;
|
|
|
|
|
|
|
|
|
|
private KeycloakHelper kh;
|
|
|
|
|
private Keycloak keycloak;
|
|
|
|
|
private ExportParser exportParser;
|
|
|
|
@ -96,8 +101,9 @@ public class ClientsCreatorFromExport {
|
|
|
|
|
configureClientResource(client, roleMap, client.authorization().resources().resources().get(0));
|
|
|
|
|
}
|
|
|
|
|
// Mapping group (from LDAP mapping) to relatives client's Member role
|
|
|
|
|
System.out.println("\tMapping '" + realmResource + "' LDAP group to client's 'Member' role");
|
|
|
|
|
kh.mapGroupToCLientRole(kh.findGroupByPath(realmResource, contextClient), client, roleMap.get(Role.MEMBER));
|
|
|
|
|
String ldapGroupPath = contextClient.substring(1);
|
|
|
|
|
System.out.println("\tMapping '" + ldapGroupPath + "' LDAP group to client's 'Member' role");
|
|
|
|
|
kh.mapGroupToCLientRole(kh.findGroupByPath(realmResource, ldapGroupPath), client, roleMap.get(Role.MEMBER));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -221,7 +227,7 @@ public class ClientsCreatorFromExport {
|
|
|
|
|
}
|
|
|
|
|
for (String username : usersAndAvatars.keySet()) {
|
|
|
|
|
String avatarURLSuffix = usersAndAvatars.get(username);
|
|
|
|
|
if (avatarURLSuffix != null) {
|
|
|
|
|
if (avatarURLSuffix != null) {
|
|
|
|
|
System.out.println("- Saving avatar of user: " + username);
|
|
|
|
|
try {
|
|
|
|
|
URL avatarURL = new URL(baseURL, avatarURLSuffix);
|
|
|
|
@ -282,29 +288,44 @@ public class ClientsCreatorFromExport {
|
|
|
|
|
exportFileFIS);
|
|
|
|
|
|
|
|
|
|
Date start = new Date();
|
|
|
|
|
Date lap;
|
|
|
|
|
System.out.println("Start at " + start);
|
|
|
|
|
// System.out.println("Deleting clients...");
|
|
|
|
|
// creator.deleteClients();
|
|
|
|
|
System.out.println("\n\n * * * Creating clients * * *");
|
|
|
|
|
creator.createClients();
|
|
|
|
|
System.out.println("\n\n * * * Mapping users to client's roles * * *");
|
|
|
|
|
creator.mapUsersWithRolesToClients();
|
|
|
|
|
if (DELETE_CLIENTS) {
|
|
|
|
|
System.out.println("Deleting clients...");
|
|
|
|
|
creator.deleteClients();
|
|
|
|
|
lap = new Date();
|
|
|
|
|
System.out.println("[lap seconds: " + new Long(lap.getTime() - start.getTime()).floatValue() / 1000 + "]");
|
|
|
|
|
}
|
|
|
|
|
if (CREATE_CLIENTS) {
|
|
|
|
|
System.out.println("\n\n * * * Creating clients * * *");
|
|
|
|
|
creator.createClients();
|
|
|
|
|
lap = new Date();
|
|
|
|
|
System.out.println("[lap seconds: " + new Long(lap.getTime() - start.getTime()).floatValue() / 1000 + "]");
|
|
|
|
|
}
|
|
|
|
|
if (MAP_ROLES) {
|
|
|
|
|
System.out.println("\n\n * * * Mapping users to client's roles * * *");
|
|
|
|
|
creator.mapUsersWithRolesToClients();
|
|
|
|
|
lap = new Date();
|
|
|
|
|
System.out.println("[lap seconds: " + new Long(lap.getTime() - start.getTime()).floatValue() / 1000 + "]");
|
|
|
|
|
}
|
|
|
|
|
if (avatarBaseURL != null) {
|
|
|
|
|
System.out.println("\n\n * * * Exporting user's avatar * * *");
|
|
|
|
|
creator.saveAvatarsLocally(avatarBaseURL, avatarExportFolder);
|
|
|
|
|
}
|
|
|
|
|
Date end = new Date();
|
|
|
|
|
System.out.println("Elapsed seconds: " + new Long(end.getTime() - start.getTime()).floatValue() / 1000);
|
|
|
|
|
System.out.println("\nClients: " + creator.getExportParser().getAllContexts().size());
|
|
|
|
|
System.out.println("Users: " + creator.getExportParser().getAllUsersAndAvatars().size());
|
|
|
|
|
Map<String, Map<String, Set<String>>> ucar = creator.getExportParser().getAllUserContextsAndRoles();
|
|
|
|
|
float rolesPerUserMean = 0;
|
|
|
|
|
for (String user : ucar.keySet()) {
|
|
|
|
|
for (String context : ucar.get(user).keySet()) {
|
|
|
|
|
rolesPerUserMean += ucar.get(user).get(context).size() + 1;
|
|
|
|
|
System.out.println("Total elapsed seconds: " + new Long(end.getTime() - start.getTime()).floatValue() / 1000);
|
|
|
|
|
if (SHOW_STATS) {
|
|
|
|
|
System.out.println("\nClients: " + creator.getExportParser().getAllContexts().size());
|
|
|
|
|
System.out.println("Users: " + creator.getExportParser().getAllUsersAndAvatars().size());
|
|
|
|
|
Map<String, Map<String, Set<String>>> ucar = creator.getExportParser().getAllUserContextsAndRoles();
|
|
|
|
|
float totalUsersRoles = 0;
|
|
|
|
|
for (String user : ucar.keySet()) {
|
|
|
|
|
for (String context : ucar.get(user).keySet()) {
|
|
|
|
|
totalUsersRoles += ucar.get(user).get(context).size() + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println(
|
|
|
|
|
"Roles per user: " + totalUsersRoles / creator.getExportParser().getAllUsersAndAvatars().size());
|
|
|
|
|
}
|
|
|
|
|
System.out.println(
|
|
|
|
|
"Roles per user mean: " + rolesPerUserMean / creator.getExportParser().getAllUsersAndAvatars().size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|