fix conflicts
This commit is contained in:
commit
f61fb4ba18
372 files changed
+12857
-13271
No files matched your search
@@ -9,25 +9,23 @@ public class AdminRoles {
|
||||
|
||||
public static String ADMIN = "admin";
|
||||
|
||||
// for admin application local to each realm
|
||||
// for admin client local to each realm
|
||||
public static String REALM_ADMIN = "realm-admin";
|
||||
|
||||
public static String CREATE_REALM = "create-realm";
|
||||
|
||||
public static String VIEW_REALM = "view-realm";
|
||||
public static String VIEW_USERS = "view-users";
|
||||
public static String VIEW_APPLICATIONS = "view-applications";
|
||||
public static String VIEW_CLIENTS = "view-clients";
|
||||
public static String VIEW_EVENTS = "view-events";
|
||||
public static String VIEW_IDENTITY_PROVIDERS = "view-identity-providers";
|
||||
|
||||
public static String MANAGE_REALM = "manage-realm";
|
||||
public static String MANAGE_USERS = "manage-users";
|
||||
public static String MANAGE_APPLICATIONS = "manage-applications";
|
||||
public static String MANAGE_IDENTITY_PROVIDERS = "manage-identity-providers";
|
||||
public static String MANAGE_CLIENTS = "manage-clients";
|
||||
public static String MANAGE_EVENTS = "manage-events";
|
||||
|
||||
public static String[] ALL_REALM_ROLES = {VIEW_REALM, VIEW_USERS, VIEW_APPLICATIONS, VIEW_CLIENTS, VIEW_EVENTS, VIEW_IDENTITY_PROVIDERS, MANAGE_REALM, MANAGE_USERS, MANAGE_APPLICATIONS, MANAGE_CLIENTS, MANAGE_EVENTS, MANAGE_IDENTITY_PROVIDERS};
|
||||
public static String[] ALL_REALM_ROLES = {VIEW_REALM, VIEW_USERS, VIEW_CLIENTS, VIEW_EVENTS, VIEW_IDENTITY_PROVIDERS, MANAGE_REALM, MANAGE_USERS, MANAGE_CLIENTS, MANAGE_EVENTS, MANAGE_IDENTITY_PROVIDERS};
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package org.keycloak.models;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public interface ApplicationModel extends RoleContainerModel, ClientModel {
|
||||
void updateApplication();
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
boolean isSurrogateAuthRequired();
|
||||
|
||||
void setSurrogateAuthRequired(boolean surrogateAuthRequired);
|
||||
|
||||
String getManagementUrl();
|
||||
|
||||
void setManagementUrl(String url);
|
||||
|
||||
String getBaseUrl();
|
||||
|
||||
void setBaseUrl(String url);
|
||||
|
||||
List<String> getDefaultRoles();
|
||||
|
||||
void addDefaultRole(String name);
|
||||
|
||||
void updateDefaultRoles(String[] defaultRoles);
|
||||
|
||||
Set<RoleModel> getApplicationScopeMappings(ClientModel client);
|
||||
|
||||
boolean isBearerOnly();
|
||||
void setBearerOnly(boolean only);
|
||||
|
||||
int getNodeReRegistrationTimeout();
|
||||
|
||||
void setNodeReRegistrationTimeout(int timeout);
|
||||
|
||||
Map<String, Integer> getRegisteredNodes();
|
||||
|
||||
/**
|
||||
* Register node or just update the 'lastReRegistration' time if this node is already registered
|
||||
*
|
||||
* @param nodeHost
|
||||
* @param registrationTime
|
||||
*/
|
||||
void registerNode(String nodeHost, int registrationTime);
|
||||
|
||||
void unregisterNode(String nodeHost);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.util.Set;
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public interface ClientModel {
|
||||
public interface ClientModel extends RoleContainerModel {
|
||||
|
||||
// COMMON ATTRIBUTES
|
||||
|
||||
@@ -16,20 +16,22 @@ public interface ClientModel {
|
||||
String PUBLIC_KEY = "publicKey";
|
||||
String X509CERTIFICATE = "X509Certificate";
|
||||
|
||||
/**
|
||||
* Internal database key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void updateClient();
|
||||
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* String exposed to outside world
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getClientId();
|
||||
|
||||
void setClientId(String clientId);
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
void setEnabled(boolean enabled);
|
||||
|
||||
boolean isSurrogateAuthRequired();
|
||||
|
||||
void setSurrogateAuthRequired(boolean surrogateAuthRequired);
|
||||
|
||||
Set<String> getWebOrigins();
|
||||
|
||||
void setWebOrigins(Set<String> webOrigins);
|
||||
@@ -46,10 +48,28 @@ public interface ClientModel {
|
||||
|
||||
void removeRedirectUri(String redirectUri);
|
||||
|
||||
String getManagementUrl();
|
||||
|
||||
boolean isEnabled();
|
||||
void setManagementUrl(String url);
|
||||
|
||||
void setEnabled(boolean enabled);
|
||||
String getBaseUrl();
|
||||
|
||||
void setBaseUrl(String url);
|
||||
|
||||
List<String> getDefaultRoles();
|
||||
|
||||
void addDefaultRole(String name);
|
||||
|
||||
void updateDefaultRoles(String[] defaultRoles);
|
||||
|
||||
Set<RoleModel> getClientScopeMappings(ClientModel client);
|
||||
|
||||
boolean isBearerOnly();
|
||||
void setBearerOnly(boolean only);
|
||||
|
||||
int getNodeReRegistrationTimeout();
|
||||
|
||||
void setNodeReRegistrationTimeout(int timeout);
|
||||
|
||||
boolean validateSecret(String secret);
|
||||
String getSecret();
|
||||
@@ -76,13 +96,15 @@ public interface ClientModel {
|
||||
boolean isDirectGrantsOnly();
|
||||
void setDirectGrantsOnly(boolean flag);
|
||||
|
||||
boolean isConsentRequired();
|
||||
void setConsentRequired(boolean consentRequired);
|
||||
|
||||
Set<RoleModel> getScopeMappings();
|
||||
void addScopeMapping(RoleModel role);
|
||||
void deleteScopeMapping(RoleModel role);
|
||||
Set<RoleModel> getRealmScopeMappings();
|
||||
boolean hasScope(RoleModel role);
|
||||
|
||||
|
||||
RealmModel getRealm();
|
||||
|
||||
/**
|
||||
@@ -104,4 +126,16 @@ public interface ClientModel {
|
||||
void updateProtocolMapper(ProtocolMapperModel mapping);
|
||||
public ProtocolMapperModel getProtocolMapperById(String id);
|
||||
public ProtocolMapperModel getProtocolMapperByName(String protocol, String name);
|
||||
|
||||
Map<String, Integer> getRegisteredNodes();
|
||||
|
||||
/**
|
||||
* Register node or just update the 'lastReRegistration' time if this node is already registered
|
||||
*
|
||||
* @param nodeHost
|
||||
* @param registrationTime
|
||||
*/
|
||||
void registerNode(String nodeHost, int registrationTime);
|
||||
|
||||
void unregisterNode(String nodeHost);
|
||||
}
|
||||
@@ -5,9 +5,9 @@ package org.keycloak.models;
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public interface Constants {
|
||||
String ADMIN_CONSOLE_APPLICATION = "security-admin-console";
|
||||
String ADMIN_CONSOLE_CLIENT_ID = "security-admin-console";
|
||||
|
||||
String ACCOUNT_MANAGEMENT_APP = "account";
|
||||
String ACCOUNT_MANAGEMENT_CLIENT_ID = "account";
|
||||
|
||||
String INSTALLED_APP_URN = "urn:ietf:wg:oauth:2.0:oob";
|
||||
String INSTALLED_APP_URL = "http://localhost";
|
||||
|
||||
@@ -29,5 +29,40 @@ public class LDAPConstants {
|
||||
public static final String BATCH_SIZE_FOR_SYNC = "batchSizeForSync";
|
||||
public static final int DEFAULT_BATCH_SIZE_FOR_SYNC = 1000;
|
||||
|
||||
// Config option to specify if registrations will be synced or not
|
||||
public static final String SYNC_REGISTRATIONS = "syncRegistrations";
|
||||
|
||||
// Applicable just for active directory
|
||||
public static final String USER_ACCOUNT_CONTROLS_AFTER_PASSWORD_UPDATE = "userAccountControlsAfterPasswordUpdate";
|
||||
|
||||
// Custom attributes on UserModel, which is mapped to LDAP
|
||||
public static final String LDAP_ID = "LDAP_ID";
|
||||
public static final String LDAP_ENTRY_DN = "LDAP_ENTRY_DN";
|
||||
|
||||
|
||||
// Those are forked from Picketlink
|
||||
public static final String GIVENNAME = "givenname";
|
||||
public static final String CN = "cn";
|
||||
public static final String SN = "sn";
|
||||
public static final String EMAIL = "mail";
|
||||
public static final String MEMBER = "member";
|
||||
public static final String MEMBER_OF = "memberOf";
|
||||
public static final String OBJECT_CLASS = "objectclass";
|
||||
public static final String UID = "uid";
|
||||
public static final String USER_PASSWORD_ATTRIBUTE = "userpassword";
|
||||
public static final String GROUP_OF_NAMES = "groupOfNames";
|
||||
public static final String GROUP_OF_ENTRIES = "groupOfEntries";
|
||||
public static final String GROUP_OF_UNIQUE_NAMES = "groupOfUniqueNames";
|
||||
|
||||
public static final String COMMA = ",";
|
||||
public static final String EQUAL = "=";
|
||||
public static final String SPACE_STRING = " ";
|
||||
|
||||
public static final String CUSTOM_ATTRIBUTE_ENABLED = "enabled";
|
||||
public static final String CUSTOM_ATTRIBUTE_CREATE_DATE = "createDate";
|
||||
public static final String CUSTOM_ATTRIBUTE_EXPIRY_DATE = "expiryDate";
|
||||
public static final String ENTRY_UUID = "entryUUID";
|
||||
public static final String OBJECT_GUID = "objectGUID";
|
||||
public static final String CREATE_TIMESTAMP = "createTimeStamp";
|
||||
public static final String MODIFY_TIMESTAMP = "modifyTimeStamp";
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package org.keycloak.models;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public interface OAuthClientModel extends ClientModel {
|
||||
void setClientId(String id);
|
||||
|
||||
}
|
||||
@@ -19,15 +19,10 @@ public interface RealmModel extends RoleContainerModel {
|
||||
interface RealmCreationEvent extends ProviderEvent {
|
||||
RealmModel getCreatedRealm();
|
||||
}
|
||||
|
||||
interface ClientCreationEvent extends ProviderEvent {
|
||||
ClientModel getCreatedClient();
|
||||
}
|
||||
interface ApplicationCreationEvent extends ClientCreationEvent {
|
||||
ApplicationModel getCreatedApplication();
|
||||
}
|
||||
interface OAuthClientCreationEvent extends ClientCreationEvent {
|
||||
OAuthClientModel getCreatedOAuthClient();
|
||||
}
|
||||
|
||||
String getId();
|
||||
|
||||
@@ -150,33 +145,21 @@ public interface RealmModel extends RoleContainerModel {
|
||||
|
||||
void updateDefaultRoles(String[] defaultRoles);
|
||||
|
||||
ClientModel findClient(String clientId);
|
||||
Map<String, ClientModel> getClientNameMap();
|
||||
|
||||
Map<String, ApplicationModel> getApplicationNameMap();
|
||||
List<ClientModel> getClients();
|
||||
|
||||
List<ApplicationModel> getApplications();
|
||||
ClientModel addClient(String name);
|
||||
|
||||
ApplicationModel addApplication(String name);
|
||||
ClientModel addClient(String id, String clientId);
|
||||
|
||||
ApplicationModel addApplication(String id, String name);
|
||||
boolean removeClient(String id);
|
||||
|
||||
boolean removeApplication(String id);
|
||||
|
||||
ApplicationModel getApplicationById(String id);
|
||||
ApplicationModel getApplicationByName(String name);
|
||||
ClientModel getClientById(String id);
|
||||
ClientModel getClientByClientId(String clientId);
|
||||
|
||||
void updateRequiredCredentials(Set<String> creds);
|
||||
|
||||
OAuthClientModel addOAuthClient(String name);
|
||||
|
||||
OAuthClientModel addOAuthClient(String id, String name);
|
||||
|
||||
OAuthClientModel getOAuthClient(String name);
|
||||
OAuthClientModel getOAuthClientById(String id);
|
||||
boolean removeOAuthClient(String id);
|
||||
|
||||
List<OAuthClientModel> getOAuthClients();
|
||||
|
||||
Map<String, String> getBrowserSecurityHeaders();
|
||||
void setBrowserSecurityHeaders(Map<String, String> headers);
|
||||
|
||||
@@ -249,11 +232,9 @@ public interface RealmModel extends RoleContainerModel {
|
||||
|
||||
void setEnabledEventTypes(Set<String> enabledEventTypes);
|
||||
|
||||
ApplicationModel getMasterAdminApp();
|
||||
ClientModel getMasterAdminClient();
|
||||
|
||||
void setMasterAdminApp(ApplicationModel app);
|
||||
|
||||
ClientModel findClientById(String id);
|
||||
void setMasterAdminClient(ClientModel client);
|
||||
|
||||
boolean isIdentityFederationEnabled();
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.keycloak.models;
|
||||
|
||||
import org.keycloak.provider.Provider;
|
||||
import org.keycloak.provider.ProviderEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,8 +18,7 @@ public interface RealmProvider extends Provider {
|
||||
RealmModel getRealmByName(String name);
|
||||
|
||||
RoleModel getRoleById(String id, RealmModel realm);
|
||||
ApplicationModel getApplicationById(String id, RealmModel realm);
|
||||
OAuthClientModel getOAuthClientById(String id, RealmModel realm);
|
||||
ClientModel getClientById(String id, RealmModel realm);
|
||||
List<RealmModel> getRealms();
|
||||
boolean removeRealm(String id);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public interface UserModel {
|
||||
void updateCredentialDirectly(UserCredentialValueModel cred);
|
||||
|
||||
Set<RoleModel> getRealmRoleMappings();
|
||||
Set<RoleModel> getApplicationRoleMappings(ApplicationModel app);
|
||||
Set<RoleModel> getClientRoleMappings(ClientModel app);
|
||||
boolean hasRole(RoleModel role);
|
||||
void grantRole(RoleModel role);
|
||||
Set<RoleModel> getRoleMappings();
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.keycloak.models;
|
||||
import org.keycloak.provider.Provider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package org.keycloak.models.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class ApplicationEntity extends ClientEntity {
|
||||
|
||||
private boolean surrogateAuthRequired;
|
||||
private String managementUrl;
|
||||
private String baseUrl;
|
||||
private boolean bearerOnly;
|
||||
private int nodeReRegistrationTimeout;
|
||||
|
||||
// We are using names of defaultRoles (not ids)
|
||||
private List<String> defaultRoles = new ArrayList<String>();
|
||||
|
||||
private Map<String, Integer> registeredNodes;
|
||||
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return surrogateAuthRequired;
|
||||
}
|
||||
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
this.surrogateAuthRequired = surrogateAuthRequired;
|
||||
}
|
||||
|
||||
public String getManagementUrl() {
|
||||
return managementUrl;
|
||||
}
|
||||
|
||||
public void setManagementUrl(String managementUrl) {
|
||||
this.managementUrl = managementUrl;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public void setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public boolean isBearerOnly() {
|
||||
return bearerOnly;
|
||||
}
|
||||
|
||||
public void setBearerOnly(boolean bearerOnly) {
|
||||
this.bearerOnly = bearerOnly;
|
||||
}
|
||||
|
||||
public List<String> getDefaultRoles() {
|
||||
return defaultRoles;
|
||||
}
|
||||
|
||||
public void setDefaultRoles(List<String> defaultRoles) {
|
||||
this.defaultRoles = defaultRoles;
|
||||
}
|
||||
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
return nodeReRegistrationTimeout;
|
||||
}
|
||||
|
||||
public void setNodeReRegistrationTimeout(int nodeReRegistrationTimeout) {
|
||||
this.nodeReRegistrationTimeout = nodeReRegistrationTimeout;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
return registeredNodes;
|
||||
}
|
||||
|
||||
public void setRegisteredNodes(Map<String, Integer> registeredNodes) {
|
||||
this.registeredNodes = registeredNodes;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+236
-154
@@ -1,154 +1,236 @@
|
||||
package org.keycloak.models.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class ClientEntity extends AbstractIdentifiableEntity {
|
||||
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
private String secret;
|
||||
private String protocol;
|
||||
private long allowedClaimsMask;
|
||||
private int notBefore;
|
||||
private boolean publicClient;
|
||||
private boolean fullScopeAllowed;
|
||||
private boolean frontchannelLogout;
|
||||
|
||||
private String realmId;
|
||||
private Map<String, String> attributes = new HashMap<String, String>();
|
||||
|
||||
|
||||
private List<String> webOrigins = new ArrayList<String>();
|
||||
private List<String> redirectUris = new ArrayList<String>();
|
||||
private List<String> scopeIds = new ArrayList<String>();
|
||||
private List<ClientIdentityProviderMappingEntity> identityProviders = new ArrayList<ClientIdentityProviderMappingEntity>();
|
||||
private List<ProtocolMapperEntity> protocolMappers = new ArrayList<ProtocolMapperEntity>();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public void setSecret(String secret) {
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
public int getNotBefore() {
|
||||
return notBefore;
|
||||
}
|
||||
|
||||
public void setNotBefore(int notBefore) {
|
||||
this.notBefore = notBefore;
|
||||
}
|
||||
|
||||
public boolean isPublicClient() {
|
||||
return publicClient;
|
||||
}
|
||||
|
||||
public void setPublicClient(boolean publicClient) {
|
||||
this.publicClient = publicClient;
|
||||
}
|
||||
|
||||
public String getRealmId() {
|
||||
return realmId;
|
||||
}
|
||||
|
||||
public void setRealmId(String realmId) {
|
||||
this.realmId = realmId;
|
||||
}
|
||||
|
||||
public List<String> getWebOrigins() {
|
||||
return webOrigins;
|
||||
}
|
||||
|
||||
public void setWebOrigins(List<String> webOrigins) {
|
||||
this.webOrigins = webOrigins;
|
||||
}
|
||||
|
||||
public List<String> getRedirectUris() {
|
||||
return redirectUris;
|
||||
}
|
||||
|
||||
public void setRedirectUris(List<String> redirectUris) {
|
||||
this.redirectUris = redirectUris;
|
||||
}
|
||||
|
||||
public List<String> getScopeIds() {
|
||||
return scopeIds;
|
||||
}
|
||||
|
||||
public void setScopeIds(List<String> scopeIds) {
|
||||
this.scopeIds = scopeIds;
|
||||
}
|
||||
|
||||
public boolean isFullScopeAllowed() {
|
||||
return fullScopeAllowed;
|
||||
}
|
||||
|
||||
public void setFullScopeAllowed(boolean fullScopeAllowed) {
|
||||
this.fullScopeAllowed = fullScopeAllowed;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(Map<String, String> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public boolean isFrontchannelLogout() {
|
||||
return frontchannelLogout;
|
||||
}
|
||||
|
||||
public void setFrontchannelLogout(boolean frontchannelLogout) {
|
||||
this.frontchannelLogout = frontchannelLogout;
|
||||
}
|
||||
|
||||
public List<ClientIdentityProviderMappingEntity> getIdentityProviders() {
|
||||
return this.identityProviders;
|
||||
}
|
||||
|
||||
public void setIdentityProviders(List<ClientIdentityProviderMappingEntity> identityProviders) {
|
||||
this.identityProviders = identityProviders;
|
||||
}
|
||||
|
||||
public List<ProtocolMapperEntity> getProtocolMappers() {
|
||||
return protocolMappers;
|
||||
}
|
||||
|
||||
public void setProtocolMappers(List<ProtocolMapperEntity> protocolMappers) {
|
||||
this.protocolMappers = protocolMappers;
|
||||
}
|
||||
}
|
||||
package org.keycloak.models.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class ClientEntity extends AbstractIdentifiableEntity {
|
||||
|
||||
private String clientId;
|
||||
private String realmId;
|
||||
private boolean enabled;
|
||||
private String secret;
|
||||
private String protocol;
|
||||
private int notBefore;
|
||||
private boolean publicClient;
|
||||
private boolean fullScopeAllowed;
|
||||
private boolean frontchannelLogout;
|
||||
|
||||
private boolean surrogateAuthRequired;
|
||||
private String managementUrl;
|
||||
private String baseUrl;
|
||||
private boolean bearerOnly;
|
||||
private boolean consentRequired;
|
||||
private boolean directGrantsOnly;
|
||||
private int nodeReRegistrationTimeout;
|
||||
|
||||
// We are using names of defaultRoles (not ids)
|
||||
private List<String> defaultRoles = new ArrayList<String>();
|
||||
|
||||
private Map<String, Integer> registeredNodes;
|
||||
|
||||
private Map<String, String> attributes = new HashMap<String, String>();
|
||||
|
||||
private List<String> webOrigins = new ArrayList<String>();
|
||||
private List<String> redirectUris = new ArrayList<String>();
|
||||
private List<String> scopeIds = new ArrayList<String>();
|
||||
private List<ClientIdentityProviderMappingEntity> identityProviders = new ArrayList<ClientIdentityProviderMappingEntity>();
|
||||
private List<ProtocolMapperEntity> protocolMappers = new ArrayList<ProtocolMapperEntity>();
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public void setSecret(String secret) {
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
public int getNotBefore() {
|
||||
return notBefore;
|
||||
}
|
||||
|
||||
public void setNotBefore(int notBefore) {
|
||||
this.notBefore = notBefore;
|
||||
}
|
||||
|
||||
public boolean isPublicClient() {
|
||||
return publicClient;
|
||||
}
|
||||
|
||||
public void setPublicClient(boolean publicClient) {
|
||||
this.publicClient = publicClient;
|
||||
}
|
||||
|
||||
public String getRealmId() {
|
||||
return realmId;
|
||||
}
|
||||
|
||||
public void setRealmId(String realmId) {
|
||||
this.realmId = realmId;
|
||||
}
|
||||
|
||||
public List<String> getWebOrigins() {
|
||||
return webOrigins;
|
||||
}
|
||||
|
||||
public void setWebOrigins(List<String> webOrigins) {
|
||||
this.webOrigins = webOrigins;
|
||||
}
|
||||
|
||||
public List<String> getRedirectUris() {
|
||||
return redirectUris;
|
||||
}
|
||||
|
||||
public void setRedirectUris(List<String> redirectUris) {
|
||||
this.redirectUris = redirectUris;
|
||||
}
|
||||
|
||||
public List<String> getScopeIds() {
|
||||
return scopeIds;
|
||||
}
|
||||
|
||||
public void setScopeIds(List<String> scopeIds) {
|
||||
this.scopeIds = scopeIds;
|
||||
}
|
||||
|
||||
public boolean isFullScopeAllowed() {
|
||||
return fullScopeAllowed;
|
||||
}
|
||||
|
||||
public void setFullScopeAllowed(boolean fullScopeAllowed) {
|
||||
this.fullScopeAllowed = fullScopeAllowed;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(Map<String, String> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public boolean isFrontchannelLogout() {
|
||||
return frontchannelLogout;
|
||||
}
|
||||
|
||||
public void setFrontchannelLogout(boolean frontchannelLogout) {
|
||||
this.frontchannelLogout = frontchannelLogout;
|
||||
}
|
||||
|
||||
public List<ClientIdentityProviderMappingEntity> getIdentityProviders() {
|
||||
return this.identityProviders;
|
||||
}
|
||||
|
||||
public void setIdentityProviders(List<ClientIdentityProviderMappingEntity> identityProviders) {
|
||||
this.identityProviders = identityProviders;
|
||||
}
|
||||
|
||||
public List<ProtocolMapperEntity> getProtocolMappers() {
|
||||
return protocolMappers;
|
||||
}
|
||||
|
||||
public void setProtocolMappers(List<ProtocolMapperEntity> protocolMappers) {
|
||||
this.protocolMappers = protocolMappers;
|
||||
}
|
||||
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return surrogateAuthRequired;
|
||||
}
|
||||
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
this.surrogateAuthRequired = surrogateAuthRequired;
|
||||
}
|
||||
|
||||
public String getManagementUrl() {
|
||||
return managementUrl;
|
||||
}
|
||||
|
||||
public void setManagementUrl(String managementUrl) {
|
||||
this.managementUrl = managementUrl;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public void setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public boolean isBearerOnly() {
|
||||
return bearerOnly;
|
||||
}
|
||||
|
||||
public void setBearerOnly(boolean bearerOnly) {
|
||||
this.bearerOnly = bearerOnly;
|
||||
}
|
||||
|
||||
public boolean isConsentRequired() {
|
||||
return consentRequired;
|
||||
}
|
||||
|
||||
public void setConsentRequired(boolean consentRequired) {
|
||||
this.consentRequired = consentRequired;
|
||||
}
|
||||
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return directGrantsOnly;
|
||||
}
|
||||
|
||||
public void setDirectGrantsOnly(boolean directGrantsOnly) {
|
||||
this.directGrantsOnly = directGrantsOnly;
|
||||
}
|
||||
|
||||
public List<String> getDefaultRoles() {
|
||||
return defaultRoles;
|
||||
}
|
||||
|
||||
public void setDefaultRoles(List<String> defaultRoles) {
|
||||
this.defaultRoles = defaultRoles;
|
||||
}
|
||||
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
return nodeReRegistrationTimeout;
|
||||
}
|
||||
|
||||
public void setNodeReRegistrationTimeout(int nodeReRegistrationTimeout) {
|
||||
this.nodeReRegistrationTimeout = nodeReRegistrationTimeout;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
return registeredNodes;
|
||||
}
|
||||
|
||||
public void setRegisteredNodes(Map<String, Integer> registeredNodes) {
|
||||
this.registeredNodes = registeredNodes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.keycloak.models.entities;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class OAuthClientEntity extends ClientEntity {
|
||||
protected boolean directGrantsOnly;
|
||||
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return directGrantsOnly;
|
||||
}
|
||||
|
||||
public void setDirectGrantsOnly(boolean directGrantsOnly) {
|
||||
this.directGrantsOnly = directGrantsOnly;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class RoleEntity extends AbstractIdentifiableEntity {
|
||||
private List<String> compositeRoleIds;
|
||||
|
||||
private String realmId;
|
||||
private String applicationId;
|
||||
private String clientId;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -47,11 +47,12 @@ public class RoleEntity extends AbstractIdentifiableEntity {
|
||||
this.realmId = realmId;
|
||||
}
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setApplicationId(String applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.keycloak.models.utils;
|
||||
|
||||
import org.bouncycastle.openssl.PEMWriter;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClaimMask;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
@@ -174,8 +172,8 @@ public final class KeycloakModelUtils {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public static ApplicationModel createApplication(RealmModel realm, String name) {
|
||||
ApplicationModel app = realm.addApplication(name);
|
||||
public static ClientModel createClient(RealmModel realm, String name) {
|
||||
ClientModel app = realm.addClient(name);
|
||||
generateSecret(app);
|
||||
app.setFullScopeAllowed(true);
|
||||
|
||||
@@ -247,7 +245,7 @@ public final class KeycloakModelUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMasterRealmAdminApplicationName(RealmModel realm) {
|
||||
public static String getMasterRealmAdminApplicationClientId(RealmModel realm) {
|
||||
return realm.getName() + "-realm";
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
package org.keycloak.models.utils;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClaimMask;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.FederatedIdentityModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
@@ -17,12 +14,11 @@ import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.UserSessionModel;
|
||||
import org.keycloak.representations.idm.ApplicationRepresentation;
|
||||
import org.keycloak.representations.idm.ClaimRepresentation;
|
||||
import org.keycloak.representations.idm.ClientIdentityProviderMappingRepresentation;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.FederatedIdentityRepresentation;
|
||||
import org.keycloak.representations.idm.IdentityProviderRepresentation;
|
||||
import org.keycloak.representations.idm.OAuthClientRepresentation;
|
||||
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
|
||||
import org.keycloak.representations.idm.RealmEventsConfigRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
@@ -30,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;
|
||||
@@ -211,63 +208,60 @@ 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();
|
||||
if (client instanceof ApplicationModel) {
|
||||
rep.getApplications().put(client.getId(), client.getClientId());
|
||||
} else if (client instanceof OAuthClientModel) {
|
||||
rep.getClients().put(client.getId(), client.getClientId());
|
||||
}
|
||||
rep.getClients().put(client.getId(), client.getClientId());
|
||||
}
|
||||
return rep;
|
||||
}
|
||||
|
||||
public static ApplicationRepresentation toRepresentation(ApplicationModel applicationModel) {
|
||||
ApplicationRepresentation rep = new ApplicationRepresentation();
|
||||
rep.setId(applicationModel.getId());
|
||||
rep.setName(applicationModel.getName());
|
||||
rep.setEnabled(applicationModel.isEnabled());
|
||||
rep.setAdminUrl(applicationModel.getManagementUrl());
|
||||
rep.setPublicClient(applicationModel.isPublicClient());
|
||||
rep.setFrontchannelLogout(applicationModel.isFrontchannelLogout());
|
||||
rep.setProtocol(applicationModel.getProtocol());
|
||||
rep.setAttributes(applicationModel.getAttributes());
|
||||
rep.setFullScopeAllowed(applicationModel.isFullScopeAllowed());
|
||||
rep.setBearerOnly(applicationModel.isBearerOnly());
|
||||
rep.setSurrogateAuthRequired(applicationModel.isSurrogateAuthRequired());
|
||||
rep.setBaseUrl(applicationModel.getBaseUrl());
|
||||
rep.setNotBefore(applicationModel.getNotBefore());
|
||||
rep.setNodeReRegistrationTimeout(applicationModel.getNodeReRegistrationTimeout());
|
||||
public static ClientRepresentation toRepresentation(ClientModel clientModel) {
|
||||
ClientRepresentation rep = new ClientRepresentation();
|
||||
rep.setId(clientModel.getId());
|
||||
rep.setClientId(clientModel.getClientId());
|
||||
rep.setEnabled(clientModel.isEnabled());
|
||||
rep.setAdminUrl(clientModel.getManagementUrl());
|
||||
rep.setPublicClient(clientModel.isPublicClient());
|
||||
rep.setFrontchannelLogout(clientModel.isFrontchannelLogout());
|
||||
rep.setProtocol(clientModel.getProtocol());
|
||||
rep.setAttributes(clientModel.getAttributes());
|
||||
rep.setFullScopeAllowed(clientModel.isFullScopeAllowed());
|
||||
rep.setBearerOnly(clientModel.isBearerOnly());
|
||||
rep.setConsentRequired(clientModel.isConsentRequired());
|
||||
rep.setSurrogateAuthRequired(clientModel.isSurrogateAuthRequired());
|
||||
rep.setBaseUrl(clientModel.getBaseUrl());
|
||||
rep.setNotBefore(clientModel.getNotBefore());
|
||||
rep.setNodeReRegistrationTimeout(clientModel.getNodeReRegistrationTimeout());
|
||||
|
||||
Set<String> redirectUris = applicationModel.getRedirectUris();
|
||||
Set<String> redirectUris = clientModel.getRedirectUris();
|
||||
if (redirectUris != null) {
|
||||
rep.setRedirectUris(new LinkedList<String>(redirectUris));
|
||||
rep.setRedirectUris(new LinkedList<>(redirectUris));
|
||||
}
|
||||
|
||||
Set<String> webOrigins = applicationModel.getWebOrigins();
|
||||
Set<String> webOrigins = clientModel.getWebOrigins();
|
||||
if (webOrigins != null) {
|
||||
rep.setWebOrigins(new LinkedList<String>(webOrigins));
|
||||
rep.setWebOrigins(new LinkedList<>(webOrigins));
|
||||
}
|
||||
|
||||
if (!applicationModel.getDefaultRoles().isEmpty()) {
|
||||
rep.setDefaultRoles(applicationModel.getDefaultRoles().toArray(new String[0]));
|
||||
if (!clientModel.getDefaultRoles().isEmpty()) {
|
||||
rep.setDefaultRoles(clientModel.getDefaultRoles().toArray(new String[0]));
|
||||
}
|
||||
|
||||
if (!applicationModel.getRegisteredNodes().isEmpty()) {
|
||||
rep.setRegisteredNodes(new HashMap<String, Integer>(applicationModel.getRegisteredNodes()));
|
||||
if (!clientModel.getRegisteredNodes().isEmpty()) {
|
||||
rep.setRegisteredNodes(new HashMap<>(clientModel.getRegisteredNodes()));
|
||||
}
|
||||
|
||||
if (!applicationModel.getIdentityProviders().isEmpty()) {
|
||||
rep.setIdentityProviders(toRepresentation(applicationModel.getIdentityProviders()));
|
||||
if (!clientModel.getIdentityProviders().isEmpty()) {
|
||||
rep.setIdentityProviders(toRepresentation(clientModel.getIdentityProviders()));
|
||||
}
|
||||
|
||||
if (!applicationModel.getProtocolMappers().isEmpty()) {
|
||||
List<ProtocolMapperRepresentation> mappings = new LinkedList<ProtocolMapperRepresentation>();
|
||||
for (ProtocolMapperModel model : applicationModel.getProtocolMappers()) {
|
||||
if (!clientModel.getProtocolMappers().isEmpty()) {
|
||||
List<ProtocolMapperRepresentation> mappings = new LinkedList<>();
|
||||
for (ProtocolMapperModel model : clientModel.getProtocolMappers()) {
|
||||
mappings.add(toRepresentation(model));
|
||||
}
|
||||
rep.setProtocolMappers(mappings);
|
||||
@@ -291,43 +285,6 @@ public class ModelToRepresentation {
|
||||
return representations;
|
||||
}
|
||||
|
||||
public static OAuthClientRepresentation toRepresentation(OAuthClientModel model) {
|
||||
OAuthClientRepresentation rep = new OAuthClientRepresentation();
|
||||
rep.setId(model.getId());
|
||||
rep.setName(model.getClientId());
|
||||
rep.setEnabled(model.isEnabled());
|
||||
rep.setPublicClient(model.isPublicClient());
|
||||
rep.setFrontchannelLogout(model.isFrontchannelLogout());
|
||||
rep.setProtocol(model.getProtocol());
|
||||
rep.setAttributes(model.getAttributes());
|
||||
rep.setFullScopeAllowed(model.isFullScopeAllowed());
|
||||
rep.setDirectGrantsOnly(model.isDirectGrantsOnly());
|
||||
Set<String> redirectUris = model.getRedirectUris();
|
||||
if (redirectUris != null) {
|
||||
rep.setRedirectUris(new LinkedList<String>(redirectUris));
|
||||
}
|
||||
|
||||
Set<String> webOrigins = model.getWebOrigins();
|
||||
if (webOrigins != null) {
|
||||
rep.setWebOrigins(new LinkedList<String>(webOrigins));
|
||||
}
|
||||
rep.setNotBefore(model.getNotBefore());
|
||||
|
||||
if (!model.getIdentityProviders().isEmpty()) {
|
||||
rep.setIdentityProviders(toRepresentation(model.getIdentityProviders()));
|
||||
}
|
||||
|
||||
if (!model.getProtocolMappers().isEmpty()) {
|
||||
List<ProtocolMapperRepresentation> mappings = new LinkedList<ProtocolMapperRepresentation>();
|
||||
for (ProtocolMapperModel mapper : model.getProtocolMappers()) {
|
||||
mappings.add(toRepresentation(mapper));
|
||||
}
|
||||
rep.setProtocolMappers(mappings);
|
||||
}
|
||||
|
||||
return rep;
|
||||
}
|
||||
|
||||
public static UserFederationProviderRepresentation toRepresentation(UserFederationProviderModel model) {
|
||||
UserFederationProviderRepresentation rep = new UserFederationProviderRepresentation();
|
||||
rep.setId(model.getId());
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.iharder.Base64;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.enums.SslRequired;
|
||||
import org.keycloak.migration.MigrationProvider;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.BrowserSecurityHeaders;
|
||||
import org.keycloak.models.ClaimMask;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
@@ -12,7 +11,6 @@ import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.FederatedIdentityModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -24,6 +22,7 @@ import org.keycloak.models.UserModel;
|
||||
import org.keycloak.representations.idm.ApplicationRepresentation;
|
||||
import org.keycloak.representations.idm.ClaimRepresentation;
|
||||
import org.keycloak.representations.idm.ClientIdentityProviderMappingRepresentation;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.FederatedIdentityRepresentation;
|
||||
import org.keycloak.representations.idm.IdentityProviderRepresentation;
|
||||
@@ -52,6 +51,7 @@ public class RepresentationToModel {
|
||||
|
||||
public static void importRealm(KeycloakSession session, RealmRepresentation rep, RealmModel newRealm) {
|
||||
convertDeprecatedSocialProviders(rep);
|
||||
convertDeprecatedApplications(session, rep);
|
||||
|
||||
newRealm.setName(rep.getRealm());
|
||||
if (rep.isEnabled() != null) newRealm.setEnabled(rep.isEnabled());
|
||||
@@ -129,8 +129,8 @@ public class RepresentationToModel {
|
||||
|
||||
importIdentityProviders(rep, newRealm);
|
||||
|
||||
if (rep.getApplications() != null) {
|
||||
Map<String, ApplicationModel> appMap = createApplications(session, rep, newRealm);
|
||||
if (rep.getClients() != null) {
|
||||
createClients(session, rep, newRealm);
|
||||
}
|
||||
|
||||
if (rep.getRoles() != null) {
|
||||
@@ -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()) {
|
||||
ApplicationModel app = newRealm.getApplicationByName(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()) {
|
||||
ApplicationModel app = newRealm.getApplicationByName(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);
|
||||
}
|
||||
}
|
||||
@@ -179,39 +179,34 @@ public class RepresentationToModel {
|
||||
newRealm.addDefaultRole(roleString.trim());
|
||||
}
|
||||
}
|
||||
// Setup application default roles
|
||||
if (rep.getApplications() != null) {
|
||||
for (ApplicationRepresentation resourceRep : rep.getApplications()) {
|
||||
// Setup client default roles
|
||||
if (rep.getClients() != null) {
|
||||
for (ClientRepresentation resourceRep : rep.getClients()) {
|
||||
if (resourceRep.getDefaultRoles() != null) {
|
||||
ApplicationModel appModel = newRealm.getApplicationByName(resourceRep.getName());
|
||||
appModel.updateDefaultRoles(resourceRep.getDefaultRoles());
|
||||
ClientModel clientModel = newRealm.getClientByClientId(resourceRep.getClientId());
|
||||
clientModel.updateDefaultRoles(resourceRep.getDefaultRoles());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rep.getOauthClients() != null) {
|
||||
createOAuthClients(session, rep, newRealm);
|
||||
}
|
||||
// Now that all possible roles and clients are created, create scope mappings
|
||||
|
||||
Map<String, ClientModel> appMap = newRealm.getClientNameMap();
|
||||
|
||||
// Now that all possible roles and applications are created, create scope mappings
|
||||
if (rep.getClientScopeMappings() != null) {
|
||||
|
||||
Map<String, ApplicationModel> appMap = newRealm.getApplicationNameMap();
|
||||
|
||||
if (rep.getApplicationScopeMappings() != null) {
|
||||
|
||||
for (Map.Entry<String, List<ScopeMappingRepresentation>> entry : rep.getApplicationScopeMappings().entrySet()) {
|
||||
ApplicationModel app = appMap.get(entry.getKey());
|
||||
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 application role mappings for app: " + entry.getKey());
|
||||
throw new RuntimeException("Unable to find client role mappings for client: " + entry.getKey());
|
||||
}
|
||||
createApplicationScopeMappings(newRealm, app, entry.getValue());
|
||||
createClientScopeMappings(newRealm, app, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (rep.getScopeMappings() != null) {
|
||||
for (ScopeMappingRepresentation scope : rep.getScopeMappings()) {
|
||||
ClientModel client = newRealm.findClient(scope.getClient());
|
||||
ClientModel client = newRealm.getClientByClientId(scope.getClient());
|
||||
if (client == null) {
|
||||
throw new RuntimeException("Unknown client specification in realm scope mappings");
|
||||
}
|
||||
@@ -290,10 +285,6 @@ public class RepresentationToModel {
|
||||
rep.setIdentityProviders(identityProviders);
|
||||
}
|
||||
}
|
||||
|
||||
rep.setSocial(null);
|
||||
rep.setSocialProviders(null);
|
||||
rep.setUpdateProfileOnInitialSocialLogin(false);
|
||||
}
|
||||
|
||||
private static void convertDeprecatedSocialProviders(UserRepresentation user) {
|
||||
@@ -314,15 +305,73 @@ public class RepresentationToModel {
|
||||
user.setSocialLinks(null);
|
||||
}
|
||||
|
||||
private static List<ProtocolMapperRepresentation> convertDeprecatedClaimsMask(KeycloakSession session, ClaimRepresentation claimRep) {
|
||||
if (claimRep == null) {
|
||||
return null;
|
||||
private static void convertDeprecatedApplications(KeycloakSession session, RealmRepresentation realm) {
|
||||
if (realm.getApplications() != null || realm.getOauthClients() != null) {
|
||||
if (realm.getClients() == null) {
|
||||
realm.setClients(new LinkedList<ClientRepresentation>());
|
||||
}
|
||||
|
||||
List<ApplicationRepresentation> clients = new LinkedList<>();
|
||||
if (realm.getApplications() != null) {
|
||||
clients.addAll(realm.getApplications());
|
||||
}
|
||||
if (realm.getOauthClients() != null) {
|
||||
clients.addAll(realm.getOauthClients());
|
||||
}
|
||||
|
||||
for (ApplicationRepresentation app : clients) {
|
||||
app.setClientId(app.getName());
|
||||
app.setName(null);
|
||||
|
||||
if (app instanceof OAuthClientRepresentation) {
|
||||
app.setConsentRequired(true);
|
||||
app.setFullScopeAllowed(false);
|
||||
}
|
||||
|
||||
if (app.getProtocolMappers() == null && app.getClaims() != null) {
|
||||
long mask = getClaimsMask(app.getClaims());
|
||||
List<ProtocolMapperRepresentation> convertedProtocolMappers = session.getProvider(MigrationProvider.class).getMappersForClaimMask(mask);
|
||||
app.setProtocolMappers(convertedProtocolMappers);
|
||||
app.setClaims(null);
|
||||
}
|
||||
|
||||
realm.getClients().add(app);
|
||||
}
|
||||
}
|
||||
|
||||
logger.warn("Using deprecated 'claims' configuration in JSON representation. It will be removed in future versions");
|
||||
long mask = getClaimsMask(claimRep);
|
||||
MigrationProvider migrationProvider = session.getProvider(MigrationProvider.class);
|
||||
return migrationProvider.getMappersForClaimMask(mask);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateRealm(RealmRepresentation rep, RealmModel realm) {
|
||||
@@ -432,31 +481,30 @@ public class RepresentationToModel {
|
||||
role.addCompositeRole(realmRole);
|
||||
}
|
||||
}
|
||||
if (roleRep.getComposites().getApplication() != null) {
|
||||
for (Map.Entry<String, List<String>> entry : roleRep.getComposites().getApplication().entrySet()) {
|
||||
ApplicationModel app = realm.getApplicationByName(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, ApplicationModel> createApplications(KeycloakSession session, RealmRepresentation rep, RealmModel realm) {
|
||||
Map<String, ApplicationModel> appMap = new HashMap<String, ApplicationModel>();
|
||||
for (ApplicationRepresentation resourceRep : rep.getApplications()) {
|
||||
ApplicationModel app = createApplication(session, realm, resourceRep, false);
|
||||
appMap.put(app.getName(), app);
|
||||
private static Map<String, ClientModel> createClients(KeycloakSession session, RealmRepresentation rep, RealmModel realm) {
|
||||
Map<String, ClientModel> appMap = new HashMap<String, ClientModel>();
|
||||
for (ClientRepresentation resourceRep : rep.getClients()) {
|
||||
ClientModel app = createClient(session, realm, resourceRep, false);
|
||||
appMap.put(app.getClientId(), app);
|
||||
}
|
||||
return appMap;
|
||||
}
|
||||
@@ -468,63 +516,57 @@ public class RepresentationToModel {
|
||||
* @param resourceRep
|
||||
* @return
|
||||
*/
|
||||
public static ApplicationModel createApplication(KeycloakSession session, RealmModel realm, ApplicationRepresentation resourceRep, boolean addDefaultRoles) {
|
||||
logger.debug("************ CREATE APPLICATION: {0}" + resourceRep.getName());
|
||||
public static ClientModel createClient(KeycloakSession session, RealmModel realm, ClientRepresentation resourceRep, boolean addDefaultRoles) {
|
||||
logger.debug("Create client: {0}" + resourceRep.getClientId());
|
||||
|
||||
if (resourceRep.getProtocolMappers() == null) {
|
||||
List<ProtocolMapperRepresentation> convertedProtocolMappers = convertDeprecatedClaimsMask(session, resourceRep.getClaims());
|
||||
if (convertedProtocolMappers != null) {
|
||||
resourceRep.setProtocolMappers(convertedProtocolMappers);
|
||||
}
|
||||
}
|
||||
|
||||
ApplicationModel applicationModel = resourceRep.getId()!=null ? realm.addApplication(resourceRep.getId(), resourceRep.getName()) : realm.addApplication(resourceRep.getName());
|
||||
if (resourceRep.isEnabled() != null) applicationModel.setEnabled(resourceRep.isEnabled());
|
||||
applicationModel.setManagementUrl(resourceRep.getAdminUrl());
|
||||
ClientModel client = resourceRep.getId()!=null ? realm.addClient(resourceRep.getId(), resourceRep.getClientId()) : realm.addClient(resourceRep.getClientId());
|
||||
if (resourceRep.isEnabled() != null) client.setEnabled(resourceRep.isEnabled());
|
||||
client.setManagementUrl(resourceRep.getAdminUrl());
|
||||
if (resourceRep.isSurrogateAuthRequired() != null)
|
||||
applicationModel.setSurrogateAuthRequired(resourceRep.isSurrogateAuthRequired());
|
||||
applicationModel.setBaseUrl(resourceRep.getBaseUrl());
|
||||
if (resourceRep.isBearerOnly() != null) applicationModel.setBearerOnly(resourceRep.isBearerOnly());
|
||||
if (resourceRep.isPublicClient() != null) applicationModel.setPublicClient(resourceRep.isPublicClient());
|
||||
if (resourceRep.isFrontchannelLogout() != null) applicationModel.setFrontchannelLogout(resourceRep.isFrontchannelLogout());
|
||||
if (resourceRep.getProtocol() != null) applicationModel.setProtocol(resourceRep.getProtocol());
|
||||
client.setSurrogateAuthRequired(resourceRep.isSurrogateAuthRequired());
|
||||
client.setBaseUrl(resourceRep.getBaseUrl());
|
||||
if (resourceRep.isBearerOnly() != null) client.setBearerOnly(resourceRep.isBearerOnly());
|
||||
if (resourceRep.isConsentRequired() != null) client.setConsentRequired(resourceRep.isConsentRequired());
|
||||
if (resourceRep.isPublicClient() != null) client.setPublicClient(resourceRep.isPublicClient());
|
||||
if (resourceRep.isFrontchannelLogout() != null) client.setFrontchannelLogout(resourceRep.isFrontchannelLogout());
|
||||
if (resourceRep.getProtocol() != null) client.setProtocol(resourceRep.getProtocol());
|
||||
if (resourceRep.isFullScopeAllowed() != null) {
|
||||
applicationModel.setFullScopeAllowed(resourceRep.isFullScopeAllowed());
|
||||
client.setFullScopeAllowed(resourceRep.isFullScopeAllowed());
|
||||
} else {
|
||||
applicationModel.setFullScopeAllowed(true);
|
||||
client.setFullScopeAllowed(!client.isConsentRequired());
|
||||
}
|
||||
if (resourceRep.getNodeReRegistrationTimeout() != null) {
|
||||
applicationModel.setNodeReRegistrationTimeout(resourceRep.getNodeReRegistrationTimeout());
|
||||
client.setNodeReRegistrationTimeout(resourceRep.getNodeReRegistrationTimeout());
|
||||
} else {
|
||||
applicationModel.setNodeReRegistrationTimeout(-1);
|
||||
client.setNodeReRegistrationTimeout(-1);
|
||||
}
|
||||
applicationModel.updateApplication();
|
||||
client.updateClient();
|
||||
|
||||
if (resourceRep.getNotBefore() != null) {
|
||||
applicationModel.setNotBefore(resourceRep.getNotBefore());
|
||||
client.setNotBefore(resourceRep.getNotBefore());
|
||||
}
|
||||
|
||||
applicationModel.setSecret(resourceRep.getSecret());
|
||||
if (applicationModel.getSecret() == null) {
|
||||
KeycloakModelUtils.generateSecret(applicationModel);
|
||||
client.setSecret(resourceRep.getSecret());
|
||||
if (client.getSecret() == null) {
|
||||
KeycloakModelUtils.generateSecret(client);
|
||||
}
|
||||
|
||||
if (resourceRep.getAttributes() != null) {
|
||||
for (Map.Entry<String, String> entry : resourceRep.getAttributes().entrySet()) {
|
||||
applicationModel.setAttribute(entry.getKey(), entry.getValue());
|
||||
client.setAttribute(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (resourceRep.getRedirectUris() != null) {
|
||||
for (String redirectUri : resourceRep.getRedirectUris()) {
|
||||
applicationModel.addRedirectUri(redirectUri);
|
||||
client.addRedirectUri(redirectUri);
|
||||
}
|
||||
}
|
||||
if (resourceRep.getWebOrigins() != null) {
|
||||
for (String webOrigin : resourceRep.getWebOrigins()) {
|
||||
logger.debugv("Application: {0} webOrigin: {1}", resourceRep.getName(), webOrigin);
|
||||
applicationModel.addWebOrigin(webOrigin);
|
||||
logger.debugv("Client: {0} webOrigin: {1}", resourceRep.getClientId(), webOrigin);
|
||||
client.addWebOrigin(webOrigin);
|
||||
}
|
||||
} else {
|
||||
// add origins from redirect uris
|
||||
@@ -538,45 +580,46 @@ public class RepresentationToModel {
|
||||
if (uri.getPort() != -1) {
|
||||
origin += ":" + uri.getPort();
|
||||
}
|
||||
logger.debugv("adding default application origin: {0}" , origin);
|
||||
logger.debugv("adding default client origin: {0}" , origin);
|
||||
origins.add(origin);
|
||||
}
|
||||
}
|
||||
if (origins.size() > 0) {
|
||||
applicationModel.setWebOrigins(origins);
|
||||
client.setWebOrigins(origins);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resourceRep.getRegisteredNodes() != null) {
|
||||
for (Map.Entry<String, Integer> entry : resourceRep.getRegisteredNodes().entrySet()) {
|
||||
applicationModel.registerNode(entry.getKey(), entry.getValue());
|
||||
client.registerNode(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (addDefaultRoles && resourceRep.getDefaultRoles() != null) {
|
||||
applicationModel.updateDefaultRoles(resourceRep.getDefaultRoles());
|
||||
client.updateDefaultRoles(resourceRep.getDefaultRoles());
|
||||
}
|
||||
|
||||
if (resourceRep.getProtocolMappers() != null) {
|
||||
// first, remove all default/built in mappers
|
||||
Set<ProtocolMapperModel> mappers = applicationModel.getProtocolMappers();
|
||||
for (ProtocolMapperModel mapper : mappers) applicationModel.removeProtocolMapper(mapper);
|
||||
Set<ProtocolMapperModel> mappers = client.getProtocolMappers();
|
||||
for (ProtocolMapperModel mapper : mappers) client.removeProtocolMapper(mapper);
|
||||
|
||||
for (ProtocolMapperRepresentation mapper : resourceRep.getProtocolMappers()) {
|
||||
applicationModel.addProtocolMapper(toModel(mapper));
|
||||
client.addProtocolMapper(toModel(mapper));
|
||||
}
|
||||
}
|
||||
|
||||
applicationModel.updateIdentityProviders(toModel(resourceRep.getIdentityProviders(), realm));
|
||||
client.updateIdentityProviders(toModel(resourceRep.getIdentityProviders(), realm));
|
||||
|
||||
return applicationModel;
|
||||
return client;
|
||||
}
|
||||
|
||||
public static void updateApplication(ApplicationRepresentation rep, ApplicationModel resource) {
|
||||
if (rep.getName() != null) resource.setName(rep.getName());
|
||||
public static void updateClient(ClientRepresentation rep, ClientModel resource) {
|
||||
if (rep.getClientId() != null) resource.setClientId(rep.getClientId());
|
||||
if (rep.isEnabled() != null) resource.setEnabled(rep.isEnabled());
|
||||
if (rep.isBearerOnly() != null) resource.setBearerOnly(rep.isBearerOnly());
|
||||
if (rep.isConsentRequired() != null) resource.setConsentRequired(rep.isConsentRequired());
|
||||
if (rep.isPublicClient() != null) resource.setPublicClient(rep.isPublicClient());
|
||||
if (rep.isFullScopeAllowed() != null) resource.setFullScopeAllowed(rep.isFullScopeAllowed());
|
||||
if (rep.isFrontchannelLogout() != null) resource.setFrontchannelLogout(rep.isFrontchannelLogout());
|
||||
@@ -584,7 +627,7 @@ public class RepresentationToModel {
|
||||
if (rep.getBaseUrl() != null) resource.setBaseUrl(rep.getBaseUrl());
|
||||
if (rep.isSurrogateAuthRequired() != null) resource.setSurrogateAuthRequired(rep.isSurrogateAuthRequired());
|
||||
if (rep.getNodeReRegistrationTimeout() != null) resource.setNodeReRegistrationTimeout(rep.getNodeReRegistrationTimeout());
|
||||
resource.updateApplication();
|
||||
resource.updateClient();
|
||||
|
||||
if (rep.getProtocol() != null) resource.setProtocol(rep.getProtocol());
|
||||
if (rep.getAttributes() != null) {
|
||||
@@ -676,93 +719,18 @@ public class RepresentationToModel {
|
||||
return mask;
|
||||
}
|
||||
|
||||
// OAuth clients
|
||||
|
||||
private static void createOAuthClients(KeycloakSession session, RealmRepresentation realmRep, RealmModel realm) {
|
||||
for (OAuthClientRepresentation rep : realmRep.getOauthClients()) {
|
||||
createOAuthClient(session, rep, realm);
|
||||
}
|
||||
}
|
||||
|
||||
public static OAuthClientModel createOAuthClient(String id, String name, RealmModel realm) {
|
||||
OAuthClientModel model = id!=null ? realm.addOAuthClient(id, name) : realm.addOAuthClient(name);
|
||||
KeycloakModelUtils.generateSecret(model);
|
||||
return model;
|
||||
}
|
||||
|
||||
public static OAuthClientModel createOAuthClient(KeycloakSession session, OAuthClientRepresentation rep, RealmModel realm) {
|
||||
OAuthClientModel model = createOAuthClient(rep.getId(), rep.getName(), realm);
|
||||
|
||||
model.updateIdentityProviders(toModel(rep.getIdentityProviders(), realm));
|
||||
|
||||
updateOAuthClient(session, rep, model);
|
||||
return model;
|
||||
}
|
||||
|
||||
public static void updateOAuthClient(KeycloakSession session, OAuthClientRepresentation rep, OAuthClientModel model) {
|
||||
if (rep.getProtocolMappers() == null) {
|
||||
List<ProtocolMapperRepresentation> convertedProtocolMappers = convertDeprecatedClaimsMask(session, rep.getClaims());
|
||||
if (convertedProtocolMappers != null) {
|
||||
rep.setProtocolMappers(convertedProtocolMappers);
|
||||
}
|
||||
}
|
||||
|
||||
if (rep.getName() != null) model.setClientId(rep.getName());
|
||||
if (rep.isEnabled() != null) model.setEnabled(rep.isEnabled());
|
||||
if (rep.isPublicClient() != null) model.setPublicClient(rep.isPublicClient());
|
||||
if (rep.isFrontchannelLogout() != null) model.setFrontchannelLogout(rep.isFrontchannelLogout());
|
||||
if (rep.isFullScopeAllowed() != null) model.setFullScopeAllowed(rep.isFullScopeAllowed());
|
||||
if (rep.isDirectGrantsOnly() != null) model.setDirectGrantsOnly(rep.isDirectGrantsOnly());
|
||||
if (rep.getNotBefore() != null) {
|
||||
model.setNotBefore(rep.getNotBefore());
|
||||
}
|
||||
if (rep.getSecret() != null) model.setSecret(rep.getSecret());
|
||||
List<String> redirectUris = rep.getRedirectUris();
|
||||
if (redirectUris != null) {
|
||||
model.setRedirectUris(new HashSet<String>(redirectUris));
|
||||
}
|
||||
|
||||
List<String> webOrigins = rep.getWebOrigins();
|
||||
if (webOrigins != null) {
|
||||
model.setWebOrigins(new HashSet<String>(webOrigins));
|
||||
}
|
||||
|
||||
if (rep.getNotBefore() != null) {
|
||||
model.setNotBefore(rep.getNotBefore());
|
||||
}
|
||||
if (rep.getProtocol() != null) model.setProtocol(rep.getProtocol());
|
||||
if (rep.getAttributes() != null) {
|
||||
for (Map.Entry<String, String> entry : rep.getAttributes().entrySet()) {
|
||||
model.setAttribute(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
updateClientIdentityProviders(rep.getIdentityProviders(), model);
|
||||
|
||||
if (rep.getProtocolMappers() != null) {
|
||||
// first, remove all default/built in mappers
|
||||
Set<ProtocolMapperModel> mappers = model.getProtocolMappers();
|
||||
for (ProtocolMapperModel mapper : mappers) model.removeProtocolMapper(mapper);
|
||||
|
||||
for (ProtocolMapperRepresentation mapper : rep.getProtocolMappers()) {
|
||||
model.addProtocolMapper(toModel(mapper));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Scope mappings
|
||||
|
||||
public static void createApplicationScopeMappings(RealmModel realm, ApplicationModel applicationModel, List<ScopeMappingRepresentation> mappings) {
|
||||
public static void createClientScopeMappings(RealmModel realm, ClientModel clientModel, List<ScopeMappingRepresentation> mappings) {
|
||||
for (ScopeMappingRepresentation mapping : mappings) {
|
||||
ClientModel client = realm.findClient(mapping.getClient());
|
||||
ClientModel client = realm.getClientByClientId(mapping.getClient());
|
||||
if (client == null) {
|
||||
throw new RuntimeException("Unknown client specified in application scope mappings");
|
||||
throw new RuntimeException("Unknown client specified in client scope mappings");
|
||||
}
|
||||
for (String roleString : mapping.getRoles()) {
|
||||
RoleModel role = applicationModel.getRole(roleString.trim());
|
||||
RoleModel role = clientModel.getRole(roleString.trim());
|
||||
if (role == null) {
|
||||
role = applicationModel.addRole(roleString.trim());
|
||||
role = clientModel.addRole(roleString.trim());
|
||||
}
|
||||
client.addScopeMapping(role);
|
||||
}
|
||||
@@ -771,7 +739,7 @@ public class RepresentationToModel {
|
||||
|
||||
// Users
|
||||
|
||||
public static UserModel createUser(KeycloakSession session, RealmModel newRealm, UserRepresentation userRep, Map<String, ApplicationModel> appMap) {
|
||||
public static UserModel createUser(KeycloakSession session, RealmModel newRealm, UserRepresentation userRep, Map<String, ClientModel> clientMap) {
|
||||
convertDeprecatedSocialProviders(userRep);
|
||||
|
||||
// Import users just to user storage. Don't federate
|
||||
@@ -812,13 +780,13 @@ public class RepresentationToModel {
|
||||
user.grantRole(role);
|
||||
}
|
||||
}
|
||||
if (userRep.getApplicationRoles() != null) {
|
||||
for (Map.Entry<String, List<String>> entry : userRep.getApplicationRoles().entrySet()) {
|
||||
ApplicationModel app = appMap.get(entry.getKey());
|
||||
if (app == null) {
|
||||
throw new RuntimeException("Unable to find application role mappings for app: " + entry.getKey());
|
||||
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());
|
||||
}
|
||||
createApplicationRoleMappings(app, user, entry.getValue());
|
||||
createClientRoleMappings(client, user, entry.getValue());
|
||||
}
|
||||
}
|
||||
return user;
|
||||
@@ -853,15 +821,15 @@ public class RepresentationToModel {
|
||||
|
||||
// Role mappings
|
||||
|
||||
public static void createApplicationRoleMappings(ApplicationModel applicationModel, UserModel user, List<String> roleNames) {
|
||||
public static void createClientRoleMappings(ClientModel clientModel, UserModel user, List<String> roleNames) {
|
||||
if (user == null) {
|
||||
throw new RuntimeException("User not found");
|
||||
}
|
||||
|
||||
for (String roleName : roleNames) {
|
||||
RoleModel role = applicationModel.getRole(roleName.trim());
|
||||
RoleModel role = clientModel.getRole(roleName.trim());
|
||||
if (role == null) {
|
||||
role = applicationModel.addRole(roleName.trim());
|
||||
role = clientModel.addRole(roleName.trim());
|
||||
}
|
||||
user.grantRole(role);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.keycloak.models.utils;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.UserCredentialValueModel;
|
||||
@@ -152,8 +152,8 @@ public class UserModelDelegate implements UserModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationRoleMappings(ApplicationModel app) {
|
||||
return delegate.getApplicationRoleMappings(app);
|
||||
public Set<RoleModel> getClientRoleMappings(ClientModel app) {
|
||||
return delegate.getClientRoleMappings(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package org.keycloak.models.utils.reflection;
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* A criteria that matches a property based on name
|
||||
*
|
||||
* @see PropertyCriteria
|
||||
*/
|
||||
public class NamedPropertyCriteria implements PropertyCriteria {
|
||||
private final String[] propertyNames;
|
||||
|
||||
public NamedPropertyCriteria(String... propertyNames) {
|
||||
this.propertyNames = propertyNames;
|
||||
}
|
||||
|
||||
public boolean fieldMatches(Field f) {
|
||||
for (String propertyName : propertyNames) {
|
||||
if (propertyName.equals(f.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean methodMatches(Method m) {
|
||||
String[] validPrefix = {"get", "is"};
|
||||
for (String propertyName : propertyNames) {
|
||||
for (String prefix : validPrefix) {
|
||||
if (m.getName().startsWith(prefix) &&
|
||||
Introspector.decapitalize(m.getName().substring(prefix.length())).equals(propertyName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package org.keycloak.models.utils.reflection;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* A criteria that matches a property based on its type
|
||||
*
|
||||
* @see PropertyCriteria
|
||||
*/
|
||||
public class TypedPropertyCriteria implements PropertyCriteria {
|
||||
|
||||
/**
|
||||
* <p> Different options can be used to match a specific property based on its type. Regardless of the option
|
||||
* chosen, if the property type equals the <code>propertyClass</code> it will be selected. <p/> <ul> <li>SUB_TYPE:
|
||||
* Also consider properties where its type is a subtype of <code>propertyClass</code>. .</li> <li>SUPER_TYPE: Also
|
||||
* consider properties where its type is a superclass or superinterface of <code>propertyClass</code>. .</li> </ul>
|
||||
* </p>
|
||||
*/
|
||||
public static enum MatchOption {
|
||||
SUB_TYPE, SUPER_TYPE, ALL
|
||||
}
|
||||
|
||||
private final Class<?> propertyClass;
|
||||
private final MatchOption matchOption;
|
||||
|
||||
public TypedPropertyCriteria(Class<?> propertyClass) {
|
||||
this(propertyClass, null);
|
||||
}
|
||||
|
||||
public TypedPropertyCriteria(Class<?> propertyClass, MatchOption matchOption) {
|
||||
if (propertyClass == null) {
|
||||
throw new IllegalArgumentException("Property class can not be null.");
|
||||
}
|
||||
this.propertyClass = propertyClass;
|
||||
this.matchOption = matchOption;
|
||||
}
|
||||
|
||||
public boolean fieldMatches(Field f) {
|
||||
return match(f.getType());
|
||||
}
|
||||
|
||||
public boolean methodMatches(Method m) {
|
||||
return match(m.getReturnType());
|
||||
}
|
||||
|
||||
private boolean match(Class<?> type) {
|
||||
if (propertyClass.equals(type)) {
|
||||
return true;
|
||||
} else {
|
||||
boolean matchSubType = propertyClass.isAssignableFrom(type);
|
||||
|
||||
if (MatchOption.SUB_TYPE == this.matchOption) {
|
||||
return matchSubType;
|
||||
}
|
||||
|
||||
boolean matchSuperType = type.isAssignableFrom(propertyClass);
|
||||
|
||||
if (MatchOption.SUPER_TYPE == this.matchOption) {
|
||||
return matchSuperType;
|
||||
}
|
||||
|
||||
if (MatchOption.ALL == this.matchOption) {
|
||||
return matchSubType || matchSuperType;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,21 +16,20 @@
|
||||
*/
|
||||
package org.keycloak.models.file;
|
||||
|
||||
import org.keycloak.models.file.adapter.RealmAdapter;
|
||||
import java.util.ArrayList;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.connections.file.FileConnectionProvider;
|
||||
import org.keycloak.connections.file.InMemoryModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.entities.RealmEntity;
|
||||
import org.keycloak.models.file.adapter.RealmAdapter;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.keycloak.connections.file.FileConnectionProvider;
|
||||
import org.keycloak.connections.file.InMemoryModel;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.entities.RealmEntity;
|
||||
|
||||
/**
|
||||
* Realm Provider for JSON persistence.
|
||||
@@ -100,13 +99,8 @@ public class FileRealmProvider implements RealmProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationById(String id, RealmModel realm) {
|
||||
return realm.getApplicationById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClientById(String id, RealmModel realm) {
|
||||
return realm.getOAuthClientById(id);
|
||||
public ClientModel getClientById(String id, RealmModel realm) {
|
||||
return realm.getClientById(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import org.keycloak.connections.file.FileConnectionProvider;
|
||||
import org.keycloak.connections.file.InMemoryModel;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.CredentialValidationOutput;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.entities.FederatedIdentityEntity;
|
||||
@@ -276,7 +276,7 @@ public class FileUserProvider implements UserProvider {
|
||||
userModel.grantRole(realm.getRole(r));
|
||||
}
|
||||
|
||||
for (ApplicationModel application : realm.getApplications()) {
|
||||
for (ClientModel application : realm.getClients()) {
|
||||
for (String r : application.getDefaultRoles()) {
|
||||
userModel.grantRole(application.getRole(r));
|
||||
}
|
||||
|
||||
@@ -1,322 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors
|
||||
* as indicated by the @author tags. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.keycloak.models.file.adapter;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.keycloak.connections.file.InMemoryModel;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.entities.ApplicationEntity;
|
||||
import org.keycloak.models.entities.ClientEntity;
|
||||
import org.keycloak.models.entities.RoleEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
/**
|
||||
* ApplicationModel used for JSON persistence.
|
||||
*
|
||||
* @author Stan Silvert ssilvert@redhat.com (C) 2015 Red Hat Inc.
|
||||
*/
|
||||
public class ApplicationAdapter extends ClientAdapter implements ApplicationModel {
|
||||
|
||||
private final ApplicationEntity applicationEntity;
|
||||
private final InMemoryModel inMemoryModel;
|
||||
|
||||
private final Map<String, RoleAdapter> allRoles = new HashMap<String, RoleAdapter>();
|
||||
|
||||
public ApplicationAdapter(KeycloakSession session, RealmModel realm, ApplicationEntity applicationEntity, ClientEntity clientEntity, InMemoryModel inMemoryModel) {
|
||||
super(session, realm, clientEntity);
|
||||
this.applicationEntity = applicationEntity;
|
||||
this.inMemoryModel = inMemoryModel;
|
||||
}
|
||||
|
||||
public ApplicationEntity getApplicationEntity() {
|
||||
return applicationEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateApplication() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return applicationEntity.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
if (appNameExists(name)) throw new ModelDuplicateException("Application named " + name + " already exists.");
|
||||
applicationEntity.setName(name);
|
||||
}
|
||||
|
||||
private boolean appNameExists(String name) {
|
||||
for (ApplicationModel app : realm.getApplications()) {
|
||||
if (app == this) continue;
|
||||
if (app.getName().equals(name)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return applicationEntity.isSurrogateAuthRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
applicationEntity.setSurrogateAuthRequired(surrogateAuthRequired);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getManagementUrl() {
|
||||
return applicationEntity.getManagementUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManagementUrl(String url) {
|
||||
applicationEntity.setManagementUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseUrl(String url) {
|
||||
applicationEntity.setBaseUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseUrl() {
|
||||
return applicationEntity.getBaseUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBearerOnly() {
|
||||
return applicationEntity.isBearerOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearerOnly(boolean only) {
|
||||
applicationEntity.setBearerOnly(only);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPublicClient() {
|
||||
return applicationEntity.isPublicClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPublicClient(boolean flag) {
|
||||
applicationEntity.setPublicClient(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return false; // applications can't be grant only
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectGrantsOnly(boolean flag) {
|
||||
// applications can't be grant only
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RoleAdapter getRole(String name) {
|
||||
for (RoleAdapter role : allRoles.values()) {
|
||||
if (role.getName().equals(name)) return role;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleAdapter addRole(String name) {
|
||||
return this.addRole(KeycloakModelUtils.generateId(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleAdapter addRole(String id, String name) {
|
||||
if (roleNameExists(name)) throw new ModelDuplicateException("Role named " + name + " already exists.");
|
||||
RoleEntity roleEntity = new RoleEntity();
|
||||
roleEntity.setId(id);
|
||||
roleEntity.setName(name);
|
||||
roleEntity.setApplicationId(getId());
|
||||
|
||||
RoleAdapter role = new RoleAdapter(getRealm(), roleEntity, this);
|
||||
allRoles.put(id, role);
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
private boolean roleNameExists(String name) {
|
||||
for (RoleModel role : allRoles.values()) {
|
||||
if (role.getName().equals(name)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(RoleModel role) {
|
||||
boolean removed = (allRoles.remove(role.getId()) != null);
|
||||
|
||||
// remove application roles from users
|
||||
for (UserModel user : inMemoryModel.getUsers(realm.getId())) {
|
||||
user.deleteRoleMapping(role);
|
||||
}
|
||||
|
||||
// delete scope mappings from applications
|
||||
for (ApplicationModel app : realm.getApplications()) {
|
||||
app.deleteScopeMapping(role);
|
||||
}
|
||||
|
||||
// delete scope mappings from oauth clients
|
||||
for (OAuthClientModel oaClient : realm.getOAuthClients()) {
|
||||
oaClient.deleteScopeMapping(role);
|
||||
}
|
||||
|
||||
// remove role from the realm
|
||||
realm.removeRole(role);
|
||||
|
||||
this.deleteScopeMapping(role);
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getRoles() {
|
||||
return new HashSet(allRoles.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScope(RoleModel role) {
|
||||
if (super.hasScope(role)) {
|
||||
return true;
|
||||
}
|
||||
Set<RoleModel> roles = getRoles();
|
||||
if (roles.contains(role)) return true;
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationScopeMappings(ClientModel client) {
|
||||
Set<RoleModel> allScopes = client.getScopeMappings();
|
||||
|
||||
Set<RoleModel> appRoles = new HashSet<RoleModel>();
|
||||
for (RoleModel role : allScopes) {
|
||||
RoleAdapter roleAdapter = (RoleAdapter)role;
|
||||
if (getId().equals(roleAdapter.getRoleEntity().getApplicationId())) {
|
||||
appRoles.add(role);
|
||||
}
|
||||
}
|
||||
return appRoles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDefaultRoles() {
|
||||
return applicationEntity.getDefaultRoles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultRole(String name) {
|
||||
RoleModel role = getRole(name);
|
||||
if (role == null) {
|
||||
addRole(name);
|
||||
}
|
||||
|
||||
List<String> defaultRoles = getDefaultRoles();
|
||||
if (defaultRoles.contains(name)) return;
|
||||
|
||||
String[] defaultRoleNames = defaultRoles.toArray(new String[defaultRoles.size() + 1]);
|
||||
defaultRoleNames[defaultRoleNames.length - 1] = name;
|
||||
updateDefaultRoles(defaultRoleNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDefaultRoles(String[] defaultRoles) {
|
||||
List<String> roleNames = new ArrayList<String>();
|
||||
for (String roleName : defaultRoles) {
|
||||
RoleModel role = getRole(roleName);
|
||||
if (role == null) {
|
||||
addRole(roleName);
|
||||
}
|
||||
|
||||
roleNames.add(roleName);
|
||||
}
|
||||
|
||||
applicationEntity.setDefaultRoles(roleNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
return applicationEntity.getNodeReRegistrationTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNodeReRegistrationTimeout(int timeout) {
|
||||
applicationEntity.setNodeReRegistrationTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
return applicationEntity.getRegisteredNodes() == null ? Collections.<String, Integer>emptyMap() : Collections.unmodifiableMap(applicationEntity.getRegisteredNodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNode(String nodeHost, int registrationTime) {
|
||||
if (applicationEntity.getRegisteredNodes() == null) {
|
||||
applicationEntity.setRegisteredNodes(new HashMap<String, Integer>());
|
||||
}
|
||||
|
||||
applicationEntity.getRegisteredNodes().put(nodeHost, registrationTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterNode(String nodeHost) {
|
||||
if (applicationEntity.getRegisteredNodes() == null) return;
|
||||
|
||||
applicationEntity.getRegisteredNodes().remove(nodeHost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof ApplicationModel)) return false;
|
||||
|
||||
ApplicationModel that = (ApplicationModel) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,45 +0,0 @@
|
||||
package org.keycloak.models.file.adapter;
|
||||
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.entities.OAuthClientEntity;
|
||||
|
||||
/**
|
||||
* OAuthClientModel for JSON persistence.
|
||||
*
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class OAuthClientAdapter extends ClientAdapter implements OAuthClientModel {
|
||||
|
||||
private final OAuthClientEntity oauthClientEntity;
|
||||
|
||||
public OAuthClientAdapter(KeycloakSession session, RealmModel realm, OAuthClientEntity oauthClientEntity) {
|
||||
super(session, realm, oauthClientEntity);
|
||||
this.oauthClientEntity = oauthClientEntity;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return oauthClientEntity.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientId(String id) {
|
||||
if (id == null) throw new NullPointerException("id == null");
|
||||
if (oauthClientEntity.getName().equals(id)) return; // allow setting name to same name
|
||||
RealmAdapter realmAdapter = (RealmAdapter)realm;
|
||||
if (realmAdapter.hasOAuthClientWithClientId(id)) throw new ModelDuplicateException("Realm already has OAuthClient with client id " + id);
|
||||
oauthClientEntity.setName(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return oauthClientEntity.isDirectGrantsOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectGrantsOnly(boolean flag) {
|
||||
oauthClientEntity.setDirectGrantsOnly(flag);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -111,7 +111,7 @@ public class RoleAdapter implements RoleModel {
|
||||
Set<RoleModel> toBeRemoved = new HashSet<RoleModel>();
|
||||
for (RoleModel compositeRole : getComposites()) {
|
||||
RoleAdapter roleAdapter = (RoleAdapter)compositeRole;
|
||||
if (appId.equals(roleAdapter.getRoleEntity().getApplicationId())) {
|
||||
if (appId.equals(roleAdapter.getRoleEntity().getClientId())) {
|
||||
toBeRemoved.add(compositeRole);
|
||||
} else {
|
||||
roleAdapter.removeApplicationComposites(appId);
|
||||
@@ -143,8 +143,8 @@ public class RoleAdapter implements RoleModel {
|
||||
// Compute it
|
||||
if (role.getRealmId() != null) {
|
||||
roleContainer = realm;//new RealmAdapter(session, realm);
|
||||
} else if (role.getApplicationId() != null) {
|
||||
roleContainer = realm.getApplicationById(role.getApplicationId());//new ApplicationAdapter(session, realm, appEntity);
|
||||
} else if (role.getClientId() != null) {
|
||||
roleContainer = realm.getClientById(role.getClientId());//new ApplicationAdapter(session, realm, appEntity);
|
||||
} else {
|
||||
throw new IllegalStateException("Both realmId and applicationId are null for role: " + this);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.keycloak.models.file.adapter;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
@@ -325,12 +325,12 @@ public class UserAdapter implements UserModel, Comparable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationRoleMappings(ApplicationModel app) {
|
||||
public Set<RoleModel> getClientRoleMappings(ClientModel app) {
|
||||
Set<RoleModel> result = new HashSet<RoleModel>();
|
||||
|
||||
for (RoleModel role : allRoles) {
|
||||
RoleEntity roleEntity = ((RoleAdapter)role).getRoleEntity();
|
||||
if (app.getId().equals(roleEntity.getApplicationId())) {
|
||||
if (app.getId().equals(roleEntity.getClientId())) {
|
||||
result.add(new RoleAdapter(realm, roleEntity, app));
|
||||
}
|
||||
}
|
||||
|
||||
-26
@@ -4,7 +4,6 @@ import org.infinispan.Cache;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.cache.RealmCache;
|
||||
import org.keycloak.models.cache.entities.CachedApplication;
|
||||
import org.keycloak.models.cache.entities.CachedOAuthClient;
|
||||
import org.keycloak.models.cache.entities.CachedRealm;
|
||||
import org.keycloak.models.cache.entities.CachedRole;
|
||||
|
||||
@@ -102,31 +101,6 @@ public class InfinispanRealmCache implements RealmCache {
|
||||
cache.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedOAuthClient getOAuthClient(String id) {
|
||||
if (!enabled) return null;
|
||||
return get(id, CachedOAuthClient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateOAuthClient(CachedOAuthClient client) {
|
||||
logger.tracev("Removing oauth client {0}", client.getId());
|
||||
cache.remove(client.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCachedOAuthClient(CachedOAuthClient client) {
|
||||
if (!enabled) return;
|
||||
logger.tracev("Adding oauth client {0}", client.getId());
|
||||
cache.put(client.getId(), client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCachedOAuthClientById(String id) {
|
||||
logger.tracev("Removing oauth client {0}", id);
|
||||
cache.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedRole getRole(String id) {
|
||||
if (!enabled) return null;
|
||||
|
||||
-247
@@ -1,247 +0,0 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.cache.entities.CachedApplication;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class ApplicationAdapter extends ClientAdapter implements ApplicationModel {
|
||||
protected ApplicationModel updated;
|
||||
protected CachedApplication cached;
|
||||
|
||||
public ApplicationAdapter(RealmModel cachedRealm, CachedApplication cached, CacheRealmProvider cacheSession, RealmCache cache) {
|
||||
super(cachedRealm, cached, cache, cacheSession);
|
||||
this.cached = cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getDelegateForUpdate() {
|
||||
if (updated == null) {
|
||||
cacheSession.registerApplicationInvalidation(getId());
|
||||
updatedClient = updated = cacheSession.getDelegate().getApplicationById(getId(), cachedRealm);
|
||||
if (updated == null) throw new IllegalStateException("Not found in database");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateApplication() {
|
||||
if (updated != null) updated.updateApplication();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (updated != null) return updated.getName();
|
||||
return cached.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientId() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
getDelegateForUpdate();
|
||||
updated.setName(name);
|
||||
cacheSession.registerRealmInvalidation(cachedRealm.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
if (updated != null) return updated.isSurrogateAuthRequired();
|
||||
return cached.isSurrogateAuthRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
getDelegateForUpdate();
|
||||
updated.setSurrogateAuthRequired(surrogateAuthRequired);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getManagementUrl() {
|
||||
if (updated != null) return updated.getManagementUrl();
|
||||
return cached.getManagementUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManagementUrl(String url) {
|
||||
getDelegateForUpdate();
|
||||
updated.setManagementUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseUrl() {
|
||||
if (updated != null) return updated.getBaseUrl();
|
||||
return cached.getBaseUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseUrl(String url) {
|
||||
getDelegateForUpdate();
|
||||
updated.setBaseUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDefaultRoles() {
|
||||
if (updated != null) return updated.getDefaultRoles();
|
||||
return cached.getDefaultRoles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultRole(String name) {
|
||||
getDelegateForUpdate();
|
||||
updated.addDefaultRole(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDefaultRoles(String[] defaultRoles) {
|
||||
getDelegateForUpdate();
|
||||
updated.updateDefaultRoles(defaultRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationScopeMappings(ClientModel client) {
|
||||
Set<RoleModel> roleMappings = client.getScopeMappings();
|
||||
|
||||
Set<RoleModel> appRoles = new HashSet<RoleModel>();
|
||||
for (RoleModel role : roleMappings) {
|
||||
RoleContainerModel container = role.getContainer();
|
||||
if (container instanceof RealmModel) {
|
||||
} else {
|
||||
ApplicationModel app = (ApplicationModel)container;
|
||||
if (app.getId().equals(getId())) {
|
||||
appRoles.add(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appRoles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBearerOnly() {
|
||||
if (updated != null) return updated.isBearerOnly();
|
||||
return cached.isBearerOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearerOnly(boolean only) {
|
||||
getDelegateForUpdate();
|
||||
updated.setBearerOnly(only);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel getRole(String name) {
|
||||
if (updated != null) return updated.getRole(name);
|
||||
String id = cached.getRoles().get(name);
|
||||
if (id == null) return null;
|
||||
return cacheSession.getRoleById(id, cachedRealm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel addRole(String name) {
|
||||
getDelegateForUpdate();
|
||||
RoleModel role = updated.addRole(name);
|
||||
cacheSession.registerRoleInvalidation(role.getId());
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel addRole(String id, String name) {
|
||||
getDelegateForUpdate();
|
||||
RoleModel role = updated.addRole(id, name);
|
||||
cacheSession.registerRoleInvalidation(role.getId());
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(RoleModel role) {
|
||||
cacheSession.registerRoleInvalidation(role.getId());
|
||||
getDelegateForUpdate();
|
||||
return updated.removeRole(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getRoles() {
|
||||
if (updated != null) return updated.getRoles();
|
||||
|
||||
Set<RoleModel> roles = new HashSet<RoleModel>();
|
||||
for (String id : cached.getRoles().values()) {
|
||||
RoleModel roleById = cacheSession.getRoleById(id, cachedRealm);
|
||||
if (roleById == null) continue;
|
||||
roles.add(roleById);
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
if (updated != null) return updated.getNodeReRegistrationTimeout();
|
||||
return cached.getNodeReRegistrationTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNodeReRegistrationTimeout(int timeout) {
|
||||
getDelegateForUpdate();
|
||||
updated.setNodeReRegistrationTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
if (updated != null) return updated.getRegisteredNodes();
|
||||
return cached.getRegisteredNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNode(String nodeHost, int registrationTime) {
|
||||
getDelegateForUpdate();
|
||||
updated.registerNode(nodeHost, registrationTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterNode(String nodeHost) {
|
||||
getDelegateForUpdate();
|
||||
updated.unregisterNode(nodeHost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScope(RoleModel role) {
|
||||
if (super.hasScope(role)) {
|
||||
return true;
|
||||
}
|
||||
Set<RoleModel> roles = getRoles();
|
||||
if (roles.contains(role)) return true;
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof ApplicationModel)) return false;
|
||||
|
||||
ApplicationModel that = (ApplicationModel) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
-4
@@ -17,8 +17,4 @@ public interface CacheRealmProvider extends RealmProvider {
|
||||
void registerApplicationInvalidation(String id);
|
||||
|
||||
void registerRoleInvalidation(String id);
|
||||
|
||||
void registerOAuthClientInvalidation(String id);
|
||||
|
||||
void registerUserInvalidation(String id);
|
||||
}
|
||||
Vendored
+297
-82
@@ -1,12 +1,12 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.cache.entities.CachedClient;
|
||||
import org.keycloak.models.cache.entities.CachedApplication;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -18,80 +18,88 @@ import java.util.Set;
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public abstract class ClientAdapter implements ClientModel {
|
||||
protected CachedClient cachedClient;
|
||||
public class ClientAdapter implements ClientModel {
|
||||
protected CacheRealmProvider cacheSession;
|
||||
protected ClientModel updatedClient;
|
||||
protected RealmModel cachedRealm;
|
||||
protected RealmCache cache;
|
||||
|
||||
public ClientAdapter(RealmModel cachedRealm, CachedClient cached, RealmCache cache, CacheRealmProvider cacheSession) {
|
||||
protected ClientModel updated;
|
||||
protected CachedApplication cached;
|
||||
|
||||
public ClientAdapter(RealmModel cachedRealm, CachedApplication cached, CacheRealmProvider cacheSession, RealmCache cache) {
|
||||
this.cachedRealm = cachedRealm;
|
||||
this.cache = cache;
|
||||
this.cacheSession = cacheSession;
|
||||
this.cachedClient = cached;
|
||||
this.cached = cached;
|
||||
}
|
||||
|
||||
protected abstract void getDelegateForUpdate();
|
||||
private void getDelegateForUpdate() {
|
||||
if (updated == null) {
|
||||
cacheSession.registerApplicationInvalidation(getId());
|
||||
updated = updated = cacheSession.getDelegate().getClientById(getId(), cachedRealm);
|
||||
if (updated == null) throw new IllegalStateException("Not found in database");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClient() {
|
||||
if (updated != null) updated.updateClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
if (updatedClient != null) return updatedClient.getId();
|
||||
return cachedClient.getId();
|
||||
if (updated != null) return updated.getId();
|
||||
return cached.getId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public abstract String getClientId();
|
||||
|
||||
public Set<String> getWebOrigins() {
|
||||
if (updatedClient != null) return updatedClient.getWebOrigins();
|
||||
return cachedClient.getWebOrigins();
|
||||
if (updated != null) return updated.getWebOrigins();
|
||||
return cached.getWebOrigins();
|
||||
}
|
||||
|
||||
public void setWebOrigins(Set<String> webOrigins) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setWebOrigins(webOrigins);
|
||||
updated.setWebOrigins(webOrigins);
|
||||
}
|
||||
|
||||
public void addWebOrigin(String webOrigin) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.addWebOrigin(webOrigin);
|
||||
updated.addWebOrigin(webOrigin);
|
||||
}
|
||||
|
||||
public void removeWebOrigin(String webOrigin) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.removeWebOrigin(webOrigin);
|
||||
updated.removeWebOrigin(webOrigin);
|
||||
}
|
||||
|
||||
public Set<String> getRedirectUris() {
|
||||
if (updatedClient != null) return updatedClient.getRedirectUris();
|
||||
return cachedClient.getRedirectUris();
|
||||
if (updated != null) return updated.getRedirectUris();
|
||||
return cached.getRedirectUris();
|
||||
}
|
||||
|
||||
public void setRedirectUris(Set<String> redirectUris) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setRedirectUris(redirectUris);
|
||||
updated.setRedirectUris(redirectUris);
|
||||
}
|
||||
|
||||
public void addRedirectUri(String redirectUri) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.addRedirectUri(redirectUri);
|
||||
updated.addRedirectUri(redirectUri);
|
||||
}
|
||||
|
||||
public void removeRedirectUri(String redirectUri) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.removeRedirectUri(redirectUri);
|
||||
updated.removeRedirectUri(redirectUri);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
if (updatedClient != null) return updatedClient.isEnabled();
|
||||
return cachedClient.isEnabled();
|
||||
if (updated != null) return updated.isEnabled();
|
||||
return cached.isEnabled();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setEnabled(enabled);
|
||||
updated.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public boolean validateSecret(String secret) {
|
||||
@@ -99,62 +107,62 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
if (updatedClient != null) return updatedClient.getSecret();
|
||||
return cachedClient.getSecret();
|
||||
if (updated != null) return updated.getSecret();
|
||||
return cached.getSecret();
|
||||
}
|
||||
|
||||
public void setSecret(String secret) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setSecret(secret);
|
||||
updated.setSecret(secret);
|
||||
}
|
||||
|
||||
public boolean isPublicClient() {
|
||||
if (updatedClient != null) return updatedClient.isPublicClient();
|
||||
return cachedClient.isPublicClient();
|
||||
if (updated != null) return updated.isPublicClient();
|
||||
return cached.isPublicClient();
|
||||
}
|
||||
|
||||
public void setPublicClient(boolean flag) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setPublicClient(flag);
|
||||
updated.setPublicClient(flag);
|
||||
}
|
||||
|
||||
public boolean isFrontchannelLogout() {
|
||||
if (updatedClient != null) return updatedClient.isPublicClient();
|
||||
return cachedClient.isFrontchannelLogout();
|
||||
if (updated != null) return updated.isPublicClient();
|
||||
return cached.isFrontchannelLogout();
|
||||
}
|
||||
|
||||
public void setFrontchannelLogout(boolean flag) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setFrontchannelLogout(flag);
|
||||
updated.setFrontchannelLogout(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullScopeAllowed() {
|
||||
if (updatedClient != null) return updatedClient.isFullScopeAllowed();
|
||||
return cachedClient.isFullScopeAllowed();
|
||||
if (updated != null) return updated.isFullScopeAllowed();
|
||||
return cached.isFullScopeAllowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullScopeAllowed(boolean value) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setFullScopeAllowed(value);
|
||||
updated.setFullScopeAllowed(value);
|
||||
|
||||
}
|
||||
|
||||
public boolean isDirectGrantsOnly() {
|
||||
if (updatedClient != null) return updatedClient.isDirectGrantsOnly();
|
||||
return cachedClient.isDirectGrantsOnly();
|
||||
if (updated != null) return updated.isDirectGrantsOnly();
|
||||
return cached.isDirectGrantsOnly();
|
||||
}
|
||||
|
||||
public void setDirectGrantsOnly(boolean flag) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setDirectGrantsOnly(flag);
|
||||
updated.setDirectGrantsOnly(flag);
|
||||
}
|
||||
|
||||
public Set<RoleModel> getScopeMappings() {
|
||||
if (updatedClient != null) return updatedClient.getScopeMappings();
|
||||
if (updated != null) return updated.getScopeMappings();
|
||||
Set<RoleModel> roles = new HashSet<RoleModel>();
|
||||
for (String id : cachedClient.getScope()) {
|
||||
for (String id : cached.getScope()) {
|
||||
roles.add(cacheSession.getRoleById(id, getRealm()));
|
||||
|
||||
}
|
||||
@@ -163,12 +171,12 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
|
||||
public void addScopeMapping(RoleModel role) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.addScopeMapping(role);
|
||||
updated.addScopeMapping(role);
|
||||
}
|
||||
|
||||
public void deleteScopeMapping(RoleModel role) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.deleteScopeMapping(role);
|
||||
updated.deleteScopeMapping(role);
|
||||
}
|
||||
|
||||
public Set<RoleModel> getRealmScopeMappings() {
|
||||
@@ -187,119 +195,107 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
return appRoles;
|
||||
}
|
||||
|
||||
public boolean hasScope(RoleModel role) {
|
||||
if (updatedClient != null) return updatedClient.hasScope(role);
|
||||
if (cachedClient.isFullScopeAllowed() || cachedClient.getScope().contains(role.getId())) return true;
|
||||
|
||||
Set<RoleModel> roles = getScopeMappings();
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public RealmModel getRealm() {
|
||||
return cachedRealm;
|
||||
}
|
||||
|
||||
public int getNotBefore() {
|
||||
if (updatedClient != null) return updatedClient.getNotBefore();
|
||||
return cachedClient.getNotBefore();
|
||||
if (updated != null) return updated.getNotBefore();
|
||||
return cached.getNotBefore();
|
||||
}
|
||||
|
||||
public void setNotBefore(int notBefore) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setNotBefore(notBefore);
|
||||
updated.setNotBefore(notBefore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocol() {
|
||||
if (updatedClient != null) return updatedClient.getProtocol();
|
||||
return cachedClient.getProtocol();
|
||||
if (updated != null) return updated.getProtocol();
|
||||
return cached.getProtocol();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProtocol(String protocol) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setProtocol(protocol);
|
||||
updated.setProtocol(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, String value) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.setAttribute(name, value);
|
||||
updated.setAttribute(name, value);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.removeAttribute(name);
|
||||
updated.removeAttribute(name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAttribute(String name) {
|
||||
if (updatedClient != null) return updatedClient.getAttribute(name);
|
||||
return cachedClient.getAttributes().get(name);
|
||||
if (updated != null) return updated.getAttribute(name);
|
||||
return cached.getAttributes().get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAttributes() {
|
||||
if (updatedClient != null) return updatedClient.getAttributes();
|
||||
if (updated != null) return updated.getAttributes();
|
||||
Map<String, String> copy = new HashMap<String, String>();
|
||||
copy.putAll(cachedClient.getAttributes());
|
||||
copy.putAll(cached.getAttributes());
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIdentityProviders(List<ClientIdentityProviderMappingModel> identityProviders) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.updateIdentityProviders(identityProviders);
|
||||
updated.updateIdentityProviders(identityProviders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ClientIdentityProviderMappingModel> getIdentityProviders() {
|
||||
if (updatedClient != null) return updatedClient.getIdentityProviders();
|
||||
return cachedClient.getIdentityProviders();
|
||||
if (updated != null) return updated.getIdentityProviders();
|
||||
return cached.getIdentityProviders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedRetrieveTokenFromIdentityProvider(String providerId) {
|
||||
if (updatedClient != null) return updatedClient.isAllowedRetrieveTokenFromIdentityProvider(providerId);
|
||||
return cachedClient.isAllowedRetrieveTokenFromIdentityProvider(providerId);
|
||||
if (updated != null) return updated.isAllowedRetrieveTokenFromIdentityProvider(providerId);
|
||||
return cached.isAllowedRetrieveTokenFromIdentityProvider(providerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ProtocolMapperModel> getProtocolMappers() {
|
||||
if (updatedClient != null) return updatedClient.getProtocolMappers();
|
||||
return cachedClient.getProtocolMappers();
|
||||
if (updated != null) return updated.getProtocolMappers();
|
||||
return cached.getProtocolMappers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolMapperModel addProtocolMapper(ProtocolMapperModel model) {
|
||||
getDelegateForUpdate();
|
||||
return updatedClient.addProtocolMapper(model);
|
||||
return updated.addProtocolMapper(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeProtocolMapper(ProtocolMapperModel mapping) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.removeProtocolMapper(mapping);
|
||||
updated.removeProtocolMapper(mapping);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProtocolMapper(ProtocolMapperModel mapping) {
|
||||
getDelegateForUpdate();
|
||||
updatedClient.updateProtocolMapper(mapping);
|
||||
updated.updateProtocolMapper(mapping);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolMapperModel getProtocolMapperById(String id) {
|
||||
for (ProtocolMapperModel mapping : cachedClient.getProtocolMappers()) {
|
||||
for (ProtocolMapperModel mapping : cached.getProtocolMappers()) {
|
||||
if (mapping.getId().equals(id)) return mapping;
|
||||
}
|
||||
return null;
|
||||
@@ -307,9 +303,228 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
|
||||
@Override
|
||||
public ProtocolMapperModel getProtocolMapperByName(String protocol, String name) {
|
||||
for (ProtocolMapperModel mapping : cachedClient.getProtocolMappers()) {
|
||||
for (ProtocolMapperModel mapping : cached.getProtocolMappers()) {
|
||||
if (mapping.getProtocol().equals(protocol) && mapping.getName().equals(name)) return mapping;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientId() {
|
||||
if (updated != null) return updated.getClientId();
|
||||
return cached.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientId(String clientId) {
|
||||
getDelegateForUpdate();
|
||||
updated.setClientId(clientId);
|
||||
cacheSession.registerRealmInvalidation(cachedRealm.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
if (updated != null) return updated.isSurrogateAuthRequired();
|
||||
return cached.isSurrogateAuthRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
getDelegateForUpdate();
|
||||
updated.setSurrogateAuthRequired(surrogateAuthRequired);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getManagementUrl() {
|
||||
if (updated != null) return updated.getManagementUrl();
|
||||
return cached.getManagementUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManagementUrl(String url) {
|
||||
getDelegateForUpdate();
|
||||
updated.setManagementUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseUrl() {
|
||||
if (updated != null) return updated.getBaseUrl();
|
||||
return cached.getBaseUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseUrl(String url) {
|
||||
getDelegateForUpdate();
|
||||
updated.setBaseUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDefaultRoles() {
|
||||
if (updated != null) return updated.getDefaultRoles();
|
||||
return cached.getDefaultRoles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultRole(String name) {
|
||||
getDelegateForUpdate();
|
||||
updated.addDefaultRole(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDefaultRoles(String[] defaultRoles) {
|
||||
getDelegateForUpdate();
|
||||
updated.updateDefaultRoles(defaultRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getClientScopeMappings(ClientModel client) {
|
||||
Set<RoleModel> roleMappings = client.getScopeMappings();
|
||||
|
||||
Set<RoleModel> appRoles = new HashSet<RoleModel>();
|
||||
for (RoleModel role : roleMappings) {
|
||||
RoleContainerModel container = role.getContainer();
|
||||
if (container instanceof RealmModel) {
|
||||
} else {
|
||||
ClientModel app = (ClientModel)container;
|
||||
if (app.getId().equals(getId())) {
|
||||
appRoles.add(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appRoles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBearerOnly() {
|
||||
if (updated != null) return updated.isBearerOnly();
|
||||
return cached.isBearerOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearerOnly(boolean only) {
|
||||
getDelegateForUpdate();
|
||||
updated.setBearerOnly(only);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsentRequired() {
|
||||
if (updated != null) return updated.isConsentRequired();
|
||||
return cached.isConsentRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConsentRequired(boolean consentRequired) {
|
||||
getDelegateForUpdate();
|
||||
updated.setConsentRequired(consentRequired);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel getRole(String name) {
|
||||
if (updated != null) return updated.getRole(name);
|
||||
String id = cached.getRoles().get(name);
|
||||
if (id == null) return null;
|
||||
return cacheSession.getRoleById(id, cachedRealm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel addRole(String name) {
|
||||
getDelegateForUpdate();
|
||||
RoleModel role = updated.addRole(name);
|
||||
cacheSession.registerRoleInvalidation(role.getId());
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel addRole(String id, String name) {
|
||||
getDelegateForUpdate();
|
||||
RoleModel role = updated.addRole(id, name);
|
||||
cacheSession.registerRoleInvalidation(role.getId());
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(RoleModel role) {
|
||||
cacheSession.registerRoleInvalidation(role.getId());
|
||||
getDelegateForUpdate();
|
||||
return updated.removeRole(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getRoles() {
|
||||
if (updated != null) return updated.getRoles();
|
||||
|
||||
Set<RoleModel> roles = new HashSet<RoleModel>();
|
||||
for (String id : cached.getRoles().values()) {
|
||||
RoleModel roleById = cacheSession.getRoleById(id, cachedRealm);
|
||||
if (roleById == null) continue;
|
||||
roles.add(roleById);
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
if (updated != null) return updated.getNodeReRegistrationTimeout();
|
||||
return cached.getNodeReRegistrationTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNodeReRegistrationTimeout(int timeout) {
|
||||
getDelegateForUpdate();
|
||||
updated.setNodeReRegistrationTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
if (updated != null) return updated.getRegisteredNodes();
|
||||
return cached.getRegisteredNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNode(String nodeHost, int registrationTime) {
|
||||
getDelegateForUpdate();
|
||||
updated.registerNode(nodeHost, registrationTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterNode(String nodeHost) {
|
||||
getDelegateForUpdate();
|
||||
updated.unregisterNode(nodeHost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScope(RoleModel role) {
|
||||
if (updated != null) return updated.hasScope(role);
|
||||
if (cached.isFullScopeAllowed() || cached.getScope().contains(role.getId())) return true;
|
||||
|
||||
Set<RoleModel> roles = getScopeMappings();
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
|
||||
roles = getRoles();
|
||||
if (roles.contains(role)) return true;
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof ClientModel)) return false;
|
||||
|
||||
ClientModel that = (ClientModel) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
+9
-51
@@ -1,15 +1,13 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakTransaction;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.cache.entities.CachedApplication;
|
||||
import org.keycloak.models.cache.entities.CachedApplicationRole;
|
||||
import org.keycloak.models.cache.entities.CachedOAuthClient;
|
||||
import org.keycloak.models.cache.entities.CachedRealm;
|
||||
import org.keycloak.models.cache.entities.CachedRealmRole;
|
||||
import org.keycloak.models.cache.entities.CachedRole;
|
||||
@@ -34,11 +32,8 @@ public class DefaultCacheRealmProvider implements CacheRealmProvider {
|
||||
protected Set<String> realmInvalidations = new HashSet<String>();
|
||||
protected Set<String> appInvalidations = new HashSet<String>();
|
||||
protected Set<String> roleInvalidations = new HashSet<String>();
|
||||
protected Set<String> clientInvalidations = new HashSet<String>();
|
||||
protected Set<String> userInvalidations = new HashSet<String>();
|
||||
protected Map<String, RealmModel> managedRealms = new HashMap<String, RealmModel>();
|
||||
protected Map<String, ApplicationModel> managedApplications = new HashMap<String, ApplicationModel>();
|
||||
protected Map<String, OAuthClientModel> managedClients = new HashMap<String, OAuthClientModel>();
|
||||
protected Map<String, ClientModel> managedApplications = new HashMap<String, ClientModel>();
|
||||
protected Map<String, RoleModel> managedRoles = new HashMap<String, RoleModel>();
|
||||
|
||||
protected boolean clearAll;
|
||||
@@ -83,16 +78,6 @@ public class DefaultCacheRealmProvider implements CacheRealmProvider {
|
||||
roleInvalidations.add(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOAuthClientInvalidation(String id) {
|
||||
clientInvalidations.add(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUserInvalidation(String id) {
|
||||
userInvalidations.add(id);
|
||||
}
|
||||
|
||||
protected void runInvalidations() {
|
||||
for (String id : realmInvalidations) {
|
||||
cache.invalidateCachedRealmById(id);
|
||||
@@ -103,9 +88,6 @@ public class DefaultCacheRealmProvider implements CacheRealmProvider {
|
||||
for (String id : appInvalidations) {
|
||||
cache.invalidateCachedApplicationById(id);
|
||||
}
|
||||
for (String id : clientInvalidations) {
|
||||
cache.invalidateCachedOAuthClientById(id);
|
||||
}
|
||||
}
|
||||
|
||||
private KeycloakTransaction getTransaction() {
|
||||
@@ -252,8 +234,8 @@ public class DefaultCacheRealmProvider implements CacheRealmProvider {
|
||||
RoleModel model = getDelegate().getRoleById(id, realm);
|
||||
if (model == null) return null;
|
||||
if (roleInvalidations.contains(id)) return model;
|
||||
if (model.getContainer() instanceof ApplicationModel) {
|
||||
cached = new CachedApplicationRole(((ApplicationModel) model.getContainer()).getId(), model, realm);
|
||||
if (model.getContainer() instanceof ClientModel) {
|
||||
cached = new CachedApplicationRole(((ClientModel) model.getContainer()).getId(), model, realm);
|
||||
} else {
|
||||
cached = new CachedRealmRole(model, realm);
|
||||
}
|
||||
@@ -270,51 +252,27 @@ public class DefaultCacheRealmProvider implements CacheRealmProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationById(String id, RealmModel realm) {
|
||||
if (!cache.isEnabled()) return getDelegate().getApplicationById(id, realm);
|
||||
public ClientModel getClientById(String id, RealmModel realm) {
|
||||
if (!cache.isEnabled()) return getDelegate().getClientById(id, realm);
|
||||
CachedApplication cached = cache.getApplication(id);
|
||||
if (cached != null && !cached.getRealm().equals(realm.getId())) {
|
||||
cached = null;
|
||||
}
|
||||
|
||||
if (cached == null) {
|
||||
ApplicationModel model = getDelegate().getApplicationById(id, realm);
|
||||
ClientModel model = getDelegate().getClientById(id, realm);
|
||||
if (model == null) return null;
|
||||
if (appInvalidations.contains(id)) return model;
|
||||
cached = new CachedApplication(cache, getDelegate(), realm, model);
|
||||
cache.addCachedApplication(cached);
|
||||
} else if (appInvalidations.contains(id)) {
|
||||
return getDelegate().getApplicationById(id, realm);
|
||||
return getDelegate().getClientById(id, realm);
|
||||
} else if (managedApplications.containsKey(id)) {
|
||||
return managedApplications.get(id);
|
||||
}
|
||||
ApplicationAdapter adapter = new ApplicationAdapter(realm, cached, this, cache);
|
||||
ClientAdapter adapter = new ClientAdapter(realm, cached, this, cache);
|
||||
managedApplications.put(id, adapter);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClientById(String id, RealmModel realm) {
|
||||
if (!cache.isEnabled()) return getDelegate().getOAuthClientById(id, realm);
|
||||
CachedOAuthClient cached = cache.getOAuthClient(id);
|
||||
if (cached != null && !cached.getRealm().equals(realm.getId())) {
|
||||
cached = null;
|
||||
}
|
||||
|
||||
if (cached == null) {
|
||||
OAuthClientModel model = getDelegate().getOAuthClientById(id, realm);
|
||||
if (model == null) return null;
|
||||
if (clientInvalidations.contains(id)) return model;
|
||||
cached = new CachedOAuthClient(cache, getDelegate(), realm, model);
|
||||
cache.addCachedOAuthClient(cached);
|
||||
} else if (clientInvalidations.contains(id)) {
|
||||
return getDelegate().getOAuthClientById(id, realm);
|
||||
} else if (managedClients.containsKey(id)) {
|
||||
return managedClients.get(id);
|
||||
}
|
||||
OAuthClientAdapter adapter = new OAuthClientAdapter(realm, cached, this, cache);
|
||||
managedClients.put(id, adapter);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
}
|
||||
-25
@@ -1,7 +1,6 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.models.cache.entities.CachedApplication;
|
||||
import org.keycloak.models.cache.entities.CachedOAuthClient;
|
||||
import org.keycloak.models.cache.entities.CachedRealm;
|
||||
import org.keycloak.models.cache.entities.CachedRole;
|
||||
|
||||
@@ -16,7 +15,6 @@ public class MemoryRealmCache implements RealmCache {
|
||||
protected ConcurrentHashMap<String, CachedRealm> realmCache = new ConcurrentHashMap<String, CachedRealm>();
|
||||
protected ConcurrentHashMap<String, CachedRealm> realmCacheByName = new ConcurrentHashMap<String, CachedRealm>();
|
||||
protected ConcurrentHashMap<String, CachedApplication> applicationCache = new ConcurrentHashMap<String, CachedApplication>();
|
||||
protected ConcurrentHashMap<String, CachedOAuthClient> clientCache = new ConcurrentHashMap<String, CachedOAuthClient>();
|
||||
protected ConcurrentHashMap<String, CachedRole> roleCache = new ConcurrentHashMap<String, CachedRole>();
|
||||
protected volatile boolean enabled = true;
|
||||
|
||||
@@ -25,7 +23,6 @@ public class MemoryRealmCache implements RealmCache {
|
||||
realmCache.clear();
|
||||
realmCacheByName.clear();
|
||||
applicationCache.clear();
|
||||
clientCache.clear();
|
||||
roleCache.clear();
|
||||
}
|
||||
|
||||
@@ -96,28 +93,6 @@ public class MemoryRealmCache implements RealmCache {
|
||||
applicationCache.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedOAuthClient getOAuthClient(String id) {
|
||||
if (!enabled) return null;
|
||||
return clientCache.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateOAuthClient(CachedOAuthClient client) {
|
||||
clientCache.remove(client.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCachedOAuthClient(CachedOAuthClient client) {
|
||||
if (!enabled) return;
|
||||
clientCache.put(client.getId(), client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCachedOAuthClientById(String id) {
|
||||
clientCache.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedRole getRole(String id) {
|
||||
if (!enabled) return null;
|
||||
|
||||
+3
-18
@@ -1,8 +1,7 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RoleModel;
|
||||
@@ -50,10 +49,6 @@ public class NoCacheRealmProvider implements CacheRealmProvider {
|
||||
public void registerRoleInvalidation(String id) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOAuthClientInvalidation(String id) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RealmModel createRealm(String name) {
|
||||
return getDelegate().createRealm(name);
|
||||
@@ -96,17 +91,7 @@ public class NoCacheRealmProvider implements CacheRealmProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationById(String id, RealmModel realm) {
|
||||
return getDelegate().getApplicationById(id, realm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClientById(String id, RealmModel realm) {
|
||||
return getDelegate().getOAuthClientById(id, realm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUserInvalidation(String id) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
public ClientModel getClientById(String id, RealmModel realm) {
|
||||
return getDelegate().getClientById(id, realm);
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.cache.entities.CachedOAuthClient;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class OAuthClientAdapter extends ClientAdapter implements OAuthClientModel {
|
||||
protected OAuthClientModel updated;
|
||||
protected CachedOAuthClient cached;
|
||||
|
||||
public OAuthClientAdapter(RealmModel cachedRealm, CachedOAuthClient cached, CacheRealmProvider cacheSession, RealmCache cache) {
|
||||
super(cachedRealm, cached, cache, cacheSession);
|
||||
this.cached = cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getDelegateForUpdate() {
|
||||
if (updated == null) {
|
||||
cacheSession.registerOAuthClientInvalidation(getId());
|
||||
updatedClient = updated = cacheSession.getDelegate().getOAuthClientById(getId(), cachedRealm);
|
||||
if (updated == null) throw new IllegalStateException("Not found in database");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientId() {
|
||||
if (updated != null) return updated.getClientId();
|
||||
return cached.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientId(String id) {
|
||||
getDelegateForUpdate();
|
||||
updated.setClientId(id);
|
||||
cacheSession.registerRealmInvalidation(cachedRealm.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof OAuthClientModel)) return false;
|
||||
|
||||
OAuthClientModel that = (OAuthClientModel) o;
|
||||
|
||||
return that.getId().equals(this.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
}
|
||||
Vendored
+26
-103
@@ -2,20 +2,15 @@ package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.enums.SslRequired;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClaimTypeModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.IdentityProviderMapperModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.cache.entities.CachedRealm;
|
||||
import org.keycloak.models.entities.IdentityProviderMapperEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
import java.security.Key;
|
||||
@@ -476,39 +471,25 @@ public class RealmAdapter implements RealmModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientModel findClient(String clientId) {
|
||||
if (updated != null) return updated.findClient(clientId);
|
||||
String appId = cached.getApplications().get(clientId);
|
||||
if (appId != null) {
|
||||
return cacheSession.getApplicationById(appId, this);
|
||||
}
|
||||
String oauth = cached.getClients().get(clientId);
|
||||
if (oauth != null) {
|
||||
return cacheSession.getOAuthClientById(oauth, this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ApplicationModel> getApplicationNameMap() {
|
||||
if (updated != null) return updated.getApplicationNameMap();
|
||||
Map<String, ApplicationModel> map = new HashMap<String, ApplicationModel>();
|
||||
public Map<String, ClientModel> getClientNameMap() {
|
||||
if (updated != null) return updated.getClientNameMap();
|
||||
Map<String, ClientModel> map = new HashMap<String, ClientModel>();
|
||||
for (String id : cached.getApplications().values()) {
|
||||
ApplicationModel model = cacheSession.getApplicationById(id, this);
|
||||
ClientModel model = cacheSession.getClientById(id, this);
|
||||
if (model == null) {
|
||||
throw new IllegalStateException("Cached application not found: " + id);
|
||||
}
|
||||
map.put(model.getName(), model);
|
||||
map.put(model.getClientId(), model);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationModel> getApplications() {
|
||||
if (updated != null) return updated.getApplications();
|
||||
List<ApplicationModel> apps = new LinkedList<ApplicationModel>();
|
||||
public List<ClientModel> getClients() {
|
||||
if (updated != null) return updated.getClients();
|
||||
List<ClientModel> apps = new LinkedList<ClientModel>();
|
||||
for (String id : cached.getApplications().values()) {
|
||||
ApplicationModel model = cacheSession.getApplicationById(id, this);
|
||||
ClientModel model = cacheSession.getClientById(id, this);
|
||||
if (model == null) {
|
||||
throw new IllegalStateException("Cached application not found: " + id);
|
||||
}
|
||||
@@ -519,40 +500,40 @@ public class RealmAdapter implements RealmModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel addApplication(String name) {
|
||||
public ClientModel addClient(String name) {
|
||||
getDelegateForUpdate();
|
||||
ApplicationModel app = updated.addApplication(name);
|
||||
ClientModel app = updated.addClient(name);
|
||||
cacheSession.registerApplicationInvalidation(app.getId());
|
||||
return app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel addApplication(String id, String name) {
|
||||
public ClientModel addClient(String id, String clientId) {
|
||||
getDelegateForUpdate();
|
||||
ApplicationModel app = updated.addApplication(id, name);
|
||||
ClientModel app = updated.addClient(id, clientId);
|
||||
cacheSession.registerApplicationInvalidation(app.getId());
|
||||
return app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeApplication(String id) {
|
||||
public boolean removeClient(String id) {
|
||||
cacheSession.registerApplicationInvalidation(id);
|
||||
getDelegateForUpdate();
|
||||
return updated.removeApplication(id);
|
||||
return updated.removeClient(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationById(String id) {
|
||||
if (updated != null) return updated.getApplicationById(id);
|
||||
return cacheSession.getApplicationById(id, this);
|
||||
public ClientModel getClientById(String id) {
|
||||
if (updated != null) return updated.getClientById(id);
|
||||
return cacheSession.getClientById(id, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationByName(String name) {
|
||||
if (updated != null) return updated.getApplicationByName(name);
|
||||
String id = cached.getApplications().get(name);
|
||||
public ClientModel getClientByClientId(String clientId) {
|
||||
if (updated != null) return updated.getClientByClientId(clientId);
|
||||
String id = cached.getApplications().get(clientId);
|
||||
if (id == null) return null;
|
||||
return getApplicationById(id);
|
||||
return getClientById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -561,57 +542,6 @@ public class RealmAdapter implements RealmModel {
|
||||
updated.updateRequiredCredentials(creds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel addOAuthClient(String name) {
|
||||
getDelegateForUpdate();
|
||||
OAuthClientModel client = updated.addOAuthClient(name);
|
||||
cacheSession.registerOAuthClientInvalidation(client.getId());
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel addOAuthClient(String id, String name) {
|
||||
getDelegateForUpdate();
|
||||
OAuthClientModel client = updated.addOAuthClient(id, name);
|
||||
cacheSession.registerOAuthClientInvalidation(client.getId());
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClient(String name) {
|
||||
if (updated != null) return updated.getOAuthClient(name);
|
||||
String id = cached.getClients().get(name);
|
||||
if (id == null) return null;
|
||||
return getOAuthClientById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClientById(String id) {
|
||||
if (updated != null) return updated.getOAuthClientById(id);
|
||||
return cacheSession.getOAuthClientById(id, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeOAuthClient(String id) {
|
||||
cacheSession.registerOAuthClientInvalidation(id);
|
||||
getDelegateForUpdate();
|
||||
return updated.removeOAuthClient(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OAuthClientModel> getOAuthClients() {
|
||||
if (updated != null) return updated.getOAuthClients();
|
||||
List<OAuthClientModel> clients = new LinkedList<OAuthClientModel>();
|
||||
for (String id : cached.getClients().values()) {
|
||||
OAuthClientModel model = cacheSession.getOAuthClientById(id, this);
|
||||
if (model == null) {
|
||||
throw new IllegalStateException("Cached oauth client not found: " + id);
|
||||
}
|
||||
clients.add(model);
|
||||
}
|
||||
return clients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getBrowserSecurityHeaders() {
|
||||
if (updated != null) return updated.getBrowserSecurityHeaders();
|
||||
@@ -821,14 +751,14 @@ public class RealmAdapter implements RealmModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getMasterAdminApp() {
|
||||
return cacheSession.getRealm(Config.getAdminRealm()).getApplicationById(cached.getMasterAdminApp());
|
||||
public ClientModel getMasterAdminClient() {
|
||||
return cacheSession.getRealm(Config.getAdminRealm()).getClientById(cached.getMasterAdminApp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMasterAdminApp(ApplicationModel app) {
|
||||
public void setMasterAdminClient(ClientModel client) {
|
||||
getDelegateForUpdate();
|
||||
updated.setMasterAdminApp(app);
|
||||
updated.setMasterAdminClient(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -875,13 +805,6 @@ public class RealmAdapter implements RealmModel {
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientModel findClientById(String id) {
|
||||
ClientModel model = getApplicationById(id);
|
||||
if (model != null) return model;
|
||||
return getOAuthClientById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentityFederationEnabled() {
|
||||
if (updated != null) return updated.isIdentityFederationEnabled();
|
||||
|
||||
Vendored
-10
@@ -1,7 +1,6 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.models.cache.entities.CachedApplication;
|
||||
import org.keycloak.models.cache.entities.CachedOAuthClient;
|
||||
import org.keycloak.models.cache.entities.CachedRealm;
|
||||
import org.keycloak.models.cache.entities.CachedRole;
|
||||
|
||||
@@ -30,14 +29,6 @@ public interface RealmCache {
|
||||
|
||||
void invalidateCachedApplicationById(String id);
|
||||
|
||||
CachedOAuthClient getOAuthClient(String id);
|
||||
|
||||
void invalidateOAuthClient(CachedOAuthClient client);
|
||||
|
||||
void addCachedOAuthClient(CachedOAuthClient client);
|
||||
|
||||
void invalidateCachedOAuthClientById(String id);
|
||||
|
||||
CachedRole getRole(String id);
|
||||
|
||||
void invalidateRole(CachedRole role);
|
||||
@@ -46,7 +37,6 @@ public interface RealmCache {
|
||||
|
||||
void invalidateCachedRoleById(String id);
|
||||
|
||||
|
||||
void invalidateRoleById(String id);
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
Vendored
+1
-1
@@ -107,7 +107,7 @@ public class RoleAdapter implements RoleModel {
|
||||
return realm;
|
||||
} else {
|
||||
CachedApplicationRole appRole = (CachedApplicationRole)cached;
|
||||
return realm.getApplicationById(appRole.getAppId());
|
||||
return realm.getClientById(appRole.getAppId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+5
-5
@@ -1,6 +1,6 @@
|
||||
package org.keycloak.models.cache;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
@@ -219,14 +219,14 @@ public class UserAdapter implements UserModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationRoleMappings(ApplicationModel app) {
|
||||
if (updated != null) return updated.getApplicationRoleMappings(app);
|
||||
public Set<RoleModel> getClientRoleMappings(ClientModel app) {
|
||||
if (updated != null) return updated.getClientRoleMappings(app);
|
||||
Set<RoleModel> roleMappings = getRoleMappings();
|
||||
Set<RoleModel> appMappings = new HashSet<RoleModel>();
|
||||
for (RoleModel role : roleMappings) {
|
||||
RoleContainerModel container = role.getContainer();
|
||||
if (container instanceof ApplicationModel) {
|
||||
if (((ApplicationModel) container).getId().equals(app.getId())) {
|
||||
if (container instanceof ClientModel) {
|
||||
if (((ClientModel) container).getId().equals(app.getId())) {
|
||||
appMappings.add(role);
|
||||
}
|
||||
}
|
||||
|
||||
+139
-4
@@ -1,38 +1,82 @@
|
||||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.cache.RealmCache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class CachedApplication extends CachedClient {
|
||||
public class CachedApplication {
|
||||
private String id;
|
||||
private String name;
|
||||
private String realm;
|
||||
private Set<String> redirectUris = new HashSet<String>();
|
||||
private boolean enabled;
|
||||
private String secret;
|
||||
private String protocol;
|
||||
private Map<String, String> attributes = new HashMap<String, String>();
|
||||
private boolean publicClient;
|
||||
private boolean fullScopeAllowed;
|
||||
private boolean directGrantsOnly;
|
||||
private boolean frontchannelLogout;
|
||||
private int notBefore;
|
||||
private Set<String> scope = new HashSet<String>();
|
||||
private Set<String> webOrigins = new HashSet<String>();
|
||||
private List<ClientIdentityProviderMappingModel> identityProviders = new ArrayList<ClientIdentityProviderMappingModel>();
|
||||
private Set<ProtocolMapperModel> protocolMappers = new HashSet<ProtocolMapperModel>();
|
||||
private boolean surrogateAuthRequired;
|
||||
private String managementUrl;
|
||||
private String baseUrl;
|
||||
private List<String> defaultRoles = new LinkedList<String>();
|
||||
private boolean bearerOnly;
|
||||
private boolean consentRequired;
|
||||
private Map<String, String> roles = new HashMap<String, String>();
|
||||
private int nodeReRegistrationTimeout;
|
||||
private Map<String, Integer> registeredNodes;
|
||||
|
||||
public CachedApplication(RealmCache cache, RealmProvider delegate, RealmModel realm, ApplicationModel model) {
|
||||
super(cache, delegate, realm, model);
|
||||
public CachedApplication(RealmCache cache, RealmProvider delegate, RealmModel realm, ClientModel model) {
|
||||
id = model.getId();
|
||||
secret = model.getSecret();
|
||||
name = model.getClientId();
|
||||
this.realm = realm.getId();
|
||||
enabled = model.isEnabled();
|
||||
protocol = model.getProtocol();
|
||||
attributes.putAll(model.getAttributes());
|
||||
notBefore = model.getNotBefore();
|
||||
directGrantsOnly = model.isDirectGrantsOnly();
|
||||
frontchannelLogout = model.isFrontchannelLogout();
|
||||
publicClient = model.isPublicClient();
|
||||
fullScopeAllowed = model.isFullScopeAllowed();
|
||||
redirectUris.addAll(model.getRedirectUris());
|
||||
webOrigins.addAll(model.getWebOrigins());
|
||||
for (RoleModel role : model.getScopeMappings()) {
|
||||
scope.add(role.getId());
|
||||
}
|
||||
this.identityProviders = model.getIdentityProviders();
|
||||
for (ProtocolMapperModel mapper : model.getProtocolMappers()) {
|
||||
this.protocolMappers.add(mapper);
|
||||
}
|
||||
surrogateAuthRequired = model.isSurrogateAuthRequired();
|
||||
managementUrl = model.getManagementUrl();
|
||||
baseUrl = model.getBaseUrl();
|
||||
defaultRoles.addAll(model.getDefaultRoles());
|
||||
bearerOnly = model.isBearerOnly();
|
||||
consentRequired = model.isConsentRequired();
|
||||
for (RoleModel role : model.getRoles()) {
|
||||
roles.put(role.getName(), role.getId());
|
||||
cache.addCachedRole(new CachedApplicationRole(id, role, realm));
|
||||
@@ -41,6 +85,93 @@ public class CachedApplication extends CachedClient {
|
||||
nodeReRegistrationTimeout = model.getNodeReRegistrationTimeout();
|
||||
registeredNodes = new TreeMap<String, Integer>(model.getRegisteredNodes());
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRealm() {
|
||||
return realm;
|
||||
}
|
||||
|
||||
public Set<String> getRedirectUris() {
|
||||
return redirectUris;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public boolean isPublicClient() {
|
||||
return publicClient;
|
||||
}
|
||||
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return directGrantsOnly;
|
||||
}
|
||||
|
||||
public int getNotBefore() {
|
||||
return notBefore;
|
||||
}
|
||||
|
||||
public Set<String> getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public Set<String> getWebOrigins() {
|
||||
return webOrigins;
|
||||
}
|
||||
|
||||
public boolean isFullScopeAllowed() {
|
||||
return fullScopeAllowed;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public boolean isFrontchannelLogout() {
|
||||
return frontchannelLogout;
|
||||
}
|
||||
|
||||
public List<ClientIdentityProviderMappingModel> getIdentityProviders() {
|
||||
return this.identityProviders;
|
||||
}
|
||||
|
||||
public boolean hasIdentityProvider(String providerId) {
|
||||
for (ClientIdentityProviderMappingModel model : getIdentityProviders()) {
|
||||
if (model.getIdentityProvider().equals(providerId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<ProtocolMapperModel> getProtocolMappers() {
|
||||
return protocolMappers;
|
||||
}
|
||||
|
||||
public boolean isAllowedRetrieveTokenFromIdentityProvider(String providerId) {
|
||||
for (ClientIdentityProviderMappingModel model : getIdentityProviders()) {
|
||||
if (model.getIdentityProvider().equals(providerId)) {
|
||||
return model.isRetrieveToken();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return surrogateAuthRequired;
|
||||
@@ -62,6 +193,10 @@ public class CachedApplication extends CachedClient {
|
||||
return bearerOnly;
|
||||
}
|
||||
|
||||
public boolean isConsentRequired() {
|
||||
return consentRequired;
|
||||
}
|
||||
|
||||
public Map<String, String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
-152
@@ -1,152 +0,0 @@
|
||||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.cache.RealmCache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class CachedClient {
|
||||
protected String id;
|
||||
protected String name;
|
||||
protected String realm;
|
||||
protected Set<String> redirectUris = new HashSet<String>();
|
||||
protected boolean enabled;
|
||||
protected String secret;
|
||||
protected String protocol;
|
||||
protected Map<String, String> attributes = new HashMap<String, String>();
|
||||
protected boolean publicClient;
|
||||
protected boolean fullScopeAllowed;
|
||||
protected boolean directGrantsOnly;
|
||||
protected boolean frontchannelLogout;
|
||||
protected int notBefore;
|
||||
protected Set<String> scope = new HashSet<String>();
|
||||
protected Set<String> webOrigins = new HashSet<String>();
|
||||
private List<ClientIdentityProviderMappingModel> identityProviders = new ArrayList<ClientIdentityProviderMappingModel>();
|
||||
private Set<ProtocolMapperModel> protocolMappers = new HashSet<ProtocolMapperModel>();
|
||||
|
||||
public CachedClient(RealmCache cache, RealmProvider delegate, RealmModel realm, ClientModel model) {
|
||||
id = model.getId();
|
||||
secret = model.getSecret();
|
||||
name = model.getClientId();
|
||||
this.realm = realm.getId();
|
||||
enabled = model.isEnabled();
|
||||
protocol = model.getProtocol();
|
||||
attributes.putAll(model.getAttributes());
|
||||
notBefore = model.getNotBefore();
|
||||
directGrantsOnly = model.isDirectGrantsOnly();
|
||||
frontchannelLogout = model.isFrontchannelLogout();
|
||||
publicClient = model.isPublicClient();
|
||||
fullScopeAllowed = model.isFullScopeAllowed();
|
||||
redirectUris.addAll(model.getRedirectUris());
|
||||
webOrigins.addAll(model.getWebOrigins());
|
||||
for (RoleModel role : model.getScopeMappings()) {
|
||||
scope.add(role.getId());
|
||||
}
|
||||
this.identityProviders = model.getIdentityProviders();
|
||||
for (ProtocolMapperModel mapper : model.getProtocolMappers()) {
|
||||
this.protocolMappers.add(mapper);
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRealm() {
|
||||
return realm;
|
||||
}
|
||||
|
||||
public Set<String> getRedirectUris() {
|
||||
return redirectUris;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public boolean isPublicClient() {
|
||||
return publicClient;
|
||||
}
|
||||
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return directGrantsOnly;
|
||||
}
|
||||
|
||||
public int getNotBefore() {
|
||||
return notBefore;
|
||||
}
|
||||
|
||||
public Set<String> getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public Set<String> getWebOrigins() {
|
||||
return webOrigins;
|
||||
}
|
||||
|
||||
public boolean isFullScopeAllowed() {
|
||||
return fullScopeAllowed;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public boolean isFrontchannelLogout() {
|
||||
return frontchannelLogout;
|
||||
}
|
||||
|
||||
public List<ClientIdentityProviderMappingModel> getIdentityProviders() {
|
||||
return this.identityProviders;
|
||||
}
|
||||
|
||||
public boolean hasIdentityProvider(String providerId) {
|
||||
for (ClientIdentityProviderMappingModel model : getIdentityProviders()) {
|
||||
if (model.getIdentityProvider().equals(providerId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<ProtocolMapperModel> getProtocolMappers() {
|
||||
return protocolMappers;
|
||||
}
|
||||
|
||||
public boolean isAllowedRetrieveTokenFromIdentityProvider(String providerId) {
|
||||
for (ClientIdentityProviderMappingModel model : getIdentityProviders()) {
|
||||
if (model.getIdentityProvider().equals(providerId)) {
|
||||
return model.isRetrieveToken();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.cache.RealmCache;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class CachedOAuthClient extends CachedClient {
|
||||
public CachedOAuthClient(RealmCache cache, RealmProvider delegate, RealmModel realm, OAuthClientModel model) {
|
||||
super(cache, delegate, realm, model);
|
||||
|
||||
}
|
||||
}
|
||||
+385
-392
@@ -1,392 +1,385 @@
|
||||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.enums.SslRequired;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.IdentityProviderMapperModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.cache.RealmCache;
|
||||
import org.keycloak.util.MultivaluedHashMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class CachedRealm {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
private SslRequired sslRequired;
|
||||
private boolean registrationAllowed;
|
||||
private boolean registrationEmailAsUsername;
|
||||
private boolean rememberMe;
|
||||
private boolean verifyEmail;
|
||||
private boolean passwordCredentialGrantAllowed;
|
||||
private boolean resetPasswordAllowed;
|
||||
private boolean identityFederationEnabled;
|
||||
//--- brute force settings
|
||||
private boolean bruteForceProtected;
|
||||
private int maxFailureWaitSeconds;
|
||||
private int minimumQuickLoginWaitSeconds;
|
||||
private int waitIncrementSeconds;
|
||||
private long quickLoginCheckMilliSeconds;
|
||||
private int maxDeltaTimeSeconds;
|
||||
private int failureFactor;
|
||||
//--- end brute force settings
|
||||
|
||||
private int ssoSessionIdleTimeout;
|
||||
private int ssoSessionMaxLifespan;
|
||||
private int accessTokenLifespan;
|
||||
private int accessCodeLifespan;
|
||||
private int accessCodeLifespanUserAction;
|
||||
private int accessCodeLifespanLogin;
|
||||
private int notBefore;
|
||||
private PasswordPolicy passwordPolicy;
|
||||
|
||||
private String publicKeyPem;
|
||||
private String privateKeyPem;
|
||||
private String certificatePem;
|
||||
private String codeSecret;
|
||||
|
||||
private String loginTheme;
|
||||
private String accountTheme;
|
||||
private String adminTheme;
|
||||
private String emailTheme;
|
||||
private String masterAdminApp;
|
||||
|
||||
private List<RequiredCredentialModel> requiredCredentials = new ArrayList<RequiredCredentialModel>();
|
||||
private List<UserFederationProviderModel> userFederationProviders = new ArrayList<UserFederationProviderModel>();
|
||||
private List<IdentityProviderModel> identityProviders = new ArrayList<IdentityProviderModel>();
|
||||
|
||||
private Map<String, String> browserSecurityHeaders = new HashMap<String, String>();
|
||||
private Map<String, String> smtpConfig = new HashMap<String, String>();
|
||||
|
||||
private boolean eventsEnabled;
|
||||
private long eventsExpiration;
|
||||
private Set<String> eventsListeners = new HashSet<String>();
|
||||
private Set<String> enabledEventTypes = new HashSet<String>();
|
||||
private List<String> defaultRoles = new LinkedList<String>();
|
||||
private Map<String, String> realmRoles = new HashMap<String, String>();
|
||||
private Map<String, String> applications = new HashMap<String, String>();
|
||||
private Map<String, String> clients = new HashMap<String, String>();
|
||||
private boolean internationalizationEnabled;
|
||||
private Set<String> supportedLocales = new HashSet<String>();
|
||||
private String defaultLocale;
|
||||
private MultivaluedHashMap<String, IdentityProviderMapperModel> identityProviderMappers = new MultivaluedHashMap<>();
|
||||
|
||||
public CachedRealm() {
|
||||
}
|
||||
|
||||
public CachedRealm(RealmCache cache, RealmProvider delegate, RealmModel model) {
|
||||
id = model.getId();
|
||||
name = model.getName();
|
||||
enabled = model.isEnabled();
|
||||
sslRequired = model.getSslRequired();
|
||||
registrationAllowed = model.isRegistrationAllowed();
|
||||
registrationEmailAsUsername = model.isRegistrationEmailAsUsername();
|
||||
rememberMe = model.isRememberMe();
|
||||
verifyEmail = model.isVerifyEmail();
|
||||
passwordCredentialGrantAllowed = model.isPasswordCredentialGrantAllowed();
|
||||
resetPasswordAllowed = model.isResetPasswordAllowed();
|
||||
identityFederationEnabled = model.isIdentityFederationEnabled();
|
||||
//--- brute force settings
|
||||
bruteForceProtected = model.isBruteForceProtected();
|
||||
maxFailureWaitSeconds = model.getMaxFailureWaitSeconds();
|
||||
minimumQuickLoginWaitSeconds = model.getMinimumQuickLoginWaitSeconds();
|
||||
waitIncrementSeconds = model.getWaitIncrementSeconds();
|
||||
quickLoginCheckMilliSeconds = model.getQuickLoginCheckMilliSeconds();
|
||||
maxDeltaTimeSeconds = model.getMaxDeltaTimeSeconds();
|
||||
failureFactor = model.getFailureFactor();
|
||||
//--- end brute force settings
|
||||
|
||||
ssoSessionIdleTimeout = model.getSsoSessionIdleTimeout();
|
||||
ssoSessionMaxLifespan = model.getSsoSessionMaxLifespan();
|
||||
accessTokenLifespan = model.getAccessTokenLifespan();
|
||||
accessCodeLifespan = model.getAccessCodeLifespan();
|
||||
accessCodeLifespanUserAction = model.getAccessCodeLifespanUserAction();
|
||||
accessCodeLifespanLogin = model.getAccessCodeLifespanLogin();
|
||||
notBefore = model.getNotBefore();
|
||||
passwordPolicy = model.getPasswordPolicy();
|
||||
|
||||
publicKeyPem = model.getPublicKeyPem();
|
||||
privateKeyPem = model.getPrivateKeyPem();
|
||||
certificatePem = model.getCertificatePem();
|
||||
codeSecret = model.getCodeSecret();
|
||||
|
||||
loginTheme = model.getLoginTheme();
|
||||
accountTheme = model.getAccountTheme();
|
||||
adminTheme = model.getAdminTheme();
|
||||
emailTheme = model.getEmailTheme();
|
||||
|
||||
requiredCredentials = model.getRequiredCredentials();
|
||||
userFederationProviders = model.getUserFederationProviders();
|
||||
|
||||
this.identityProviders = new ArrayList<>();
|
||||
|
||||
for (IdentityProviderModel identityProviderModel : model.getIdentityProviders()) {
|
||||
this.identityProviders.add(new IdentityProviderModel(identityProviderModel));
|
||||
}
|
||||
|
||||
for (IdentityProviderMapperModel mapper : model.getIdentityProviderMappers()) {
|
||||
identityProviderMappers.add(mapper.getIdentityProviderAlias(), mapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
smtpConfig.putAll(model.getSmtpConfig());
|
||||
browserSecurityHeaders.putAll(model.getBrowserSecurityHeaders());
|
||||
|
||||
eventsEnabled = model.isEventsEnabled();
|
||||
eventsExpiration = model.getEventsExpiration();
|
||||
eventsListeners.addAll(model.getEventsListeners());
|
||||
enabledEventTypes.addAll(model.getEnabledEventTypes());
|
||||
defaultRoles.addAll(model.getDefaultRoles());
|
||||
masterAdminApp = model.getMasterAdminApp().getId();
|
||||
|
||||
for (RoleModel role : model.getRoles()) {
|
||||
realmRoles.put(role.getName(), role.getId());
|
||||
CachedRole cachedRole = new CachedRealmRole(role, model);
|
||||
cache.addCachedRole(cachedRole);
|
||||
}
|
||||
|
||||
for (ApplicationModel app : model.getApplications()) {
|
||||
applications.put(app.getName(), app.getId());
|
||||
CachedApplication cachedApp = new CachedApplication(cache, delegate, model, app);
|
||||
cache.addCachedApplication(cachedApp);
|
||||
}
|
||||
|
||||
for (OAuthClientModel client : model.getOAuthClients()) {
|
||||
clients.put(client.getClientId(), client.getId());
|
||||
CachedOAuthClient cachedApp = new CachedOAuthClient(cache, delegate, model, client);
|
||||
cache.addCachedOAuthClient(cachedApp);
|
||||
}
|
||||
|
||||
internationalizationEnabled = model.isInternationalizationEnabled();
|
||||
supportedLocales.addAll(model.getSupportedLocales());
|
||||
defaultLocale = model.getDefaultLocale();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getMasterAdminApp() {
|
||||
return masterAdminApp;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getDefaultRoles() {
|
||||
return defaultRoles;
|
||||
}
|
||||
|
||||
public Map<String, String> getRealmRoles() {
|
||||
return realmRoles;
|
||||
}
|
||||
|
||||
public Map<String, String> getApplications() {
|
||||
return applications;
|
||||
}
|
||||
|
||||
public Map<String, String> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public SslRequired getSslRequired() {
|
||||
return sslRequired;
|
||||
}
|
||||
|
||||
public boolean isRegistrationAllowed() {
|
||||
return registrationAllowed;
|
||||
}
|
||||
|
||||
public boolean isRegistrationEmailAsUsername() {
|
||||
return registrationEmailAsUsername;
|
||||
}
|
||||
|
||||
public boolean isPasswordCredentialGrantAllowed() {
|
||||
return passwordCredentialGrantAllowed;
|
||||
}
|
||||
|
||||
public boolean isRememberMe() {
|
||||
return this.rememberMe;
|
||||
}
|
||||
|
||||
public boolean isBruteForceProtected() {
|
||||
return bruteForceProtected;
|
||||
}
|
||||
|
||||
public int getMaxFailureWaitSeconds() {
|
||||
return this.maxFailureWaitSeconds;
|
||||
}
|
||||
|
||||
public int getWaitIncrementSeconds() {
|
||||
return this.waitIncrementSeconds;
|
||||
}
|
||||
|
||||
public int getMinimumQuickLoginWaitSeconds() {
|
||||
return this.minimumQuickLoginWaitSeconds;
|
||||
}
|
||||
|
||||
public long getQuickLoginCheckMilliSeconds() {
|
||||
return quickLoginCheckMilliSeconds;
|
||||
}
|
||||
|
||||
public int getMaxDeltaTimeSeconds() {
|
||||
return maxDeltaTimeSeconds;
|
||||
}
|
||||
|
||||
public int getFailureFactor() {
|
||||
return failureFactor;
|
||||
}
|
||||
|
||||
public boolean isVerifyEmail() {
|
||||
return verifyEmail;
|
||||
}
|
||||
|
||||
public boolean isResetPasswordAllowed() {
|
||||
return resetPasswordAllowed;
|
||||
}
|
||||
|
||||
public int getSsoSessionIdleTimeout() {
|
||||
return ssoSessionIdleTimeout;
|
||||
}
|
||||
|
||||
public int getSsoSessionMaxLifespan() {
|
||||
return ssoSessionMaxLifespan;
|
||||
}
|
||||
|
||||
public int getAccessTokenLifespan() {
|
||||
return accessTokenLifespan;
|
||||
}
|
||||
|
||||
public int getAccessCodeLifespan() {
|
||||
return accessCodeLifespan;
|
||||
}
|
||||
|
||||
public int getAccessCodeLifespanUserAction() {
|
||||
return accessCodeLifespanUserAction;
|
||||
}
|
||||
public int getAccessCodeLifespanLogin() {
|
||||
return accessCodeLifespanLogin;
|
||||
}
|
||||
|
||||
public String getPublicKeyPem() {
|
||||
return publicKeyPem;
|
||||
}
|
||||
|
||||
public String getPrivateKeyPem() {
|
||||
return privateKeyPem;
|
||||
}
|
||||
|
||||
public String getCodeSecret() {
|
||||
return codeSecret;
|
||||
}
|
||||
|
||||
public List<RequiredCredentialModel> getRequiredCredentials() {
|
||||
return requiredCredentials;
|
||||
}
|
||||
|
||||
public PasswordPolicy getPasswordPolicy() {
|
||||
return passwordPolicy;
|
||||
}
|
||||
|
||||
public boolean isIdentityFederationEnabled() {
|
||||
return identityFederationEnabled;
|
||||
}
|
||||
|
||||
public Map<String, String> getSmtpConfig() {
|
||||
return smtpConfig;
|
||||
}
|
||||
|
||||
public Map<String, String> getBrowserSecurityHeaders() {
|
||||
return browserSecurityHeaders;
|
||||
}
|
||||
|
||||
public String getLoginTheme() {
|
||||
return loginTheme;
|
||||
}
|
||||
|
||||
public String getAccountTheme() {
|
||||
return accountTheme;
|
||||
}
|
||||
|
||||
public String getAdminTheme() {
|
||||
return this.adminTheme;
|
||||
}
|
||||
|
||||
public String getEmailTheme() {
|
||||
return emailTheme;
|
||||
}
|
||||
|
||||
public int getNotBefore() {
|
||||
return notBefore;
|
||||
}
|
||||
|
||||
public boolean isEventsEnabled() {
|
||||
return eventsEnabled;
|
||||
}
|
||||
|
||||
public long getEventsExpiration() {
|
||||
return eventsExpiration;
|
||||
}
|
||||
|
||||
public Set<String> getEventsListeners() {
|
||||
return eventsListeners;
|
||||
}
|
||||
|
||||
public Set<String> getEnabledEventTypes() {
|
||||
return enabledEventTypes;
|
||||
}
|
||||
|
||||
public List<UserFederationProviderModel> getUserFederationProviders() {
|
||||
return userFederationProviders;
|
||||
}
|
||||
|
||||
public String getCertificatePem() {
|
||||
return certificatePem;
|
||||
}
|
||||
|
||||
public List<IdentityProviderModel> getIdentityProviders() {
|
||||
return identityProviders;
|
||||
}
|
||||
|
||||
public boolean isInternationalizationEnabled() {
|
||||
return internationalizationEnabled;
|
||||
}
|
||||
|
||||
public Set<String> getSupportedLocales() {
|
||||
return supportedLocales;
|
||||
}
|
||||
|
||||
public String getDefaultLocale() {
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
public MultivaluedHashMap<String, IdentityProviderMapperModel> getIdentityProviderMappers() {
|
||||
return identityProviderMappers;
|
||||
}
|
||||
}
|
||||
package org.keycloak.models.cache.entities;
|
||||
|
||||
import org.keycloak.enums.SslRequired;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.IdentityProviderMapperModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserFederationProviderModel;
|
||||
import org.keycloak.models.cache.RealmCache;
|
||||
import org.keycloak.util.MultivaluedHashMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class CachedRealm {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
private SslRequired sslRequired;
|
||||
private boolean registrationAllowed;
|
||||
private boolean registrationEmailAsUsername;
|
||||
private boolean rememberMe;
|
||||
private boolean verifyEmail;
|
||||
private boolean passwordCredentialGrantAllowed;
|
||||
private boolean resetPasswordAllowed;
|
||||
private boolean identityFederationEnabled;
|
||||
//--- brute force settings
|
||||
private boolean bruteForceProtected;
|
||||
private int maxFailureWaitSeconds;
|
||||
private int minimumQuickLoginWaitSeconds;
|
||||
private int waitIncrementSeconds;
|
||||
private long quickLoginCheckMilliSeconds;
|
||||
private int maxDeltaTimeSeconds;
|
||||
private int failureFactor;
|
||||
//--- end brute force settings
|
||||
|
||||
private int ssoSessionIdleTimeout;
|
||||
private int ssoSessionMaxLifespan;
|
||||
private int accessTokenLifespan;
|
||||
private int accessCodeLifespan;
|
||||
private int accessCodeLifespanUserAction;
|
||||
private int accessCodeLifespanLogin;
|
||||
private int notBefore;
|
||||
private PasswordPolicy passwordPolicy;
|
||||
|
||||
private String publicKeyPem;
|
||||
private String privateKeyPem;
|
||||
private String certificatePem;
|
||||
private String codeSecret;
|
||||
|
||||
private String loginTheme;
|
||||
private String accountTheme;
|
||||
private String adminTheme;
|
||||
private String emailTheme;
|
||||
private String masterAdminApp;
|
||||
|
||||
private List<RequiredCredentialModel> requiredCredentials = new ArrayList<RequiredCredentialModel>();
|
||||
private List<UserFederationProviderModel> userFederationProviders = new ArrayList<UserFederationProviderModel>();
|
||||
private List<IdentityProviderModel> identityProviders = new ArrayList<IdentityProviderModel>();
|
||||
|
||||
private Map<String, String> browserSecurityHeaders = new HashMap<String, String>();
|
||||
private Map<String, String> smtpConfig = new HashMap<String, String>();
|
||||
|
||||
private boolean eventsEnabled;
|
||||
private long eventsExpiration;
|
||||
private Set<String> eventsListeners = new HashSet<String>();
|
||||
private Set<String> enabledEventTypes = new HashSet<String>();
|
||||
private List<String> defaultRoles = new LinkedList<String>();
|
||||
private Map<String, String> realmRoles = new HashMap<String, String>();
|
||||
private Map<String, String> applications = new HashMap<String, String>();
|
||||
private Map<String, String> clients = new HashMap<String, String>();
|
||||
private boolean internationalizationEnabled;
|
||||
private Set<String> supportedLocales = new HashSet<String>();
|
||||
private String defaultLocale;
|
||||
private MultivaluedHashMap<String, IdentityProviderMapperModel> identityProviderMappers = new MultivaluedHashMap<>();
|
||||
|
||||
public CachedRealm() {
|
||||
}
|
||||
|
||||
public CachedRealm(RealmCache cache, RealmProvider delegate, RealmModel model) {
|
||||
id = model.getId();
|
||||
name = model.getName();
|
||||
enabled = model.isEnabled();
|
||||
sslRequired = model.getSslRequired();
|
||||
registrationAllowed = model.isRegistrationAllowed();
|
||||
registrationEmailAsUsername = model.isRegistrationEmailAsUsername();
|
||||
rememberMe = model.isRememberMe();
|
||||
verifyEmail = model.isVerifyEmail();
|
||||
passwordCredentialGrantAllowed = model.isPasswordCredentialGrantAllowed();
|
||||
resetPasswordAllowed = model.isResetPasswordAllowed();
|
||||
identityFederationEnabled = model.isIdentityFederationEnabled();
|
||||
//--- brute force settings
|
||||
bruteForceProtected = model.isBruteForceProtected();
|
||||
maxFailureWaitSeconds = model.getMaxFailureWaitSeconds();
|
||||
minimumQuickLoginWaitSeconds = model.getMinimumQuickLoginWaitSeconds();
|
||||
waitIncrementSeconds = model.getWaitIncrementSeconds();
|
||||
quickLoginCheckMilliSeconds = model.getQuickLoginCheckMilliSeconds();
|
||||
maxDeltaTimeSeconds = model.getMaxDeltaTimeSeconds();
|
||||
failureFactor = model.getFailureFactor();
|
||||
//--- end brute force settings
|
||||
|
||||
ssoSessionIdleTimeout = model.getSsoSessionIdleTimeout();
|
||||
ssoSessionMaxLifespan = model.getSsoSessionMaxLifespan();
|
||||
accessTokenLifespan = model.getAccessTokenLifespan();
|
||||
accessCodeLifespan = model.getAccessCodeLifespan();
|
||||
accessCodeLifespanUserAction = model.getAccessCodeLifespanUserAction();
|
||||
accessCodeLifespanLogin = model.getAccessCodeLifespanLogin();
|
||||
notBefore = model.getNotBefore();
|
||||
passwordPolicy = model.getPasswordPolicy();
|
||||
|
||||
publicKeyPem = model.getPublicKeyPem();
|
||||
privateKeyPem = model.getPrivateKeyPem();
|
||||
certificatePem = model.getCertificatePem();
|
||||
codeSecret = model.getCodeSecret();
|
||||
|
||||
loginTheme = model.getLoginTheme();
|
||||
accountTheme = model.getAccountTheme();
|
||||
adminTheme = model.getAdminTheme();
|
||||
emailTheme = model.getEmailTheme();
|
||||
|
||||
requiredCredentials = model.getRequiredCredentials();
|
||||
userFederationProviders = model.getUserFederationProviders();
|
||||
|
||||
this.identityProviders = new ArrayList<>();
|
||||
|
||||
for (IdentityProviderModel identityProviderModel : model.getIdentityProviders()) {
|
||||
this.identityProviders.add(new IdentityProviderModel(identityProviderModel));
|
||||
}
|
||||
|
||||
for (IdentityProviderMapperModel mapper : model.getIdentityProviderMappers()) {
|
||||
identityProviderMappers.add(mapper.getIdentityProviderAlias(), mapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
smtpConfig.putAll(model.getSmtpConfig());
|
||||
browserSecurityHeaders.putAll(model.getBrowserSecurityHeaders());
|
||||
|
||||
eventsEnabled = model.isEventsEnabled();
|
||||
eventsExpiration = model.getEventsExpiration();
|
||||
eventsListeners.addAll(model.getEventsListeners());
|
||||
enabledEventTypes.addAll(model.getEnabledEventTypes());
|
||||
defaultRoles.addAll(model.getDefaultRoles());
|
||||
masterAdminApp = model.getMasterAdminClient().getId();
|
||||
|
||||
for (RoleModel role : model.getRoles()) {
|
||||
realmRoles.put(role.getName(), role.getId());
|
||||
CachedRole cachedRole = new CachedRealmRole(role, model);
|
||||
cache.addCachedRole(cachedRole);
|
||||
}
|
||||
|
||||
for (ClientModel app : model.getClients()) {
|
||||
applications.put(app.getClientId(), app.getId());
|
||||
CachedApplication cachedApp = new CachedApplication(cache, delegate, model, app);
|
||||
cache.addCachedApplication(cachedApp);
|
||||
}
|
||||
|
||||
internationalizationEnabled = model.isInternationalizationEnabled();
|
||||
supportedLocales.addAll(model.getSupportedLocales());
|
||||
defaultLocale = model.getDefaultLocale();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getMasterAdminApp() {
|
||||
return masterAdminApp;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getDefaultRoles() {
|
||||
return defaultRoles;
|
||||
}
|
||||
|
||||
public Map<String, String> getRealmRoles() {
|
||||
return realmRoles;
|
||||
}
|
||||
|
||||
public Map<String, String> getApplications() {
|
||||
return applications;
|
||||
}
|
||||
|
||||
public Map<String, String> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public SslRequired getSslRequired() {
|
||||
return sslRequired;
|
||||
}
|
||||
|
||||
public boolean isRegistrationAllowed() {
|
||||
return registrationAllowed;
|
||||
}
|
||||
|
||||
public boolean isRegistrationEmailAsUsername() {
|
||||
return registrationEmailAsUsername;
|
||||
}
|
||||
|
||||
public boolean isPasswordCredentialGrantAllowed() {
|
||||
return passwordCredentialGrantAllowed;
|
||||
}
|
||||
|
||||
public boolean isRememberMe() {
|
||||
return this.rememberMe;
|
||||
}
|
||||
|
||||
public boolean isBruteForceProtected() {
|
||||
return bruteForceProtected;
|
||||
}
|
||||
|
||||
public int getMaxFailureWaitSeconds() {
|
||||
return this.maxFailureWaitSeconds;
|
||||
}
|
||||
|
||||
public int getWaitIncrementSeconds() {
|
||||
return this.waitIncrementSeconds;
|
||||
}
|
||||
|
||||
public int getMinimumQuickLoginWaitSeconds() {
|
||||
return this.minimumQuickLoginWaitSeconds;
|
||||
}
|
||||
|
||||
public long getQuickLoginCheckMilliSeconds() {
|
||||
return quickLoginCheckMilliSeconds;
|
||||
}
|
||||
|
||||
public int getMaxDeltaTimeSeconds() {
|
||||
return maxDeltaTimeSeconds;
|
||||
}
|
||||
|
||||
public int getFailureFactor() {
|
||||
return failureFactor;
|
||||
}
|
||||
|
||||
public boolean isVerifyEmail() {
|
||||
return verifyEmail;
|
||||
}
|
||||
|
||||
public boolean isResetPasswordAllowed() {
|
||||
return resetPasswordAllowed;
|
||||
}
|
||||
|
||||
public int getSsoSessionIdleTimeout() {
|
||||
return ssoSessionIdleTimeout;
|
||||
}
|
||||
|
||||
public int getSsoSessionMaxLifespan() {
|
||||
return ssoSessionMaxLifespan;
|
||||
}
|
||||
|
||||
public int getAccessTokenLifespan() {
|
||||
return accessTokenLifespan;
|
||||
}
|
||||
|
||||
public int getAccessCodeLifespan() {
|
||||
return accessCodeLifespan;
|
||||
}
|
||||
|
||||
public int getAccessCodeLifespanUserAction() {
|
||||
return accessCodeLifespanUserAction;
|
||||
}
|
||||
public int getAccessCodeLifespanLogin() {
|
||||
return accessCodeLifespanLogin;
|
||||
}
|
||||
|
||||
public String getPublicKeyPem() {
|
||||
return publicKeyPem;
|
||||
}
|
||||
|
||||
public String getPrivateKeyPem() {
|
||||
return privateKeyPem;
|
||||
}
|
||||
|
||||
public String getCodeSecret() {
|
||||
return codeSecret;
|
||||
}
|
||||
|
||||
public List<RequiredCredentialModel> getRequiredCredentials() {
|
||||
return requiredCredentials;
|
||||
}
|
||||
|
||||
public PasswordPolicy getPasswordPolicy() {
|
||||
return passwordPolicy;
|
||||
}
|
||||
|
||||
public boolean isIdentityFederationEnabled() {
|
||||
return identityFederationEnabled;
|
||||
}
|
||||
|
||||
public Map<String, String> getSmtpConfig() {
|
||||
return smtpConfig;
|
||||
}
|
||||
|
||||
public Map<String, String> getBrowserSecurityHeaders() {
|
||||
return browserSecurityHeaders;
|
||||
}
|
||||
|
||||
public String getLoginTheme() {
|
||||
return loginTheme;
|
||||
}
|
||||
|
||||
public String getAccountTheme() {
|
||||
return accountTheme;
|
||||
}
|
||||
|
||||
public String getAdminTheme() {
|
||||
return this.adminTheme;
|
||||
}
|
||||
|
||||
public String getEmailTheme() {
|
||||
return emailTheme;
|
||||
}
|
||||
|
||||
public int getNotBefore() {
|
||||
return notBefore;
|
||||
}
|
||||
|
||||
public boolean isEventsEnabled() {
|
||||
return eventsEnabled;
|
||||
}
|
||||
|
||||
public long getEventsExpiration() {
|
||||
return eventsExpiration;
|
||||
}
|
||||
|
||||
public Set<String> getEventsListeners() {
|
||||
return eventsListeners;
|
||||
}
|
||||
|
||||
public Set<String> getEnabledEventTypes() {
|
||||
return enabledEventTypes;
|
||||
}
|
||||
|
||||
public List<UserFederationProviderModel> getUserFederationProviders() {
|
||||
return userFederationProviders;
|
||||
}
|
||||
|
||||
public String getCertificatePem() {
|
||||
return certificatePem;
|
||||
}
|
||||
|
||||
public List<IdentityProviderModel> getIdentityProviders() {
|
||||
return identityProviders;
|
||||
}
|
||||
|
||||
public boolean isInternationalizationEnabled() {
|
||||
return internationalizationEnabled;
|
||||
}
|
||||
|
||||
public Set<String> getSupportedLocales() {
|
||||
return supportedLocales;
|
||||
}
|
||||
|
||||
public String getDefaultLocale() {
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
public MultivaluedHashMap<String, IdentityProviderMapperModel> getIdentityProviderMappers() {
|
||||
return identityProviderMappers;
|
||||
}
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
package org.keycloak.models.jpa;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.jpa.entities.ApplicationEntity;
|
||||
import org.keycloak.models.jpa.entities.IdentityProviderEntity;
|
||||
import org.keycloak.models.jpa.entities.RoleEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.TypedQuery;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class ApplicationAdapter extends ClientAdapter implements ApplicationModel {
|
||||
|
||||
protected EntityManager em;
|
||||
protected KeycloakSession session;
|
||||
protected ApplicationEntity applicationEntity;
|
||||
|
||||
public ApplicationAdapter(RealmModel realm, EntityManager em, KeycloakSession session, ApplicationEntity applicationEntity) {
|
||||
super(realm, applicationEntity, em);
|
||||
this.session = session;
|
||||
this.realm = realm;
|
||||
this.em = em;
|
||||
this.applicationEntity = applicationEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateApplication() {
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return entity.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
entity.setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return applicationEntity.isSurrogateAuthRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
applicationEntity.setSurrogateAuthRequired(surrogateAuthRequired);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getManagementUrl() {
|
||||
return applicationEntity.getManagementUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManagementUrl(String url) {
|
||||
applicationEntity.setManagementUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseUrl() {
|
||||
return applicationEntity.getBaseUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseUrl(String url) {
|
||||
applicationEntity.setBaseUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBearerOnly() {
|
||||
return applicationEntity.isBearerOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearerOnly(boolean only) {
|
||||
applicationEntity.setBearerOnly(only);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return false; // applications can't be grant only
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectGrantsOnly(boolean flag) {
|
||||
// applications can't be grant only
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel getRole(String name) {
|
||||
TypedQuery<RoleEntity> query = em.createNamedQuery("getAppRoleByName", RoleEntity.class);
|
||||
query.setParameter("name", name);
|
||||
query.setParameter("application", entity);
|
||||
List<RoleEntity> roles = query.getResultList();
|
||||
if (roles.size() == 0) return null;
|
||||
return new RoleAdapter(realm, em, roles.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel addRole(String name) {
|
||||
return this.addRole(KeycloakModelUtils.generateId(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel addRole(String id, String name) {
|
||||
RoleEntity roleEntity = new RoleEntity();
|
||||
roleEntity.setId(id);
|
||||
roleEntity.setName(name);
|
||||
roleEntity.setApplication(applicationEntity);
|
||||
roleEntity.setApplicationRole(true);
|
||||
roleEntity.setRealmId(realm.getId());
|
||||
em.persist(roleEntity);
|
||||
applicationEntity.getRoles().add(roleEntity);
|
||||
em.flush();
|
||||
return new RoleAdapter(realm, em, roleEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(RoleModel roleModel) {
|
||||
if (roleModel == null) {
|
||||
return false;
|
||||
}
|
||||
if (!roleModel.getContainer().equals(this)) return false;
|
||||
|
||||
session.users().preRemove(getRealm(), roleModel);
|
||||
RoleEntity role = RoleAdapter.toRoleEntity(roleModel, em);
|
||||
if (!role.isApplicationRole()) return false;
|
||||
|
||||
|
||||
applicationEntity.getRoles().remove(role);
|
||||
applicationEntity.getDefaultRoles().remove(role);
|
||||
em.createNativeQuery("delete from COMPOSITE_ROLE where CHILD_ROLE = :role").setParameter("role", role).executeUpdate();
|
||||
em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", role).executeUpdate();
|
||||
role.setApplication(null);
|
||||
em.flush();
|
||||
em.remove(role);
|
||||
em.flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getRoles() {
|
||||
Set<RoleModel> list = new HashSet<RoleModel>();
|
||||
Collection<RoleEntity> roles = applicationEntity.getRoles();
|
||||
if (roles == null) return list;
|
||||
for (RoleEntity entity : roles) {
|
||||
list.add(new RoleAdapter(realm, em, entity));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScope(RoleModel role) {
|
||||
if (super.hasScope(role)) {
|
||||
return true;
|
||||
}
|
||||
Set<RoleModel> roles = getRoles();
|
||||
if (roles.contains(role)) return true;
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationScopeMappings(ClientModel client) {
|
||||
Set<RoleModel> roleMappings = client.getScopeMappings();
|
||||
|
||||
Set<RoleModel> appRoles = new HashSet<RoleModel>();
|
||||
for (RoleModel role : roleMappings) {
|
||||
RoleContainerModel container = role.getContainer();
|
||||
if (container instanceof RealmModel) {
|
||||
} else {
|
||||
ApplicationModel app = (ApplicationModel)container;
|
||||
if (app.getId().equals(getId())) {
|
||||
appRoles.add(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appRoles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getDefaultRoles() {
|
||||
Collection<RoleEntity> entities = applicationEntity.getDefaultRoles();
|
||||
List<String> roles = new ArrayList<String>();
|
||||
if (entities == null) return roles;
|
||||
for (RoleEntity entity : entities) {
|
||||
roles.add(entity.getName());
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultRole(String name) {
|
||||
RoleModel role = getRole(name);
|
||||
if (role == null) {
|
||||
role = addRole(name);
|
||||
}
|
||||
Collection<RoleEntity> entities = applicationEntity.getDefaultRoles();
|
||||
for (RoleEntity entity : entities) {
|
||||
if (entity.getId().equals(role.getId())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
RoleEntity roleEntity = RoleAdapter.toRoleEntity(role, em);
|
||||
entities.add(roleEntity);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDefaultRoles(String[] defaultRoles) {
|
||||
Collection<RoleEntity> entities = applicationEntity.getDefaultRoles();
|
||||
Set<String> already = new HashSet<String>();
|
||||
List<RoleEntity> remove = new ArrayList<RoleEntity>();
|
||||
for (RoleEntity rel : entities) {
|
||||
if (!contains(rel.getName(), defaultRoles)) {
|
||||
remove.add(rel);
|
||||
} else {
|
||||
already.add(rel.getName());
|
||||
}
|
||||
}
|
||||
for (RoleEntity entity : remove) {
|
||||
entities.remove(entity);
|
||||
}
|
||||
em.flush();
|
||||
for (String roleName : defaultRoles) {
|
||||
if (!already.contains(roleName)) {
|
||||
addDefaultRole(roleName);
|
||||
}
|
||||
}
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
return applicationEntity.getNodeReRegistrationTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNodeReRegistrationTimeout(int timeout) {
|
||||
applicationEntity.setNodeReRegistrationTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
return applicationEntity.getRegisteredNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNode(String nodeHost, int registrationTime) {
|
||||
Map<String, Integer> currentNodes = getRegisteredNodes();
|
||||
currentNodes.put(nodeHost, registrationTime);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterNode(String nodeHost) {
|
||||
Map<String, Integer> currentNodes = getRegisteredNodes();
|
||||
currentNodes.remove(nodeHost);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof ApplicationModel)) return false;
|
||||
|
||||
ApplicationModel that = (ApplicationModel) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
ApplicationEntity getJpaEntity() {
|
||||
return applicationEntity;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package org.keycloak.models.jpa;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
@@ -22,8 +21,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -32,15 +29,18 @@ import java.util.Set;
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public abstract class ClientAdapter implements ClientModel {
|
||||
protected ClientEntity entity;
|
||||
public class ClientAdapter implements ClientModel {
|
||||
|
||||
protected KeycloakSession session;
|
||||
protected RealmModel realm;
|
||||
protected EntityManager em;
|
||||
protected ClientEntity entity;
|
||||
|
||||
public ClientAdapter(RealmModel realm, ClientEntity entity, EntityManager em) {
|
||||
public ClientAdapter(RealmModel realm, EntityManager em, KeycloakSession session, ClientEntity entity) {
|
||||
this.session = session;
|
||||
this.realm = realm;
|
||||
this.entity = entity;
|
||||
this.em = em;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public ClientEntity getEntity() {
|
||||
@@ -57,11 +57,6 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
return realm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientId() {
|
||||
return entity.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return entity.isEnabled();
|
||||
@@ -177,7 +172,7 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
public Set<RoleModel> getRealmScopeMappings() {
|
||||
Set<RoleModel> roleMappings = getScopeMappings();
|
||||
|
||||
Set<RoleModel> appRoles = new HashSet<RoleModel>();
|
||||
Set<RoleModel> appRoles = new HashSet<>();
|
||||
for (RoleModel role : roleMappings) {
|
||||
RoleContainerModel container = role.getContainer();
|
||||
if (container instanceof RealmModel) {
|
||||
@@ -190,8 +185,6 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
return appRoles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getScopeMappings() {
|
||||
TypedQuery<String> query = em.createNamedQuery("clientScopeMappingIds", String.class);
|
||||
@@ -236,32 +229,6 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScope(RoleModel role) {
|
||||
if (isFullScopeAllowed()) return true;
|
||||
Set<RoleModel> roles = getScopeMappings();
|
||||
if (roles.contains(role)) return true;
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!this.getClass().equals(o.getClass())) return false;
|
||||
|
||||
ClientAdapter that = (ClientAdapter) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return entity.getId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocol() {
|
||||
return entity.getProtocol();
|
||||
@@ -281,7 +248,7 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
entity.getAttributes().remove(name);
|
||||
entity.getAttributes().remove(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -291,7 +258,7 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAttributes() {
|
||||
Map<String, String> copy = new HashMap<String, String>();
|
||||
Map<String, String> copy = new HashMap<>();
|
||||
copy.putAll(entity.getAttributes());
|
||||
return copy;
|
||||
}
|
||||
@@ -299,8 +266,8 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
@Override
|
||||
public void updateIdentityProviders(List<ClientIdentityProviderMappingModel> identityProviders) {
|
||||
Collection<ClientIdentityProviderMappingEntity> entities = entity.getIdentityProviders();
|
||||
Set<String> already = new HashSet<String>();
|
||||
List<ClientIdentityProviderMappingEntity> remove = new ArrayList<ClientIdentityProviderMappingEntity>();
|
||||
Set<String> already = new HashSet<>();
|
||||
List<ClientIdentityProviderMappingEntity> remove = new ArrayList<>();
|
||||
|
||||
for (ClientIdentityProviderMappingEntity entity : entities) {
|
||||
IdentityProviderEntity identityProvider = entity.getIdentityProvider();
|
||||
@@ -500,4 +467,282 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
mapping.setConfig(config);
|
||||
return mapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClient() {
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientId() {
|
||||
return entity.getClientId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientId(String clientId) {
|
||||
entity.setClientId(clientId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return entity.isSurrogateAuthRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
entity.setSurrogateAuthRequired(surrogateAuthRequired);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getManagementUrl() {
|
||||
return entity.getManagementUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManagementUrl(String url) {
|
||||
entity.setManagementUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseUrl() {
|
||||
return entity.getBaseUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseUrl(String url) {
|
||||
entity.setBaseUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBearerOnly() {
|
||||
return entity.isBearerOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearerOnly(boolean only) {
|
||||
entity.setBearerOnly(only);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsentRequired() {
|
||||
return entity.isConsentRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConsentRequired(boolean consentRequired) {
|
||||
entity.setConsentRequired(consentRequired);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return entity.isDirectGrantsOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectGrantsOnly(boolean flag) {
|
||||
entity.setDirectGrantsOnly(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel getRole(String name) {
|
||||
TypedQuery<RoleEntity> query = em.createNamedQuery("getAppRoleByName", RoleEntity.class);
|
||||
query.setParameter("name", name);
|
||||
query.setParameter("application", entity);
|
||||
List<RoleEntity> roles = query.getResultList();
|
||||
if (roles.size() == 0) return null;
|
||||
return new RoleAdapter(realm, em, roles.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel addRole(String name) {
|
||||
return this.addRole(KeycloakModelUtils.generateId(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleModel addRole(String id, String name) {
|
||||
RoleEntity roleEntity = new RoleEntity();
|
||||
roleEntity.setId(id);
|
||||
roleEntity.setName(name);
|
||||
roleEntity.setApplication(entity);
|
||||
roleEntity.setApplicationRole(true);
|
||||
roleEntity.setRealmId(realm.getId());
|
||||
em.persist(roleEntity);
|
||||
entity.getRoles().add(roleEntity);
|
||||
em.flush();
|
||||
return new RoleAdapter(realm, em, roleEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(RoleModel roleModel) {
|
||||
if (roleModel == null) {
|
||||
return false;
|
||||
}
|
||||
if (!roleModel.getContainer().equals(this)) return false;
|
||||
|
||||
session.users().preRemove(getRealm(), roleModel);
|
||||
RoleEntity role = RoleAdapter.toRoleEntity(roleModel, em);
|
||||
if (!role.isApplicationRole()) return false;
|
||||
|
||||
entity.getRoles().remove(role);
|
||||
entity.getDefaultRoles().remove(role);
|
||||
em.createNativeQuery("delete from COMPOSITE_ROLE where CHILD_ROLE = :role").setParameter("role", role).executeUpdate();
|
||||
em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", role).executeUpdate();
|
||||
role.setApplication(null);
|
||||
em.flush();
|
||||
em.remove(role);
|
||||
em.flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getRoles() {
|
||||
Set<RoleModel> list = new HashSet<RoleModel>();
|
||||
Collection<RoleEntity> roles = entity.getRoles();
|
||||
if (roles == null) return list;
|
||||
for (RoleEntity entity : roles) {
|
||||
list.add(new RoleAdapter(realm, em, entity));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScope(RoleModel role) {
|
||||
if (isFullScopeAllowed()) return true;
|
||||
Set<RoleModel> roles = getScopeMappings();
|
||||
if (roles.contains(role)) return true;
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
roles = getRoles();
|
||||
if (roles.contains(role)) return true;
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getClientScopeMappings(ClientModel client) {
|
||||
Set<RoleModel> roleMappings = client.getScopeMappings();
|
||||
|
||||
Set<RoleModel> appRoles = new HashSet<RoleModel>();
|
||||
for (RoleModel role : roleMappings) {
|
||||
RoleContainerModel container = role.getContainer();
|
||||
if (container instanceof RealmModel) {
|
||||
} else {
|
||||
ClientModel app = (ClientModel)container;
|
||||
if (app.getId().equals(getId())) {
|
||||
appRoles.add(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appRoles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getDefaultRoles() {
|
||||
Collection<RoleEntity> entities = entity.getDefaultRoles();
|
||||
List<String> roles = new ArrayList<String>();
|
||||
if (entities == null) return roles;
|
||||
for (RoleEntity entity : entities) {
|
||||
roles.add(entity.getName());
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultRole(String name) {
|
||||
RoleModel role = getRole(name);
|
||||
if (role == null) {
|
||||
role = addRole(name);
|
||||
}
|
||||
Collection<RoleEntity> entities = entity.getDefaultRoles();
|
||||
for (RoleEntity entity : entities) {
|
||||
if (entity.getId().equals(role.getId())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
RoleEntity roleEntity = RoleAdapter.toRoleEntity(role, em);
|
||||
entities.add(roleEntity);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDefaultRoles(String[] defaultRoles) {
|
||||
Collection<RoleEntity> entities = entity.getDefaultRoles();
|
||||
Set<String> already = new HashSet<String>();
|
||||
List<RoleEntity> remove = new ArrayList<RoleEntity>();
|
||||
for (RoleEntity rel : entities) {
|
||||
if (!contains(rel.getName(), defaultRoles)) {
|
||||
remove.add(rel);
|
||||
} else {
|
||||
already.add(rel.getName());
|
||||
}
|
||||
}
|
||||
for (RoleEntity entity : remove) {
|
||||
entities.remove(entity);
|
||||
}
|
||||
em.flush();
|
||||
for (String roleName : defaultRoles) {
|
||||
if (!already.contains(roleName)) {
|
||||
addDefaultRole(roleName);
|
||||
}
|
||||
}
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
return entity.getNodeReRegistrationTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNodeReRegistrationTimeout(int timeout) {
|
||||
entity.setNodeReRegistrationTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
return entity.getRegisteredNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNode(String nodeHost, int registrationTime) {
|
||||
Map<String, Integer> currentNodes = getRegisteredNodes();
|
||||
currentNodes.put(nodeHost, registrationTime);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterNode(String nodeHost) {
|
||||
Map<String, Integer> currentNodes = getRegisteredNodes();
|
||||
currentNodes.remove(nodeHost);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof ClientModel)) return false;
|
||||
|
||||
ClientModel that = (ClientModel) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClientId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
package org.keycloak.models.jpa;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.jpa.entities.ApplicationEntity;
|
||||
import org.keycloak.models.jpa.entities.OAuthClientEntity;
|
||||
import org.keycloak.models.jpa.entities.ClientEntity;
|
||||
import org.keycloak.models.jpa.entities.RealmEntity;
|
||||
import org.keycloak.models.jpa.entities.RoleEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
@@ -93,12 +91,8 @@ public class JpaRealmProvider implements RealmProvider {
|
||||
|
||||
RealmAdapter adapter = new RealmAdapter(session, em, realm);
|
||||
session.users().preRemove(adapter);
|
||||
for (ApplicationEntity a : new LinkedList<ApplicationEntity>(realm.getApplications())) {
|
||||
adapter.removeApplication(a.getId());
|
||||
}
|
||||
|
||||
for (OAuthClientModel oauth : adapter.getOAuthClients()) {
|
||||
adapter.removeOAuthClient(oauth.getId());
|
||||
for (ClientEntity a : new LinkedList<>(realm.getApplications())) {
|
||||
adapter.removeClient(a.getId());
|
||||
}
|
||||
|
||||
em.remove(realm);
|
||||
@@ -118,21 +112,12 @@ public class JpaRealmProvider implements RealmProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationById(String id, RealmModel realm) {
|
||||
ApplicationEntity app = em.find(ApplicationEntity.class, id);
|
||||
public ClientModel getClientById(String id, RealmModel realm) {
|
||||
ClientEntity app = em.find(ClientEntity.class, id);
|
||||
|
||||
// Check if application belongs to this realm
|
||||
if (app == null || !realm.getId().equals(app.getRealm().getId())) return null;
|
||||
return new ApplicationAdapter(realm, em, session, app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClientById(String id, RealmModel realm) {
|
||||
OAuthClientEntity client = em.find(OAuthClientEntity.class, id);
|
||||
|
||||
// Check if client belongs to this realm
|
||||
if (client == null || !realm.getId().equals(client.getRealm().getId())) return null;
|
||||
return new OAuthClientAdapter(realm, client, em);
|
||||
return new ClientAdapter(realm, em, session, app);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.keycloak.models.jpa;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.CredentialValidationOutput;
|
||||
import org.keycloak.models.FederatedIdentityModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -61,7 +61,7 @@ public class JpaUserProvider implements UserProvider {
|
||||
userModel.grantRole(realm.getRole(r));
|
||||
}
|
||||
|
||||
for (ApplicationModel application : realm.getApplications()) {
|
||||
for (ClientModel application : realm.getClients()) {
|
||||
for (String r : application.getDefaultRoles()) {
|
||||
userModel.grantRole(application.getRole(r));
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package org.keycloak.models.jpa;
|
||||
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.jpa.entities.OAuthClientEntity;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class OAuthClientAdapter extends ClientAdapter implements OAuthClientModel {
|
||||
|
||||
protected final OAuthClientEntity oAuthClientEntity;
|
||||
|
||||
public OAuthClientAdapter(RealmModel realm, OAuthClientEntity entity, EntityManager em) {
|
||||
super(realm, entity, em);
|
||||
oAuthClientEntity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientId(String id) {
|
||||
entity.setName(id);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return oAuthClientEntity.isDirectGrantsOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectGrantsOnly(boolean flag) {
|
||||
oAuthClientEntity.setDirectGrantsOnly(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof OAuthClientModel)) return false;
|
||||
|
||||
OAuthClientModel that = (OAuthClientModel) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -105,7 +105,7 @@ public class RoleAdapter implements RoleModel {
|
||||
@Override
|
||||
public RoleContainerModel getContainer() {
|
||||
if (role.isApplicationRole()) {
|
||||
return realm.getApplicationById(role.getApplication().getId());
|
||||
return realm.getClientById(role.getApplication().getId());
|
||||
|
||||
} else {
|
||||
return realm;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.keycloak.models.jpa;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
@@ -363,14 +363,14 @@ public class UserAdapter implements UserModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationRoleMappings(ApplicationModel app) {
|
||||
public Set<RoleModel> getClientRoleMappings(ClientModel app) {
|
||||
Set<RoleModel> roleMappings = getRoleMappings();
|
||||
|
||||
Set<RoleModel> roles = new HashSet<RoleModel>();
|
||||
for (RoleModel role : roleMappings) {
|
||||
RoleContainerModel container = role.getContainer();
|
||||
if (container instanceof ApplicationModel) {
|
||||
ApplicationModel appModel = (ApplicationModel)container;
|
||||
if (container instanceof ClientModel) {
|
||||
ClientModel appModel = (ClientModel)container;
|
||||
if (appModel.getId().equals(app.getId())) {
|
||||
roles.add(role);
|
||||
}
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
package org.keycloak.models.jpa.entities;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
@Entity
|
||||
public class ApplicationEntity extends ClientEntity {
|
||||
|
||||
@Column(name="SURROGATE_AUTH_REQUIRED")
|
||||
private boolean surrogateAuthRequired;
|
||||
|
||||
@Column(name="BASE_URL")
|
||||
private String baseUrl;
|
||||
|
||||
@Column(name="MANAGEMENT_URL")
|
||||
private String managementUrl;
|
||||
|
||||
@Column(name="BEARER_ONLY")
|
||||
private boolean bearerOnly;
|
||||
|
||||
@Column(name="NODE_REREG_TIMEOUT")
|
||||
private int nodeReRegistrationTimeout;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "application")
|
||||
Collection<RoleEntity> roles = new ArrayList<RoleEntity>();
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
|
||||
@JoinTable(name="APPLICATION_DEFAULT_ROLES", joinColumns = { @JoinColumn(name="APPLICATION_ID")}, inverseJoinColumns = { @JoinColumn(name="ROLE_ID")})
|
||||
Collection<RoleEntity> defaultRoles = new ArrayList<RoleEntity>();
|
||||
|
||||
@ElementCollection
|
||||
@MapKeyColumn(name="NAME")
|
||||
@Column(name="VALUE")
|
||||
@CollectionTable(name="APP_NODE_REGISTRATIONS", joinColumns={ @JoinColumn(name="APPLICATION_ID") })
|
||||
Map<String, Integer> registeredNodes = new HashMap<String, Integer>();
|
||||
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return surrogateAuthRequired;
|
||||
}
|
||||
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
this.surrogateAuthRequired = surrogateAuthRequired;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public void setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public String getManagementUrl() {
|
||||
return managementUrl;
|
||||
}
|
||||
|
||||
public void setManagementUrl(String managementUrl) {
|
||||
this.managementUrl = managementUrl;
|
||||
}
|
||||
|
||||
public Collection<RoleEntity> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Collection<RoleEntity> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public Collection<RoleEntity> getDefaultRoles() {
|
||||
return defaultRoles;
|
||||
}
|
||||
|
||||
public void setDefaultRoles(Collection<RoleEntity> defaultRoles) {
|
||||
this.defaultRoles = defaultRoles;
|
||||
}
|
||||
|
||||
public boolean isBearerOnly() {
|
||||
return bearerOnly;
|
||||
}
|
||||
|
||||
public void setBearerOnly(boolean bearerOnly) {
|
||||
this.bearerOnly = bearerOnly;
|
||||
}
|
||||
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
return nodeReRegistrationTimeout;
|
||||
}
|
||||
|
||||
public void setNodeReRegistrationTimeout(int nodeReRegistrationTimeout) {
|
||||
this.nodeReRegistrationTimeout = nodeReRegistrationTimeout;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
return registeredNodes;
|
||||
}
|
||||
|
||||
public void setRegisteredNodes(Map<String, Integer> registeredNodes) {
|
||||
this.registeredNodes = registeredNodes;
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
@@ -28,14 +26,14 @@ import java.util.Set;
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@Table(name="CLIENT", uniqueConstraints = {@UniqueConstraint(columnNames = {"REALM_ID", "NAME"})})
|
||||
public abstract class ClientEntity {
|
||||
@Table(name="CLIENT", uniqueConstraints = {@UniqueConstraint(columnNames = {"REALM_ID", "CLIENT_ID"})})
|
||||
public class ClientEntity {
|
||||
|
||||
@Id
|
||||
@Column(name="ID", length = 36)
|
||||
private String id;
|
||||
@Column(name = "NAME")
|
||||
private String name;
|
||||
@Column(name = "CLIENT_ID")
|
||||
private String clientId;
|
||||
@Column(name="ENABLED")
|
||||
private boolean enabled;
|
||||
@Column(name="SECRET")
|
||||
@@ -77,6 +75,40 @@ public abstract class ClientEntity {
|
||||
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "client")
|
||||
Collection<ProtocolMapperEntity> protocolMappers = new ArrayList<ProtocolMapperEntity>();
|
||||
|
||||
@Column(name="SURROGATE_AUTH_REQUIRED")
|
||||
private boolean surrogateAuthRequired;
|
||||
|
||||
@Column(name="BASE_URL")
|
||||
private String baseUrl;
|
||||
|
||||
@Column(name="MANAGEMENT_URL")
|
||||
private String managementUrl;
|
||||
|
||||
@Column(name="DIRECT_GRANTS_ONLY")
|
||||
protected boolean directGrantsOnly;
|
||||
|
||||
@Column(name="BEARER_ONLY")
|
||||
private boolean bearerOnly;
|
||||
|
||||
@Column(name="CONSENT_REQUIRED")
|
||||
private boolean consentRequired;
|
||||
|
||||
@Column(name="NODE_REREG_TIMEOUT")
|
||||
private int nodeReRegistrationTimeout;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "application")
|
||||
Collection<RoleEntity> roles = new ArrayList<RoleEntity>();
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
|
||||
@JoinTable(name="APPLICATION_DEFAULT_ROLES", joinColumns = { @JoinColumn(name="APPLICATION_ID")}, inverseJoinColumns = { @JoinColumn(name="ROLE_ID")})
|
||||
Collection<RoleEntity> defaultRoles = new ArrayList<RoleEntity>();
|
||||
|
||||
@ElementCollection
|
||||
@MapKeyColumn(name="NAME")
|
||||
@Column(name="VALUE")
|
||||
@CollectionTable(name="APP_NODE_REGISTRATIONS", joinColumns={ @JoinColumn(name="APPLICATION_ID") })
|
||||
Map<String, Integer> registeredNodes = new HashMap<String, Integer>();
|
||||
|
||||
public RealmEntity getRealm() {
|
||||
return realm;
|
||||
}
|
||||
@@ -101,12 +133,12 @@ public abstract class ClientEntity {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public Set<String> getWebOrigins() {
|
||||
@@ -196,4 +228,84 @@ public abstract class ClientEntity {
|
||||
public void setProtocolMappers(Collection<ProtocolMapperEntity> protocolMappers) {
|
||||
this.protocolMappers = protocolMappers;
|
||||
}
|
||||
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return surrogateAuthRequired;
|
||||
}
|
||||
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
this.surrogateAuthRequired = surrogateAuthRequired;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public void setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public String getManagementUrl() {
|
||||
return managementUrl;
|
||||
}
|
||||
|
||||
public void setManagementUrl(String managementUrl) {
|
||||
this.managementUrl = managementUrl;
|
||||
}
|
||||
|
||||
public Collection<RoleEntity> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Collection<RoleEntity> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public Collection<RoleEntity> getDefaultRoles() {
|
||||
return defaultRoles;
|
||||
}
|
||||
|
||||
public void setDefaultRoles(Collection<RoleEntity> defaultRoles) {
|
||||
this.defaultRoles = defaultRoles;
|
||||
}
|
||||
|
||||
public boolean isBearerOnly() {
|
||||
return bearerOnly;
|
||||
}
|
||||
|
||||
public void setBearerOnly(boolean bearerOnly) {
|
||||
this.bearerOnly = bearerOnly;
|
||||
}
|
||||
|
||||
public boolean isConsentRequired() {
|
||||
return consentRequired;
|
||||
}
|
||||
|
||||
public void setConsentRequired(boolean consentRequired) {
|
||||
this.consentRequired = consentRequired;
|
||||
}
|
||||
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return directGrantsOnly;
|
||||
}
|
||||
|
||||
public void setDirectGrantsOnly(boolean directGrantsOnly) {
|
||||
this.directGrantsOnly = directGrantsOnly;
|
||||
}
|
||||
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
return nodeReRegistrationTimeout;
|
||||
}
|
||||
|
||||
public void setNodeReRegistrationTimeout(int nodeReRegistrationTimeout) {
|
||||
this.nodeReRegistrationTimeout = nodeReRegistrationTimeout;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
return registeredNodes;
|
||||
}
|
||||
|
||||
public void setRegisteredNodes(Map<String, Integer> registeredNodes) {
|
||||
this.registeredNodes = registeredNodes;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package org.keycloak.models.jpa.entities;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
@NamedQueries({
|
||||
@NamedQuery(name="findOAuthClientByName", query="select o from OAuthClientEntity o where o.name=:name and o.realm = :realm"),
|
||||
@NamedQuery(name="findOAuthClientByRealm", query="select o from OAuthClientEntity o where o.realm = :realm")
|
||||
|
||||
})
|
||||
@Entity
|
||||
public class OAuthClientEntity extends ClientEntity {
|
||||
@Column(name="DIRECT_GRANTS_ONLY")
|
||||
protected boolean directGrantsOnly;
|
||||
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return directGrantsOnly;
|
||||
}
|
||||
|
||||
public void setDirectGrantsOnly(boolean directGrantsOnly) {
|
||||
this.directGrantsOnly = directGrantsOnly;
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,6 @@ import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public class RealmEntity {
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
|
||||
@JoinTable(name="REALM_APPLICATION", joinColumns={ @JoinColumn(name="REALM_ID") }, inverseJoinColumns={ @JoinColumn(name="APPLICATION_ID") })
|
||||
Collection<ApplicationEntity> applications = new ArrayList<ApplicationEntity>();
|
||||
Collection<ClientEntity> applications = new ArrayList<ClientEntity>();
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm")
|
||||
Collection<RoleEntity> roles = new ArrayList<RoleEntity>();
|
||||
@@ -137,7 +137,7 @@ public class RealmEntity {
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name="MASTER_ADMIN_APP")
|
||||
protected ApplicationEntity masterAdminApp;
|
||||
protected ClientEntity masterAdminApp;
|
||||
|
||||
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm")
|
||||
protected List<IdentityProviderEntity> identityProviders = new ArrayList<IdentityProviderEntity>();
|
||||
@@ -318,11 +318,11 @@ public class RealmEntity {
|
||||
this.requiredCredentials = requiredCredentials;
|
||||
}
|
||||
|
||||
public Collection<ApplicationEntity> getApplications() {
|
||||
public Collection<ClientEntity> getApplications() {
|
||||
return applications;
|
||||
}
|
||||
|
||||
public void setApplications(Collection<ApplicationEntity> applications) {
|
||||
public void setApplications(Collection<ClientEntity> applications) {
|
||||
this.applications = applications;
|
||||
}
|
||||
|
||||
@@ -437,11 +437,11 @@ public class RealmEntity {
|
||||
this.enabledEventTypes = enabledEventTypes;
|
||||
}
|
||||
|
||||
public ApplicationEntity getMasterAdminApp() {
|
||||
public ClientEntity getMasterAdminApp() {
|
||||
return masterAdminApp;
|
||||
}
|
||||
|
||||
public void setMasterAdminApp(ApplicationEntity masterAdminApp) {
|
||||
public void setMasterAdminApp(ClientEntity masterAdminApp) {
|
||||
this.masterAdminApp = masterAdminApp;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class RoleEntity {
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "APPLICATION")
|
||||
private ApplicationEntity application;
|
||||
private ClientEntity application;
|
||||
|
||||
// Hack to ensure that either name+application or name+realm are unique. Needed due to MS-SQL as it don't allow multiple NULL values in the column, which is part of constraint
|
||||
@Column(name="APP_REALM_CONSTRAINT", length = 36)
|
||||
@@ -118,11 +118,11 @@ public class RoleEntity {
|
||||
this.appRealmConstraint = realm.getId();
|
||||
}
|
||||
|
||||
public ApplicationEntity getApplication() {
|
||||
public ClientEntity getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(ApplicationEntity application) {
|
||||
public void setApplication(ClientEntity application) {
|
||||
this.application = application;
|
||||
if (application != null) {
|
||||
this.appRealmConstraint = application.getId();
|
||||
|
||||
-275
@@ -1,275 +0,0 @@
|
||||
package org.keycloak.models.mongo.keycloak.adapters;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.QueryBuilder;
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
||||
import org.keycloak.models.mongo.utils.MongoModelUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class ApplicationAdapter extends ClientAdapter<MongoApplicationEntity> implements ApplicationModel {
|
||||
|
||||
public ApplicationAdapter(KeycloakSession session, RealmModel realm, MongoApplicationEntity applicationEntity, MongoStoreInvocationContext invContext) {
|
||||
super(session, realm, applicationEntity, invContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateApplication() {
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getMongoEntity().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
getMongoEntity().setName(name);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurrogateAuthRequired() {
|
||||
return getMongoEntity().isSurrogateAuthRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
|
||||
getMongoEntity().setSurrogateAuthRequired(surrogateAuthRequired);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getManagementUrl() {
|
||||
return getMongoEntity().getManagementUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManagementUrl(String url) {
|
||||
getMongoEntity().setManagementUrl(url);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseUrl(String url) {
|
||||
getMongoEntity().setBaseUrl(url);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseUrl() {
|
||||
return getMongoEntity().getBaseUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBearerOnly() {
|
||||
return getMongoEntity().isBearerOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearerOnly(boolean only) {
|
||||
getMongoEntity().setBearerOnly(only);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPublicClient() {
|
||||
return getMongoEntity().isPublicClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPublicClient(boolean flag) {
|
||||
getMongoEntity().setPublicClient(flag);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return false; // applications can't be grant only
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectGrantsOnly(boolean flag) {
|
||||
// applications can't be grant only
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RoleAdapter getRole(String name) {
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("name").is(name)
|
||||
.and("applicationId").is(getId())
|
||||
.get();
|
||||
MongoRoleEntity role = getMongoStore().loadSingleEntity(MongoRoleEntity.class, query, invocationContext);
|
||||
if (role == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new RoleAdapter(session, getRealm(), role, invocationContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleAdapter addRole(String name) {
|
||||
return this.addRole(null, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleAdapter addRole(String id, String name) {
|
||||
MongoRoleEntity roleEntity = new MongoRoleEntity();
|
||||
roleEntity.setId(id);
|
||||
roleEntity.setName(name);
|
||||
roleEntity.setApplicationId(getId());
|
||||
|
||||
getMongoStore().insertEntity(roleEntity, invocationContext);
|
||||
|
||||
return new RoleAdapter(session, getRealm(), roleEntity, this, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeRole(RoleModel role) {
|
||||
session.users().preRemove(getRealm(), role);
|
||||
return getMongoStore().removeEntity(MongoRoleEntity.class, role.getId(), invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getRoles() {
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("applicationId").is(getId())
|
||||
.get();
|
||||
List<MongoRoleEntity> roles = getMongoStore().loadEntities(MongoRoleEntity.class, query, invocationContext);
|
||||
|
||||
Set<RoleModel> result = new HashSet<RoleModel>();
|
||||
for (MongoRoleEntity role : roles) {
|
||||
result.add(new RoleAdapter(session, getRealm(), role, this, invocationContext));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScope(RoleModel role) {
|
||||
if (super.hasScope(role)) {
|
||||
return true;
|
||||
}
|
||||
Set<RoleModel> roles = getRoles();
|
||||
if (roles.contains(role)) return true;
|
||||
|
||||
for (RoleModel mapping : roles) {
|
||||
if (mapping.hasRole(role)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationScopeMappings(ClientModel client) {
|
||||
Set<RoleModel> result = new HashSet<RoleModel>();
|
||||
List<MongoRoleEntity> roles = MongoModelUtils.getAllScopesOfClient(client, invocationContext);
|
||||
|
||||
for (MongoRoleEntity role : roles) {
|
||||
if (getId().equals(role.getApplicationId())) {
|
||||
result.add(new RoleAdapter(session, getRealm(), role, this, invocationContext));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDefaultRoles() {
|
||||
return getMongoEntity().getDefaultRoles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultRole(String name) {
|
||||
RoleModel role = getRole(name);
|
||||
if (role == null) {
|
||||
addRole(name);
|
||||
}
|
||||
|
||||
getMongoStore().pushItemToList(getMongoEntity(), "defaultRoles", name, true, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDefaultRoles(String[] defaultRoles) {
|
||||
List<String> roleNames = new ArrayList<String>();
|
||||
for (String roleName : defaultRoles) {
|
||||
RoleModel role = getRole(roleName);
|
||||
if (role == null) {
|
||||
addRole(roleName);
|
||||
}
|
||||
|
||||
roleNames.add(roleName);
|
||||
}
|
||||
|
||||
getMongoEntity().setDefaultRoles(roleNames);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeReRegistrationTimeout() {
|
||||
return getMongoEntity().getNodeReRegistrationTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNodeReRegistrationTimeout(int timeout) {
|
||||
getMongoEntity().setNodeReRegistrationTimeout(timeout);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getRegisteredNodes() {
|
||||
return getMongoEntity().getRegisteredNodes() == null ? Collections.<String, Integer>emptyMap() : Collections.unmodifiableMap(getMongoEntity().getRegisteredNodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNode(String nodeHost, int registrationTime) {
|
||||
MongoApplicationEntity entity = getMongoEntity();
|
||||
if (entity.getRegisteredNodes() == null) {
|
||||
entity.setRegisteredNodes(new HashMap<String, Integer>());
|
||||
}
|
||||
|
||||
entity.getRegisteredNodes().put(nodeHost, registrationTime);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterNode(String nodeHost) {
|
||||
MongoApplicationEntity entity = getMongoEntity();
|
||||
if (entity.getRegisteredNodes() == null) return;
|
||||
|
||||
entity.getRegisteredNodes().remove(nodeHost);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof ApplicationModel)) return false;
|
||||
|
||||
ApplicationModel that = (ApplicationModel) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+672
-445
File diff suppressed because it is too large.
Load diff
+6
-18
@@ -5,14 +5,12 @@ import com.mongodb.DBObject;
|
||||
import com.mongodb.QueryBuilder;
|
||||
import org.keycloak.connections.mongo.api.MongoStore;
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoOAuthClientEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoClientEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoRealmEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
@@ -107,30 +105,20 @@ public class MongoRealmProvider implements RealmProvider {
|
||||
MongoRoleEntity role = getMongoStore().loadEntity(MongoRoleEntity.class, id, invocationContext);
|
||||
if (role == null) return null;
|
||||
if (role.getRealmId() != null && !role.getRealmId().equals(realm.getId())) return null;
|
||||
if (role.getApplicationId() != null && realm.getApplicationById(role.getApplicationId()) == null) return null;
|
||||
if (role.getClientId() != null && realm.getClientById(role.getClientId()) == null) return null;
|
||||
return new RoleAdapter(session, realm, role, null, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationById(String id, RealmModel realm) {
|
||||
MongoApplicationEntity appData = getMongoStore().loadEntity(MongoApplicationEntity.class, id, invocationContext);
|
||||
public ClientModel getClientById(String id, RealmModel realm) {
|
||||
MongoClientEntity appData = getMongoStore().loadEntity(MongoClientEntity.class, id, invocationContext);
|
||||
|
||||
// Check if application belongs to this realm
|
||||
if (appData == null || !realm.getId().equals(appData.getRealmId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ApplicationAdapter(session, realm, appData, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClientById(String id, RealmModel realm) {
|
||||
MongoOAuthClientEntity clientEntity = getMongoStore().loadEntity(MongoOAuthClientEntity.class, id, invocationContext);
|
||||
|
||||
// Check if client belongs to this realm
|
||||
if (clientEntity == null || !realm.getId().equals(clientEntity.getRealmId())) return null;
|
||||
|
||||
return new OAuthClientAdapter(session, realm, clientEntity, invocationContext);
|
||||
return new ClientAdapter(session, realm, appData, invocationContext);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -5,7 +5,7 @@ import com.mongodb.DBObject;
|
||||
import com.mongodb.QueryBuilder;
|
||||
import org.keycloak.connections.mongo.api.MongoStore;
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.CredentialValidationOutput;
|
||||
import org.keycloak.models.FederatedIdentityModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -249,7 +249,7 @@ public class MongoUserProvider implements UserProvider {
|
||||
userModel.grantRole(realm.getRole(r));
|
||||
}
|
||||
|
||||
for (ApplicationModel application : realm.getApplications()) {
|
||||
for (ClientModel application : realm.getClients()) {
|
||||
for (String r : application.getDefaultRoles()) {
|
||||
userModel.grantRole(application.getRole(r));
|
||||
}
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package org.keycloak.models.mongo.keycloak.adapters;
|
||||
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoOAuthClientEntity;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class OAuthClientAdapter extends ClientAdapter<MongoOAuthClientEntity> implements OAuthClientModel {
|
||||
|
||||
public OAuthClientAdapter(KeycloakSession session, RealmModel realm, MongoOAuthClientEntity oauthClientEntity, MongoStoreInvocationContext invContext) {
|
||||
super(session, realm, oauthClientEntity, invContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientId(String id) {
|
||||
getMongoEntity().setName(id);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return getMongoEntity().isDirectGrantsOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectGrantsOnly(boolean flag) {
|
||||
getMongoEntity().setDirectGrantsOnly(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || !(o instanceof OAuthClientModel)) return false;
|
||||
|
||||
OAuthClientModel that = (OAuthClientModel) o;
|
||||
return that.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
+30
-115
@@ -4,12 +4,10 @@ import com.mongodb.DBObject;
|
||||
import com.mongodb.QueryBuilder;
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.enums.SslRequired;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.IdentityProviderMapperModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RealmProvider;
|
||||
@@ -20,8 +18,7 @@ import org.keycloak.models.entities.IdentityProviderEntity;
|
||||
import org.keycloak.models.entities.IdentityProviderMapperEntity;
|
||||
import org.keycloak.models.entities.RequiredCredentialEntity;
|
||||
import org.keycloak.models.entities.UserFederationProviderEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoOAuthClientEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoClientEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoRealmEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
@@ -579,80 +576,59 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientModel findClient(String clientId) {
|
||||
ClientModel model = getApplicationByName(clientId);
|
||||
if (model != null) return model;
|
||||
return getOAuthClient(clientId);
|
||||
public ClientModel getClientById(String id) {
|
||||
return model.getClientById(id, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientModel findClientById(String id) {
|
||||
ClientModel model = getApplicationById(id);
|
||||
if (model != null) return model;
|
||||
return getOAuthClientById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationById(String id) {
|
||||
return model.getApplicationById(id, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getApplicationByName(String name) {
|
||||
public ClientModel getClientByClientId(String clientId) {
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("realmId").is(getId())
|
||||
.and("name").is(name)
|
||||
.and("clientId").is(clientId)
|
||||
.get();
|
||||
MongoApplicationEntity appEntity = getMongoStore().loadSingleEntity(MongoApplicationEntity.class, query, invocationContext);
|
||||
return appEntity == null ? null : new ApplicationAdapter(session, this, appEntity, invocationContext);
|
||||
MongoClientEntity appEntity = getMongoStore().loadSingleEntity(MongoClientEntity.class, query, invocationContext);
|
||||
return appEntity == null ? null : new ClientAdapter(session, this, appEntity, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ApplicationModel> getApplicationNameMap() {
|
||||
Map<String, ApplicationModel> resourceMap = new HashMap<String, ApplicationModel>();
|
||||
for (ApplicationModel resource : getApplications()) {
|
||||
resourceMap.put(resource.getName(), resource);
|
||||
public Map<String, ClientModel> getClientNameMap() {
|
||||
Map<String, ClientModel> resourceMap = new HashMap<String, ClientModel>();
|
||||
for (ClientModel resource : getClients()) {
|
||||
resourceMap.put(resource.getClientId(), resource);
|
||||
}
|
||||
return resourceMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationModel> getApplications() {
|
||||
public List<ClientModel> getClients() {
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("realmId").is(getId())
|
||||
.get();
|
||||
List<MongoApplicationEntity> appDatas = getMongoStore().loadEntities(MongoApplicationEntity.class, query, invocationContext);
|
||||
List<MongoClientEntity> appDatas = getMongoStore().loadEntities(MongoClientEntity.class, query, invocationContext);
|
||||
|
||||
List<ApplicationModel> result = new ArrayList<ApplicationModel>();
|
||||
for (MongoApplicationEntity appData : appDatas) {
|
||||
result.add(new ApplicationAdapter(session, this, appData, invocationContext));
|
||||
List<ClientModel> result = new ArrayList<ClientModel>();
|
||||
for (MongoClientEntity appData : appDatas) {
|
||||
result.add(new ClientAdapter(session, this, appData, invocationContext));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel addApplication(String name) {
|
||||
return this.addApplication(null, name);
|
||||
public ClientModel addClient(String name) {
|
||||
return this.addClient(null, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel addApplication(String id, String name) {
|
||||
MongoApplicationEntity appData = new MongoApplicationEntity();
|
||||
public ClientModel addClient(String id, String clientId) {
|
||||
MongoClientEntity appData = new MongoClientEntity();
|
||||
appData.setId(id);
|
||||
appData.setName(name);
|
||||
appData.setClientId(clientId);
|
||||
appData.setRealmId(getId());
|
||||
appData.setEnabled(true);
|
||||
getMongoStore().insertEntity(appData, invocationContext);
|
||||
|
||||
final ApplicationModel model = new ApplicationAdapter(session, this, appData, invocationContext);
|
||||
session.getKeycloakSessionFactory().publish(new ApplicationCreationEvent() {
|
||||
@Override
|
||||
public ApplicationModel getCreatedApplication() {
|
||||
return model;
|
||||
}
|
||||
|
||||
final ClientModel model = new ClientAdapter(session, this, appData, invocationContext);
|
||||
session.getKeycloakSessionFactory().publish(new ClientCreationEvent() {
|
||||
@Override
|
||||
public ClientModel getCreatedClient() {
|
||||
return model;
|
||||
@@ -662,69 +638,8 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeApplication(String id) {
|
||||
return getMongoStore().removeEntity(MongoApplicationEntity.class, id, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel addOAuthClient(String name) {
|
||||
return this.addOAuthClient(null, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel addOAuthClient(String id, String name) {
|
||||
MongoOAuthClientEntity oauthClient = new MongoOAuthClientEntity();
|
||||
oauthClient.setId(id);
|
||||
oauthClient.setRealmId(getId());
|
||||
oauthClient.setName(name);
|
||||
getMongoStore().insertEntity(oauthClient, invocationContext);
|
||||
|
||||
final OAuthClientAdapter model = new OAuthClientAdapter(session, this, oauthClient, invocationContext);
|
||||
session.getKeycloakSessionFactory().publish(new OAuthClientCreationEvent() {
|
||||
@Override
|
||||
public OAuthClientModel getCreatedOAuthClient() {
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientModel getCreatedClient() {
|
||||
return model;
|
||||
}
|
||||
});
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeOAuthClient(String id) {
|
||||
return getMongoStore().removeEntity(MongoOAuthClientEntity.class, id, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClient(String name) {
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("realmId").is(getId())
|
||||
.and("name").is(name)
|
||||
.get();
|
||||
MongoOAuthClientEntity oauthClient = getMongoStore().loadSingleEntity(MongoOAuthClientEntity.class, query, invocationContext);
|
||||
return oauthClient == null ? null : new OAuthClientAdapter(session, this, oauthClient, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthClientModel getOAuthClientById(String id) {
|
||||
return model.getOAuthClientById(id, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OAuthClientModel> getOAuthClients() {
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("realmId").is(getId())
|
||||
.get();
|
||||
List<MongoOAuthClientEntity> results = getMongoStore().loadEntities(MongoOAuthClientEntity.class, query, invocationContext);
|
||||
List<OAuthClientModel> list = new ArrayList<OAuthClientModel>();
|
||||
for (MongoOAuthClientEntity data : results) {
|
||||
list.add(new OAuthClientAdapter(session, this, data, invocationContext));
|
||||
}
|
||||
return list;
|
||||
public boolean removeClient(String id) {
|
||||
return getMongoStore().removeEntity(MongoClientEntity.class, id, invocationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1063,14 +978,14 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationModel getMasterAdminApp() {
|
||||
MongoApplicationEntity appData = getMongoStore().loadEntity(MongoApplicationEntity.class, realm.getAdminAppId(), invocationContext);
|
||||
return appData != null ? new ApplicationAdapter(session, this, appData, invocationContext) : null;
|
||||
public ClientModel getMasterAdminClient() {
|
||||
MongoClientEntity appData = getMongoStore().loadEntity(MongoClientEntity.class, realm.getAdminAppId(), invocationContext);
|
||||
return appData != null ? new ClientAdapter(session, this, appData, invocationContext) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMasterAdminApp(ApplicationModel app) {
|
||||
String adminAppId = app != null ? app.getId() : null;
|
||||
public void setMasterAdminClient(ClientModel client) {
|
||||
String adminAppId = client != null ? client.getId() : null;
|
||||
realm.setAdminAppId(adminAppId);
|
||||
updateRealm();
|
||||
}
|
||||
|
||||
+6
-6
@@ -7,7 +7,7 @@ import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoClientEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoRealmEntity;
|
||||
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
@@ -115,14 +115,14 @@ public class RoleAdapter extends AbstractMongoAdapter<MongoRoleEntity> implement
|
||||
throw new IllegalStateException("Realm with id: " + role.getRealmId() + " doesn't exists");
|
||||
}
|
||||
roleContainer = new RealmAdapter(session, realm, invocationContext);
|
||||
} else if (role.getApplicationId() != null) {
|
||||
MongoApplicationEntity appEntity = getMongoStore().loadEntity(MongoApplicationEntity.class, role.getApplicationId(), invocationContext);
|
||||
} else if (role.getClientId() != null) {
|
||||
MongoClientEntity appEntity = getMongoStore().loadEntity(MongoClientEntity.class, role.getClientId(), invocationContext);
|
||||
if (appEntity == null) {
|
||||
throw new IllegalStateException("Application with id: " + role.getApplicationId() + " doesn't exists");
|
||||
throw new IllegalStateException("Application with id: " + role.getClientId() + " doesn't exists");
|
||||
}
|
||||
roleContainer = new ApplicationAdapter(session, realm, appEntity, invocationContext);
|
||||
roleContainer = new ClientAdapter(session, realm, appEntity, invocationContext);
|
||||
} else {
|
||||
throw new IllegalStateException("Both realmId and applicationId are null for role: " + this);
|
||||
throw new IllegalStateException("Both realmId and clientId are null for role: " + this);
|
||||
}
|
||||
}
|
||||
return roleContainer;
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package org.keycloak.models.mongo.keycloak.adapters;
|
||||
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -316,12 +316,12 @@ public class UserAdapter extends AbstractMongoAdapter<MongoUserEntity> implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RoleModel> getApplicationRoleMappings(ApplicationModel app) {
|
||||
public Set<RoleModel> getClientRoleMappings(ClientModel app) {
|
||||
Set<RoleModel> result = new HashSet<RoleModel>();
|
||||
List<MongoRoleEntity> roles = MongoModelUtils.getAllRolesOfUser(this, invocationContext);
|
||||
|
||||
for (MongoRoleEntity role : roles) {
|
||||
if (app.getId().equals(role.getApplicationId())) {
|
||||
if (app.getId().equals(role.getClientId())) {
|
||||
result.add(new RoleAdapter(session, realm, role, app, invocationContext));
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -5,19 +5,19 @@ import com.mongodb.QueryBuilder;
|
||||
import org.keycloak.connections.mongo.api.MongoCollection;
|
||||
import org.keycloak.connections.mongo.api.MongoIdentifiableEntity;
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.entities.ApplicationEntity;
|
||||
import org.keycloak.models.entities.ClientEntity;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
@MongoCollection(collectionName = "applications")
|
||||
public class MongoApplicationEntity extends ApplicationEntity implements MongoIdentifiableEntity {
|
||||
@MongoCollection(collectionName = "clients")
|
||||
public class MongoClientEntity extends ClientEntity implements MongoIdentifiableEntity {
|
||||
|
||||
@Override
|
||||
public void afterRemove(MongoStoreInvocationContext context) {
|
||||
// Remove all roles, which belongs to this application
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("applicationId").is(getId())
|
||||
.and("clientId").is(getId())
|
||||
.get();
|
||||
context.getMongoStore().removeEntities(MongoRoleEntity.class, query, context);
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package org.keycloak.models.mongo.keycloak.entities;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.QueryBuilder;
|
||||
import org.keycloak.connections.mongo.api.MongoCollection;
|
||||
import org.keycloak.connections.mongo.api.MongoIdentifiableEntity;
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.entities.OAuthClientEntity;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
@MongoCollection(collectionName = "oauthClients")
|
||||
public class MongoOAuthClientEntity extends OAuthClientEntity implements MongoIdentifiableEntity {
|
||||
|
||||
@Override
|
||||
public void afterRemove(MongoStoreInvocationContext context) {
|
||||
// Remove all session associations
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("associatedClientIds").is(getId())
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -26,9 +26,6 @@ public class MongoRealmEntity extends RealmEntity implements MongoIdentifiableEn
|
||||
context.getMongoStore().removeEntities(MongoRoleEntity.class, query, context);
|
||||
|
||||
// Remove all applications of this realm
|
||||
context.getMongoStore().removeEntities(MongoApplicationEntity.class, query, context);
|
||||
|
||||
// Remove all clients of this realm
|
||||
context.getMongoStore().removeEntities(MongoOAuthClientEntity.class, query, context);
|
||||
context.getMongoStore().removeEntities(MongoClientEntity.class, query, context);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -24,13 +24,13 @@ public class MongoRoleEntity extends RoleEntity implements MongoIdentifiableEnti
|
||||
// TODO This is required as Mongo doesn't support sparse indexes with compound keys (see https://jira.mongodb.org/browse/SERVER-2193)
|
||||
public String getNameIndex() {
|
||||
String realmId = getRealmId();
|
||||
String applicationId = getApplicationId();
|
||||
String clientId = getClientId();
|
||||
String name = getName();
|
||||
|
||||
if (realmId != null) {
|
||||
return realmId + "//" + name;
|
||||
} else {
|
||||
return applicationId + "//" + name;
|
||||
return clientId + "//" + name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ public class MongoRoleEntity extends RoleEntity implements MongoIdentifiableEnti
|
||||
}
|
||||
|
||||
// Remove defaultRoles from application
|
||||
if (getApplicationId() != null) {
|
||||
MongoApplicationEntity appEntity = mongoStore.loadEntity(MongoApplicationEntity.class, getApplicationId(), invContext);
|
||||
if (getClientId() != null) {
|
||||
MongoClientEntity appEntity = mongoStore.loadEntity(MongoClientEntity.class, getClientId(), invContext);
|
||||
|
||||
// Application might be already removed at this point
|
||||
if (appEntity != null) {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class MongoModelUtils {
|
||||
|
||||
// Get everything including both application and realm scopes
|
||||
public static List<MongoRoleEntity> getAllScopesOfClient(ClientModel client, MongoStoreInvocationContext invContext) {
|
||||
ClientEntity scopedEntity = ((ClientAdapter)client).getMongoEntityAsClient();
|
||||
ClientEntity scopedEntity = ((ClientAdapter)client).getMongoEntity();
|
||||
List<String> scopeIds = scopedEntity.getScopeIds();
|
||||
|
||||
if (scopeIds == null || scopeIds.isEmpty()) {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class ClientSessionAdapter implements ClientSessionModel {
|
||||
|
||||
@Override
|
||||
public ClientModel getClient() {
|
||||
return realm.findClientById(entity.getClient());
|
||||
return realm.getClientById(entity.getClient());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ public class ClientSessionAdapter implements ClientSessionModel {
|
||||
|
||||
@Override
|
||||
public ClientModel getClient() {
|
||||
return realm.findClientById(entity.getClientId());
|
||||
return realm.getClientById(entity.getClientId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-1
@@ -20,7 +20,6 @@ import javax.persistence.EntityManager;
|
||||
import javax.persistence.TypedQuery;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class ClientSessionAdapter implements ClientSessionModel {
|
||||
|
||||
@Override
|
||||
public ClientModel getClient() {
|
||||
return realm.findClientById(entity.getClientId());
|
||||
return realm.getClientById(entity.getClientId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-1
@@ -25,7 +25,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class ClientSessionAdapter extends AbstractMongoAdapter<MongoClientSessio
|
||||
|
||||
@Override
|
||||
public ClientModel getClient() {
|
||||
return realm.findClientById(entity.getClientId());
|
||||
return realm.getClientById(entity.getClientId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user