|
|
|
@ -15,6 +15,7 @@ import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
@ -32,6 +33,7 @@ import org.keycloak.admin.client.resource.RealmResource;
|
|
|
|
|
import org.keycloak.admin.client.resource.ResourceResource;
|
|
|
|
|
import org.keycloak.admin.client.resource.RoleResource;
|
|
|
|
|
import org.keycloak.admin.client.resource.UserResource;
|
|
|
|
|
import org.keycloak.representations.idm.RoleRepresentation;
|
|
|
|
|
import org.keycloak.representations.idm.authorization.DecisionStrategy;
|
|
|
|
|
import org.keycloak.representations.idm.authorization.Logic;
|
|
|
|
|
import org.keycloak.representations.idm.authorization.ResourceRepresentation;
|
|
|
|
@ -41,8 +43,9 @@ 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 CREATE_CLIENTS = false;
|
|
|
|
|
private static final boolean MAP_ROLES = true;
|
|
|
|
|
private static final boolean DL_AVATARS = false;
|
|
|
|
|
private static final boolean SHOW_STATS = true;
|
|
|
|
|
|
|
|
|
|
private KeycloakHelper kh;
|
|
|
|
@ -181,6 +184,18 @@ public class ClientsCreatorFromExport {
|
|
|
|
|
System.out.println("\tcontext: " + userContext);
|
|
|
|
|
ClientResource clientResource = kh.findClient(realmResource, clientId);
|
|
|
|
|
if (clientResource != null) {
|
|
|
|
|
List<RoleRepresentation> oldRoles = userResource.roles().clientLevel(clientResource.toRepresentation().getId()).listAll();
|
|
|
|
|
RoleRepresentation memberRole = null;
|
|
|
|
|
for (RoleRepresentation roleRepresentation : oldRoles) {
|
|
|
|
|
if (roleRepresentation.getName().equals(Role.MEMBER.asString())) {
|
|
|
|
|
memberRole = roleRepresentation;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
oldRoles.remove(memberRole);
|
|
|
|
|
if (oldRoles.size() > 0) {
|
|
|
|
|
System.out.println("\t\tremoving old roles [" + oldRoles + "]");
|
|
|
|
|
userResource.roles().clientLevel(clientResource.toRepresentation().getId()).remove(oldRoles);
|
|
|
|
|
}
|
|
|
|
|
// This is no more needed, it is assigned automatically since is member
|
|
|
|
|
// of the corresponding LDAP group
|
|
|
|
|
// System.out.println("\t\tmapping default role: " + Role.MEMBER.asString());
|
|
|
|
@ -308,7 +323,7 @@ public class ClientsCreatorFromExport {
|
|
|
|
|
lap = new Date();
|
|
|
|
|
System.out.println("[lap seconds: " + new Long(lap.getTime() - start.getTime()).floatValue() / 1000 + "]");
|
|
|
|
|
}
|
|
|
|
|
if (avatarBaseURL != null) {
|
|
|
|
|
if (DL_AVATARS && avatarBaseURL != null) {
|
|
|
|
|
System.out.println("\n\n * * * Exporting user's avatar * * *");
|
|
|
|
|
creator.saveAvatarsLocally(avatarBaseURL, avatarExportFolder);
|
|
|
|
|
}
|
|
|
|
|