KEYCLOAK-1187 Updated representations
This commit is contained in:
parent
716bf104db
commit
9a047eda36
16 changed files with 220 additions and 186 deletions
|
@ -1,38 +0,0 @@
|
|||
package org.keycloak.representations.idm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class ApplicationMappingsRepresentation {
|
||||
protected String applicationId;
|
||||
protected String application;
|
||||
|
||||
protected List<RoleRepresentation> mappings;
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
public void setApplicationId(String applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
}
|
||||
|
||||
public String getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(String application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public List<RoleRepresentation> getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
public void setMappings(List<RoleRepresentation> mappings) {
|
||||
this.mappings = mappings;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package org.keycloak.representations.idm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class ClientMappingsRepresentation {
|
||||
protected String id;
|
||||
protected String client;
|
||||
|
||||
protected List<RoleRepresentation> mappings;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setClient(String client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public List<RoleRepresentation> getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
public void setMappings(List<RoleRepresentation> mappings) {
|
||||
this.mappings = mappings;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import java.util.Map;
|
|||
*/
|
||||
public class MappingsRepresentation {
|
||||
protected List<RoleRepresentation> realmMappings;
|
||||
protected Map<String, ApplicationMappingsRepresentation> applicationMappings;
|
||||
protected Map<String, ClientMappingsRepresentation> clientMappings;
|
||||
|
||||
public List<RoleRepresentation> getRealmMappings() {
|
||||
return realmMappings;
|
||||
|
@ -19,11 +19,11 @@ public class MappingsRepresentation {
|
|||
this.realmMappings = realmMappings;
|
||||
}
|
||||
|
||||
public Map<String, ApplicationMappingsRepresentation> getApplicationMappings() {
|
||||
return applicationMappings;
|
||||
public Map<String, ClientMappingsRepresentation> getClientMappings() {
|
||||
return clientMappings;
|
||||
}
|
||||
|
||||
public void setApplicationMappings(Map<String, ApplicationMappingsRepresentation> applicationMappings) {
|
||||
this.applicationMappings = applicationMappings;
|
||||
public void setClientMappings(Map<String, ClientMappingsRepresentation> clientMappings) {
|
||||
this.clientMappings = clientMappings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,13 +25,6 @@ public class RealmRepresentation {
|
|||
protected Boolean verifyEmail;
|
||||
protected Boolean resetPasswordAllowed;
|
||||
|
||||
@Deprecated
|
||||
protected Boolean social;
|
||||
@Deprecated
|
||||
protected Boolean updateProfileOnInitialSocialLogin;
|
||||
@Deprecated
|
||||
protected Map<String, String> socialProviders;
|
||||
|
||||
protected Boolean userCacheEnabled;
|
||||
protected Boolean realmCacheEnabled;
|
||||
|
||||
|
@ -55,12 +48,8 @@ public class RealmRepresentation {
|
|||
protected String passwordPolicy;
|
||||
protected List<UserRepresentation> users;
|
||||
protected List<ScopeMappingRepresentation> scopeMappings;
|
||||
protected Map<String, List<ScopeMappingRepresentation>> applicationScopeMappings;
|
||||
protected Map<String, List<ScopeMappingRepresentation>> clientScopeMappings;
|
||||
protected List<ClientRepresentation> clients;
|
||||
@Deprecated
|
||||
protected List<ApplicationRepresentation> applications;
|
||||
@Deprecated
|
||||
protected List<OAuthClientRepresentation> oauthClients;
|
||||
protected Map<String, String> browserSecurityHeaders;
|
||||
protected Map<String, String> smtpServer;
|
||||
protected List<UserFederationProviderRepresentation> userFederationProviders;
|
||||
|
@ -79,6 +68,18 @@ public class RealmRepresentation {
|
|||
protected Set<String> supportedLocales;
|
||||
protected String defaultLocale;
|
||||
|
||||
@Deprecated
|
||||
protected Boolean social;
|
||||
@Deprecated
|
||||
protected Boolean updateProfileOnInitialSocialLogin;
|
||||
@Deprecated
|
||||
protected Map<String, String> socialProviders;
|
||||
@Deprecated
|
||||
protected Map<String, List<ScopeMappingRepresentation>> applicationScopeMappings;
|
||||
@Deprecated
|
||||
protected List<ApplicationRepresentation> applications;
|
||||
@Deprecated
|
||||
protected List<OAuthClientRepresentation> oauthClients;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
|
@ -124,10 +125,6 @@ public class RealmRepresentation {
|
|||
this.clients = clients;
|
||||
}
|
||||
|
||||
public void setApplications(List<ApplicationRepresentation> applications) {
|
||||
this.applications = applications;
|
||||
}
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
@ -324,22 +321,16 @@ public class RealmRepresentation {
|
|||
this.resetPasswordAllowed = resetPassword;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Boolean isSocial() {
|
||||
return social;
|
||||
}
|
||||
|
||||
public void setSocial(Boolean social) {
|
||||
this.social = social;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Boolean isUpdateProfileOnInitialSocialLogin() {
|
||||
return updateProfileOnInitialSocialLogin;
|
||||
}
|
||||
|
||||
public void setUpdateProfileOnInitialSocialLogin(Boolean updateProfileOnInitialSocialLogin) {
|
||||
this.updateProfileOnInitialSocialLogin = updateProfileOnInitialSocialLogin;
|
||||
}
|
||||
|
||||
public Map<String, String> getBrowserSecurityHeaders() {
|
||||
return browserSecurityHeaders;
|
||||
}
|
||||
|
@ -348,14 +339,11 @@ public class RealmRepresentation {
|
|||
this.browserSecurityHeaders = browserSecurityHeaders;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Map<String, String> getSocialProviders() {
|
||||
return socialProviders;
|
||||
}
|
||||
|
||||
public void setSocialProviders(Map<String, String> socialProviders) {
|
||||
this.socialProviders = socialProviders;
|
||||
}
|
||||
|
||||
public Map<String, String> getSmtpServer() {
|
||||
return smtpServer;
|
||||
}
|
||||
|
@ -364,22 +352,24 @@ public class RealmRepresentation {
|
|||
this.smtpServer = smtpServer;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public List<OAuthClientRepresentation> getOauthClients() {
|
||||
return oauthClients;
|
||||
}
|
||||
|
||||
public void setOauthClients(List<OAuthClientRepresentation> oauthClients) {
|
||||
this.oauthClients = oauthClients;
|
||||
public Map<String, List<ScopeMappingRepresentation>> getClientScopeMappings() {
|
||||
return clientScopeMappings;
|
||||
}
|
||||
|
||||
public void setClientScopeMappings(Map<String, List<ScopeMappingRepresentation>> clientScopeMappings) {
|
||||
this.clientScopeMappings = clientScopeMappings;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Map<String, List<ScopeMappingRepresentation>> getApplicationScopeMappings() {
|
||||
return applicationScopeMappings;
|
||||
}
|
||||
|
||||
public void setApplicationScopeMappings(Map<String, List<ScopeMappingRepresentation>> applicationScopeMappings) {
|
||||
this.applicationScopeMappings = applicationScopeMappings;
|
||||
}
|
||||
|
||||
public RolesRepresentation getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
|
|
@ -17,9 +17,10 @@ public class RoleRepresentation {
|
|||
|
||||
public static class Composites {
|
||||
protected Set<String> realm;
|
||||
protected Map<String, List<String>> client;
|
||||
@Deprecated
|
||||
protected Map<String, List<String>> application;
|
||||
|
||||
|
||||
public Set<String> getRealm() {
|
||||
return realm;
|
||||
}
|
||||
|
@ -28,12 +29,17 @@ public class RoleRepresentation {
|
|||
this.realm = realm;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getApplication() {
|
||||
return application;
|
||||
public Map<String, List<String>> getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setApplication(Map<String, List<String>> application) {
|
||||
this.application = application;
|
||||
public void setClient(Map<String, List<String>> client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Map<String, List<String>> getApplication() {
|
||||
return application;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ import java.util.Map;
|
|||
*/
|
||||
public class RolesRepresentation {
|
||||
protected List<RoleRepresentation> realm;
|
||||
protected Map<String, List<RoleRepresentation>> client;
|
||||
@Deprecated
|
||||
protected Map<String, List<RoleRepresentation>> application;
|
||||
|
||||
public List<RoleRepresentation> getRealm() {
|
||||
|
@ -19,11 +21,16 @@ public class RolesRepresentation {
|
|||
this.realm = realm;
|
||||
}
|
||||
|
||||
public Map<String, List<RoleRepresentation>> getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setClient(Map<String, List<RoleRepresentation>> client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Map<String, List<RoleRepresentation>> getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(Map<String, List<RoleRepresentation>> application) {
|
||||
this.application = application;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,10 +25,13 @@ public class UserRepresentation {
|
|||
protected List<CredentialRepresentation> credentials;
|
||||
protected List<String> requiredActions;
|
||||
protected List<FederatedIdentityRepresentation> federatedIdentities;
|
||||
protected List<String> realmRoles;
|
||||
protected Map<String, List<String>> clientRoles;
|
||||
|
||||
@Deprecated
|
||||
protected Map<String, List<String>> applicationRoles;
|
||||
@Deprecated
|
||||
protected List<SocialLinkRepresentation> socialLinks;
|
||||
protected List<String> realmRoles;
|
||||
protected Map<String, List<String>> applicationRoles;
|
||||
|
||||
public String getSelf() {
|
||||
return self;
|
||||
|
@ -165,12 +168,17 @@ public class UserRepresentation {
|
|||
this.realmRoles = realmRoles;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getApplicationRoles() {
|
||||
return applicationRoles;
|
||||
public Map<String, List<String>> getClientRoles() {
|
||||
return clientRoles;
|
||||
}
|
||||
|
||||
public void setApplicationRoles(Map<String, List<String>> applicationRoles) {
|
||||
this.applicationRoles = applicationRoles;
|
||||
public void setClientRoles(Map<String, List<String>> clientRoles) {
|
||||
this.clientRoles = clientRoles;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Map<String, List<String>> getApplicationRoles() {
|
||||
return applicationRoles;
|
||||
}
|
||||
|
||||
public String getFederationLink() {
|
||||
|
|
|
@ -15,7 +15,6 @@ public class UserSessionRepresentation {
|
|||
private String ipAddress;
|
||||
private long start;
|
||||
private long lastAccess;
|
||||
private Map<String, String> applications = new HashMap<String, String>();
|
||||
private Map<String, String> clients = new HashMap<String, String>();
|
||||
|
||||
public String getId() {
|
||||
|
@ -58,14 +57,6 @@ public class UserSessionRepresentation {
|
|||
this.lastAccess = lastAccess;
|
||||
}
|
||||
|
||||
public Map<String, String> getApplications() {
|
||||
return applications;
|
||||
}
|
||||
|
||||
public void setApplications(Map<String, String> applications) {
|
||||
this.applications = applications;
|
||||
}
|
||||
|
||||
public Map<String, String> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ public class Time {
|
|||
return new Date(((long) time ) * 1000);
|
||||
}
|
||||
|
||||
public static long toMillis(int time) {
|
||||
return ((long) time) * 1000;
|
||||
}
|
||||
|
||||
public static void setOffset(int offset) {
|
||||
Time.offset = offset;
|
||||
}
|
||||
|
|
|
@ -65,30 +65,30 @@ public class ExportUtils {
|
|||
|
||||
// Roles
|
||||
List<RoleRepresentation> realmRoleReps = null;
|
||||
Map<String, List<RoleRepresentation>> appRolesReps = new HashMap<String, List<RoleRepresentation>>();
|
||||
Map<String, List<RoleRepresentation>> clientRolesReps = new HashMap<>();
|
||||
|
||||
Set<RoleModel> realmRoles = realm.getRoles();
|
||||
if (realmRoles != null && realmRoles.size() > 0) {
|
||||
realmRoleReps = exportRoles(realmRoles);
|
||||
}
|
||||
for (ClientModel app : clients) {
|
||||
Set<RoleModel> currentAppRoles = app.getRoles();
|
||||
for (ClientModel client : clients) {
|
||||
Set<RoleModel> currentAppRoles = client.getRoles();
|
||||
List<RoleRepresentation> currentAppRoleReps = exportRoles(currentAppRoles);
|
||||
appRolesReps.put(app.getClientId(), currentAppRoleReps);
|
||||
clientRolesReps.put(client.getClientId(), currentAppRoleReps);
|
||||
}
|
||||
|
||||
RolesRepresentation rolesRep = new RolesRepresentation();
|
||||
if (realmRoleReps != null) {
|
||||
rolesRep.setRealm(realmRoleReps);
|
||||
}
|
||||
if (appRolesReps.size() > 0) {
|
||||
rolesRep.setApplication(appRolesReps);
|
||||
if (clientRolesReps.size() > 0) {
|
||||
rolesRep.setClient(clientRolesReps);
|
||||
}
|
||||
rep.setRoles(rolesRep);
|
||||
|
||||
// Scopes
|
||||
List<ClientModel> allClients = new ArrayList<>(clients);
|
||||
Map<String, List<ScopeMappingRepresentation>> appScopeReps = new HashMap<>();
|
||||
Map<String, List<ScopeMappingRepresentation>> clientScopeReps = new HashMap<>();
|
||||
|
||||
for (ClientModel client : allClients) {
|
||||
Set<RoleModel> clientScopes = client.getScopeMappings();
|
||||
|
@ -102,10 +102,10 @@ public class ExportUtils {
|
|||
} else {
|
||||
ClientModel app = (ClientModel)scope.getContainer();
|
||||
String appName = app.getClientId();
|
||||
List<ScopeMappingRepresentation> currentAppScopes = appScopeReps.get(appName);
|
||||
List<ScopeMappingRepresentation> currentAppScopes = clientScopeReps.get(appName);
|
||||
if (currentAppScopes == null) {
|
||||
currentAppScopes = new ArrayList<>();
|
||||
appScopeReps.put(appName, currentAppScopes);
|
||||
clientScopeReps.put(appName, currentAppScopes);
|
||||
}
|
||||
|
||||
ScopeMappingRepresentation currentClientScope = null;
|
||||
|
@ -125,8 +125,8 @@ public class ExportUtils {
|
|||
}
|
||||
}
|
||||
|
||||
if (appScopeReps.size() > 0) {
|
||||
rep.setApplicationScopeMappings(appScopeReps);
|
||||
if (clientScopeReps.size() > 0) {
|
||||
rep.setClientScopeMappings(clientScopeReps);
|
||||
}
|
||||
|
||||
// Finally users if needed
|
||||
|
@ -186,27 +186,27 @@ public class ExportUtils {
|
|||
Set<RoleModel> composites = role.getComposites();
|
||||
if (composites != null && composites.size() > 0) {
|
||||
Set<String> compositeRealmRoles = null;
|
||||
Map<String, List<String>> compositeAppRoles = null;
|
||||
Map<String, List<String>> compositeClientRoles = null;
|
||||
|
||||
for (RoleModel composite : composites) {
|
||||
RoleContainerModel crContainer = composite.getContainer();
|
||||
if (crContainer instanceof RealmModel) {
|
||||
|
||||
if (compositeRealmRoles == null) {
|
||||
compositeRealmRoles = new HashSet<String>();
|
||||
compositeRealmRoles = new HashSet<>();
|
||||
}
|
||||
compositeRealmRoles.add(composite.getName());
|
||||
} else {
|
||||
if (compositeAppRoles == null) {
|
||||
compositeAppRoles = new HashMap<String, List<String>>();
|
||||
if (compositeClientRoles == null) {
|
||||
compositeClientRoles = new HashMap<>();
|
||||
}
|
||||
|
||||
ClientModel app = (ClientModel)crContainer;
|
||||
String appName = app.getClientId();
|
||||
List<String> currentAppComposites = compositeAppRoles.get(appName);
|
||||
List<String> currentAppComposites = compositeClientRoles.get(appName);
|
||||
if (currentAppComposites == null) {
|
||||
currentAppComposites = new ArrayList<String>();
|
||||
compositeAppRoles.put(appName, currentAppComposites);
|
||||
currentAppComposites = new ArrayList<>();
|
||||
compositeClientRoles.put(appName, currentAppComposites);
|
||||
}
|
||||
currentAppComposites.add(composite.getName());
|
||||
}
|
||||
|
@ -216,8 +216,8 @@ public class ExportUtils {
|
|||
if (compositeRealmRoles != null) {
|
||||
compRep.setRealm(compositeRealmRoles);
|
||||
}
|
||||
if (compositeAppRoles != null) {
|
||||
compRep.setApplication(compositeAppRoles);
|
||||
if (compositeClientRoles != null) {
|
||||
compRep.setClient(compositeClientRoles);
|
||||
}
|
||||
|
||||
roleRep.setComposites(compRep);
|
||||
|
@ -248,29 +248,29 @@ public class ExportUtils {
|
|||
|
||||
// Role mappings
|
||||
Set<RoleModel> roles = user.getRoleMappings();
|
||||
List<String> realmRoleNames = new ArrayList<String>();
|
||||
Map<String, List<String>> appRoleNames = new HashMap<String, List<String>>();
|
||||
List<String> realmRoleNames = new ArrayList<>();
|
||||
Map<String, List<String>> clientRoleNames = new HashMap<>();
|
||||
for (RoleModel role : roles) {
|
||||
if (role.getContainer() instanceof RealmModel) {
|
||||
realmRoleNames.add(role.getName());
|
||||
} else {
|
||||
ClientModel app = (ClientModel)role.getContainer();
|
||||
String appName = app.getClientId();
|
||||
List<String> currentAppRoles = appRoleNames.get(appName);
|
||||
if (currentAppRoles == null) {
|
||||
currentAppRoles = new ArrayList<String>();
|
||||
appRoleNames.put(appName, currentAppRoles);
|
||||
ClientModel client = (ClientModel)role.getContainer();
|
||||
String clientId = client.getClientId();
|
||||
List<String> currentClientRoles = clientRoleNames.get(clientId);
|
||||
if (currentClientRoles == null) {
|
||||
currentClientRoles = new ArrayList<>();
|
||||
clientRoleNames.put(clientId, currentClientRoles);
|
||||
}
|
||||
|
||||
currentAppRoles.add(role.getName());
|
||||
currentClientRoles.add(role.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (realmRoleNames.size() > 0) {
|
||||
userRep.setRealmRoles(realmRoleNames);
|
||||
}
|
||||
if (appRoleNames.size() > 0) {
|
||||
userRep.setApplicationRoles(appRoleNames);
|
||||
if (clientRoleNames.size() > 0) {
|
||||
userRep.setClientRoles(clientRoleNames);
|
||||
}
|
||||
|
||||
// Credentials
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.keycloak.representations.idm.RoleRepresentation;
|
|||
import org.keycloak.representations.idm.UserFederationProviderRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.representations.idm.UserSessionRepresentation;
|
||||
import org.keycloak.util.Time;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -207,13 +208,13 @@ public class ModelToRepresentation {
|
|||
public static UserSessionRepresentation toRepresentation(UserSessionModel session) {
|
||||
UserSessionRepresentation rep = new UserSessionRepresentation();
|
||||
rep.setId(session.getId());
|
||||
rep.setStart(((long)session.getStarted()) * 1000L);
|
||||
rep.setLastAccess(((long)session.getLastSessionRefresh())* 1000L);
|
||||
rep.setStart(Time.toMillis(session.getStarted()));
|
||||
rep.setLastAccess(Time.toMillis(session.getLastSessionRefresh()));
|
||||
rep.setUser(session.getUser().getUsername());
|
||||
rep.setIpAddress(session.getIpAddress());
|
||||
for (ClientSessionModel clientSession : session.getClientSessions()) {
|
||||
ClientModel client = clientSession.getClient();
|
||||
rep.getApplications().put(client.getId(), client.getClientId());
|
||||
rep.getClients().put(client.getId(), client.getClientId());
|
||||
}
|
||||
return rep;
|
||||
}
|
||||
|
|
|
@ -139,15 +139,15 @@ public class RepresentationToModel {
|
|||
createRole(newRealm, roleRep);
|
||||
}
|
||||
}
|
||||
if (rep.getRoles().getApplication() != null) {
|
||||
for (Map.Entry<String, List<RoleRepresentation>> entry : rep.getRoles().getApplication().entrySet()) {
|
||||
ClientModel app = newRealm.getClientByClientId(entry.getKey());
|
||||
if (app == null) {
|
||||
if (rep.getRoles().getClient() != null) {
|
||||
for (Map.Entry<String, List<RoleRepresentation>> entry : rep.getRoles().getClient().entrySet()) {
|
||||
ClientModel client = newRealm.getClientByClientId(entry.getKey());
|
||||
if (client == null) {
|
||||
throw new RuntimeException("App doesn't exist in role definitions: " + entry.getKey());
|
||||
}
|
||||
for (RoleRepresentation roleRep : entry.getValue()) {
|
||||
// Application role may already exists (for example if it is defaultRole)
|
||||
RoleModel role = roleRep.getId()!=null ? app.addRole(roleRep.getId(), roleRep.getName()) : app.addRole(roleRep.getName());
|
||||
RoleModel role = roleRep.getId()!=null ? client.addRole(roleRep.getId(), roleRep.getName()) : client.addRole(roleRep.getName());
|
||||
role.setDescription(roleRep.getDescription());
|
||||
}
|
||||
}
|
||||
|
@ -159,14 +159,14 @@ public class RepresentationToModel {
|
|||
addComposites(role, roleRep, newRealm);
|
||||
}
|
||||
}
|
||||
if (rep.getRoles().getApplication() != null) {
|
||||
for (Map.Entry<String, List<RoleRepresentation>> entry : rep.getRoles().getApplication().entrySet()) {
|
||||
ClientModel app = newRealm.getClientByClientId(entry.getKey());
|
||||
if (app == null) {
|
||||
if (rep.getRoles().getClient() != null) {
|
||||
for (Map.Entry<String, List<RoleRepresentation>> entry : rep.getRoles().getClient().entrySet()) {
|
||||
ClientModel client = newRealm.getClientByClientId(entry.getKey());
|
||||
if (client == null) {
|
||||
throw new RuntimeException("App doesn't exist in role definitions: " + entry.getKey());
|
||||
}
|
||||
for (RoleRepresentation roleRep : entry.getValue()) {
|
||||
RoleModel role = app.getRole(roleRep.getName());
|
||||
RoleModel role = client.getRole(roleRep.getName());
|
||||
addComposites(role, roleRep, newRealm);
|
||||
}
|
||||
}
|
||||
|
@ -193,9 +193,9 @@ public class RepresentationToModel {
|
|||
|
||||
Map<String, ClientModel> appMap = newRealm.getClientNameMap();
|
||||
|
||||
if (rep.getApplicationScopeMappings() != null) {
|
||||
if (rep.getClientScopeMappings() != null) {
|
||||
|
||||
for (Map.Entry<String, List<ScopeMappingRepresentation>> entry : rep.getApplicationScopeMappings().entrySet()) {
|
||||
for (Map.Entry<String, List<ScopeMappingRepresentation>> entry : rep.getClientScopeMappings().entrySet()) {
|
||||
ClientModel app = appMap.get(entry.getKey());
|
||||
if (app == null) {
|
||||
throw new RuntimeException("Unable to find client role mappings for client: " + entry.getKey());
|
||||
|
@ -285,10 +285,6 @@ public class RepresentationToModel {
|
|||
rep.setIdentityProviders(identityProviders);
|
||||
}
|
||||
}
|
||||
|
||||
rep.setSocial(null);
|
||||
rep.setSocialProviders(null);
|
||||
rep.setUpdateProfileOnInitialSocialLogin(false);
|
||||
}
|
||||
|
||||
private static void convertDeprecatedSocialProviders(UserRepresentation user) {
|
||||
|
@ -341,8 +337,40 @@ public class RepresentationToModel {
|
|||
|
||||
realm.getClients().add(app);
|
||||
}
|
||||
}
|
||||
|
||||
realm.setApplications(null);
|
||||
if (realm.getApplicationScopeMappings() != null && realm.getClientScopeMappings() == null) {
|
||||
realm.setClientScopeMappings(realm.getApplicationScopeMappings());
|
||||
}
|
||||
|
||||
if (realm.getRoles() != null && realm.getRoles().getApplication() != null && realm.getRoles().getClient() == null) {
|
||||
realm.getRoles().setClient(realm.getRoles().getApplication());
|
||||
}
|
||||
|
||||
if (realm.getUsers() != null) {
|
||||
for (UserRepresentation user : realm.getUsers()) {
|
||||
if (user.getApplicationRoles() != null && user.getClientRoles() == null) {
|
||||
user.setClientRoles(user.getApplicationRoles());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (realm.getRoles() != null && realm.getRoles().getRealm() != null) {
|
||||
for (RoleRepresentation role : realm.getRoles().getRealm()) {
|
||||
if (role.getComposites() != null && role.getComposites().getApplication() != null && role.getComposites().getClient() == null) {
|
||||
role.getComposites().setClient(role.getComposites().getApplication());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (realm.getRoles() != null && realm.getRoles().getClient() != null) {
|
||||
for (Map.Entry<String, List<RoleRepresentation>> clientRoles : realm.getRoles().getClient().entrySet()) {
|
||||
for (RoleRepresentation role : clientRoles.getValue()) {
|
||||
if (role.getComposites() != null && role.getComposites().getApplication() != null && role.getComposites().getClient() == null) {
|
||||
role.getComposites().setClient(role.getComposites().getApplication());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -453,25 +481,24 @@ public class RepresentationToModel {
|
|||
role.addCompositeRole(realmRole);
|
||||
}
|
||||
}
|
||||
if (roleRep.getComposites().getApplication() != null) {
|
||||
for (Map.Entry<String, List<String>> entry : roleRep.getComposites().getApplication().entrySet()) {
|
||||
ClientModel app = realm.getClientByClientId(entry.getKey());
|
||||
if (app == null) {
|
||||
if (roleRep.getComposites().getClient() != null) {
|
||||
for (Map.Entry<String, List<String>> entry : roleRep.getComposites().getClient().entrySet()) {
|
||||
ClientModel client = realm.getClientByClientId(entry.getKey());
|
||||
if (client == null) {
|
||||
throw new RuntimeException("App doesn't exist in role definitions: " + roleRep.getName());
|
||||
}
|
||||
for (String roleStr : entry.getValue()) {
|
||||
RoleModel appRole = app.getRole(roleStr);
|
||||
if (appRole == null) throw new RuntimeException("Unable to find composite app role: " + roleStr);
|
||||
role.addCompositeRole(appRole);
|
||||
RoleModel clientRole = client.getRole(roleStr);
|
||||
if (clientRole == null) throw new RuntimeException("Unable to find composite client role: " + roleStr);
|
||||
role.addCompositeRole(clientRole);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// APPLICATIONS
|
||||
// CLIENTS
|
||||
|
||||
private static Map<String, ClientModel> createClients(KeycloakSession session, RealmRepresentation rep, RealmModel realm) {
|
||||
Map<String, ClientModel> appMap = new HashMap<String, ClientModel>();
|
||||
|
@ -753,8 +780,8 @@ public class RepresentationToModel {
|
|||
user.grantRole(role);
|
||||
}
|
||||
}
|
||||
if (userRep.getApplicationRoles() != null) {
|
||||
for (Map.Entry<String, List<String>> entry : userRep.getApplicationRoles().entrySet()) {
|
||||
if (userRep.getClientRoles() != null) {
|
||||
for (Map.Entry<String, List<String>> entry : userRep.getClientRoles().entrySet()) {
|
||||
ClientModel client = clientMap.get(entry.getKey());
|
||||
if (client == null) {
|
||||
throw new RuntimeException("Unable to find client role mappings for client: " + entry.getKey());
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.keycloak.models.KeycloakSession;
|
|||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.utils.ModelToRepresentation;
|
||||
import org.keycloak.representations.idm.ApplicationMappingsRepresentation;
|
||||
import org.keycloak.representations.idm.ClientMappingsRepresentation;
|
||||
import org.keycloak.representations.idm.MappingsRepresentation;
|
||||
import org.keycloak.representations.idm.RoleRepresentation;
|
||||
|
||||
|
@ -64,22 +64,22 @@ public class ScopeMappedResource {
|
|||
all.setRealmMappings(realmRep);
|
||||
}
|
||||
|
||||
List<ClientModel> applications = realm.getClients();
|
||||
if (applications.size() > 0) {
|
||||
Map<String, ApplicationMappingsRepresentation> appMappings = new HashMap<String, ApplicationMappingsRepresentation>();
|
||||
for (ClientModel app : applications) {
|
||||
Set<RoleModel> roleMappings = app.getApplicationScopeMappings(client);
|
||||
List<ClientModel> clients = realm.getClients();
|
||||
if (clients.size() > 0) {
|
||||
Map<String, ClientMappingsRepresentation> clientMappings = new HashMap<String, ClientMappingsRepresentation>();
|
||||
for (ClientModel client : clients) {
|
||||
Set<RoleModel> roleMappings = client.getApplicationScopeMappings(this.client);
|
||||
if (roleMappings.size() > 0) {
|
||||
ApplicationMappingsRepresentation mappings = new ApplicationMappingsRepresentation();
|
||||
mappings.setApplicationId(app.getId());
|
||||
mappings.setApplication(app.getClientId());
|
||||
ClientMappingsRepresentation mappings = new ClientMappingsRepresentation();
|
||||
mappings.setId(client.getId());
|
||||
mappings.setClient(client.getClientId());
|
||||
List<RoleRepresentation> roles = new ArrayList<RoleRepresentation>();
|
||||
mappings.setMappings(roles);
|
||||
for (RoleModel role : roleMappings) {
|
||||
roles.add(ModelToRepresentation.toRepresentation(role));
|
||||
}
|
||||
appMappings.put(app.getClientId(), mappings);
|
||||
all.setApplicationMappings(appMappings);
|
||||
clientMappings.put(client.getClientId(), mappings);
|
||||
all.setClientMappings(clientMappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.keycloak.models.utils.RepresentationToModel;
|
|||
import org.keycloak.protocol.oidc.OIDCLoginProtocol;
|
||||
import org.keycloak.protocol.oidc.TokenManager;
|
||||
import org.keycloak.protocol.oidc.utils.RedirectUtils;
|
||||
import org.keycloak.representations.idm.ApplicationMappingsRepresentation;
|
||||
import org.keycloak.representations.idm.ClientMappingsRepresentation;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.FederatedIdentityRepresentation;
|
||||
import org.keycloak.representations.idm.MappingsRepresentation;
|
||||
|
@ -441,20 +441,20 @@ public class UsersResource {
|
|||
|
||||
List<ClientModel> applications = realm.getClients();
|
||||
if (applications.size() > 0) {
|
||||
Map<String, ApplicationMappingsRepresentation> appMappings = new HashMap<String, ApplicationMappingsRepresentation>();
|
||||
Map<String, ClientMappingsRepresentation> appMappings = new HashMap<String, ClientMappingsRepresentation>();
|
||||
for (ClientModel application : applications) {
|
||||
Set<RoleModel> roleMappings = user.getApplicationRoleMappings(application);
|
||||
if (roleMappings.size() > 0) {
|
||||
ApplicationMappingsRepresentation mappings = new ApplicationMappingsRepresentation();
|
||||
mappings.setApplicationId(application.getId());
|
||||
mappings.setApplication(application.getClientId());
|
||||
ClientMappingsRepresentation mappings = new ClientMappingsRepresentation();
|
||||
mappings.setId(application.getId());
|
||||
mappings.setClient(application.getClientId());
|
||||
List<RoleRepresentation> roles = new ArrayList<RoleRepresentation>();
|
||||
mappings.setMappings(roles);
|
||||
for (RoleModel role : roleMappings) {
|
||||
roles.add(ModelToRepresentation.toRepresentation(role));
|
||||
}
|
||||
appMappings.put(application.getClientId(), mappings);
|
||||
all.setApplicationMappings(appMappings);
|
||||
all.setClientMappings(appMappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public class ClientTest extends AbstractClientTest {
|
|||
|
||||
List<UserSessionRepresentation> userSessions = app.getUserSessions(0, 100);
|
||||
assertEquals(2, userSessions.size());
|
||||
assertEquals(1, userSessions.get(0).getApplications().size());
|
||||
assertEquals(1, userSessions.get(0).getClients().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
"value" : "password" }
|
||||
],
|
||||
"realmRoles": ["user"],
|
||||
"applicationRoles": {
|
||||
"clientRoles": {
|
||||
"test-app": [ "customer-user" ],
|
||||
"account": [ "view-profile", "manage-account" ]
|
||||
}
|
||||
|
@ -41,7 +41,7 @@
|
|||
"value" : "password" }
|
||||
],
|
||||
"realmRoles": ["user"],
|
||||
"applicationRoles": {
|
||||
"clientRoles": {
|
||||
"test-app": [ "customer-user" ],
|
||||
"account": [ "view-profile", "manage-account" ]
|
||||
}
|
||||
|
@ -67,7 +67,7 @@
|
|||
"roles": ["user"]
|
||||
}
|
||||
],
|
||||
"applications": [
|
||||
"clients": [
|
||||
{
|
||||
"name": "test-app",
|
||||
"enabled": true,
|
||||
|
@ -90,7 +90,7 @@
|
|||
"description": "Have Administrator privileges"
|
||||
}
|
||||
],
|
||||
"application" : {
|
||||
"client" : {
|
||||
"test-app" : [
|
||||
{
|
||||
"name": "customer-user",
|
||||
|
@ -105,7 +105,7 @@
|
|||
|
||||
},
|
||||
|
||||
"applicationScopeMappings": {
|
||||
"clientScopeMappings": {
|
||||
"test-app": [
|
||||
{
|
||||
"client": "third-party",
|
||||
|
|
Loading…
Reference in a new issue