Merge pull request #507 from stianst/master
Removed model methods from KeycloakSession
This commit is contained in:
commit
20bf888d73
40 changed files with 196 additions and 436 deletions
|
@ -7,6 +7,7 @@ import org.keycloak.audit.EventType;
|
||||||
import org.keycloak.email.EmailException;
|
import org.keycloak.email.EmailException;
|
||||||
import org.keycloak.email.EmailProvider;
|
import org.keycloak.email.EmailProvider;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
|
|
||||||
|
@ -20,11 +21,13 @@ public class EmailAuditListener implements AuditListener {
|
||||||
private static final Logger log = Logger.getLogger(EmailAuditListener.class);
|
private static final Logger log = Logger.getLogger(EmailAuditListener.class);
|
||||||
|
|
||||||
private KeycloakSession session;
|
private KeycloakSession session;
|
||||||
|
private ModelProvider model;
|
||||||
private EmailProvider emailProvider;
|
private EmailProvider emailProvider;
|
||||||
private Set<EventType> includedEvents;
|
private Set<EventType> includedEvents;
|
||||||
|
|
||||||
public EmailAuditListener(KeycloakSession session, EmailProvider emailProvider, Set<EventType> includedEvents) {
|
public EmailAuditListener(KeycloakSession session, EmailProvider emailProvider, Set<EventType> includedEvents) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
this.model = session.getModel();
|
||||||
this.emailProvider = emailProvider;
|
this.emailProvider = emailProvider;
|
||||||
this.includedEvents = includedEvents;
|
this.includedEvents = includedEvents;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +36,7 @@ public class EmailAuditListener implements AuditListener {
|
||||||
public void onEvent(Event event) {
|
public void onEvent(Event event) {
|
||||||
if (includedEvents.contains(event.getEvent())) {
|
if (includedEvents.contains(event.getEvent())) {
|
||||||
if (event.getRealmId() != null && event.getUserId() != null) {
|
if (event.getRealmId() != null && event.getUserId() != null) {
|
||||||
RealmModel realm = session.getRealm(event.getRealmId());
|
RealmModel realm = model.getRealm(event.getRealmId());
|
||||||
UserModel user = realm.getUserById(event.getUserId());
|
UserModel user = realm.getUserById(event.getUserId());
|
||||||
if (user != null && user.getEmail() != null && user.isEmailVerified()) {
|
if (user != null && user.getEmail() != null && user.isEmailVerified()) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.keycloak.authentication.model;
|
package org.keycloak.authentication.model;
|
||||||
|
|
||||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
|
||||||
import org.keycloak.authentication.AuthProviderConstants;
|
import org.keycloak.authentication.AuthProviderConstants;
|
||||||
import org.keycloak.authentication.AuthenticationProviderException;
|
import org.keycloak.authentication.AuthenticationProviderException;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -17,7 +17,10 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class ExternalModelAuthenticationProvider extends AbstractModelAuthenticationProvider {
|
public class ExternalModelAuthenticationProvider extends AbstractModelAuthenticationProvider {
|
||||||
|
|
||||||
public ExternalModelAuthenticationProvider() {
|
private ModelProvider model;
|
||||||
|
|
||||||
|
public ExternalModelAuthenticationProvider(KeycloakSession session) {
|
||||||
|
this.model = session.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,13 +40,7 @@ public class ExternalModelAuthenticationProvider extends AbstractModelAuthentica
|
||||||
throw new AuthenticationProviderException("Option '" + AuthProviderConstants.EXTERNAL_REALM_ID + "' not specified in configuration");
|
throw new AuthenticationProviderException("Option '" + AuthProviderConstants.EXTERNAL_REALM_ID + "' not specified in configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This won't be needed when KeycloakSession is available from ProviderSession
|
RealmModel realm = model.getRealm(realmId);
|
||||||
KeycloakSession session = ResteasyProviderFactory.getContextData(KeycloakSession.class);
|
|
||||||
if (session == null) {
|
|
||||||
throw new AuthenticationProviderException("KeycloakSession not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
RealmModel realm = session.getRealm(realmId);
|
|
||||||
if (realm == null) {
|
if (realm == null) {
|
||||||
throw new AuthenticationProviderException("Realm with id '" + realmId + "' doesn't exists");
|
throw new AuthenticationProviderException("Realm with id '" + realmId + "' doesn't exists");
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class ExternalModelAuthenticationProviderFactory implements Authenticatio
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthenticationProvider create(KeycloakSession session) {
|
public AuthenticationProvider create(KeycloakSession session) {
|
||||||
return new ExternalModelAuthenticationProvider();
|
return new ExternalModelAuthenticationProvider(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -41,11 +41,11 @@ public class ExportImportProviderImpl implements ExportImportProvider {
|
||||||
|
|
||||||
if (export) {
|
if (export) {
|
||||||
ExportWriter exportWriter = getProvider().getExportWriter();
|
ExportWriter exportWriter = getProvider().getExportWriter();
|
||||||
new ModelExporter().exportModel(session, exportWriter);
|
new ModelExporter().exportModel(session.getModel(), exportWriter);
|
||||||
logger.infof("Export finished successfully");
|
logger.infof("Export finished successfully");
|
||||||
} else {
|
} else {
|
||||||
ImportReader importReader = getProvider().getImportReader();
|
ImportReader importReader = getProvider().getImportReader();
|
||||||
new ModelImporter().importModel(session, importReader);
|
new ModelImporter().importModel(session.getModel(), importReader);
|
||||||
logger.infof("Import finished successfully");
|
logger.infof("Import finished successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.keycloak.models.AuthenticationLinkModel;
|
||||||
import org.keycloak.models.AuthenticationProviderModel;
|
import org.keycloak.models.AuthenticationProviderModel;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.OAuthClientModel;
|
import org.keycloak.models.OAuthClientModel;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RequiredCredentialModel;
|
import org.keycloak.models.RequiredCredentialModel;
|
||||||
|
@ -43,24 +44,24 @@ public class ModelExporter {
|
||||||
private ExportWriter exportWriter;
|
private ExportWriter exportWriter;
|
||||||
private ExportImportPropertiesManager propertiesManager;
|
private ExportImportPropertiesManager propertiesManager;
|
||||||
|
|
||||||
public void exportModel(KeycloakSession session, ExportWriter exportWriter) {
|
public void exportModel(ModelProvider model, ExportWriter exportWriter) {
|
||||||
// Initialize needed objects
|
// Initialize needed objects
|
||||||
this.exportWriter = exportWriter;
|
this.exportWriter = exportWriter;
|
||||||
this.propertiesManager = new ExportImportPropertiesManager();
|
this.propertiesManager = new ExportImportPropertiesManager();
|
||||||
|
|
||||||
// Create separate files for "realms", "applications", "oauthClients", "roles" and finally "users". Users may be done in more files (pagination)
|
// Create separate files for "realms", "applications", "oauthClients", "roles" and finally "users". Users may be done in more files (pagination)
|
||||||
exportRealms(session, "realms.json");
|
exportRealms(model, "realms.json");
|
||||||
exportApplications(session, "applications.json");
|
exportApplications(model, "applications.json");
|
||||||
exportOAuthClients(session, "oauthClients.json");
|
exportOAuthClients(model, "oauthClients.json");
|
||||||
exportRoles(session, "roles.json");
|
exportRoles(model, "roles.json");
|
||||||
exportUsers(session, "users.json");
|
exportUsers(model, "users.json");
|
||||||
exportUserFailures(session, "userFailures.json");
|
exportUserFailures(model, "userFailures.json");
|
||||||
|
|
||||||
this.exportWriter.closeExportWriter();
|
this.exportWriter.closeExportWriter();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void exportRealms(KeycloakSession session, String fileName) {
|
protected void exportRealms(ModelProvider model, String fileName) {
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = model.getRealms();
|
||||||
|
|
||||||
// Convert models to entities, which will be written into JSON file
|
// Convert models to entities, which will be written into JSON file
|
||||||
List<RealmEntity> result = new LinkedList<RealmEntity>();
|
List<RealmEntity> result = new LinkedList<RealmEntity>();
|
||||||
|
@ -106,8 +107,8 @@ public class ModelExporter {
|
||||||
logger.infof("Realms exported: " + result);
|
logger.infof("Realms exported: " + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void exportApplications(KeycloakSession session, String fileName) {
|
protected void exportApplications(ModelProvider model, String fileName) {
|
||||||
List<ApplicationModel> allApplications = getAllApplications(session);
|
List<ApplicationModel> allApplications = getAllApplications(model);
|
||||||
|
|
||||||
List<ApplicationEntity> result = new LinkedList<ApplicationEntity>();
|
List<ApplicationEntity> result = new LinkedList<ApplicationEntity>();
|
||||||
for (ApplicationModel appModel : allApplications) {
|
for (ApplicationModel appModel : allApplications) {
|
||||||
|
@ -129,8 +130,8 @@ public class ModelExporter {
|
||||||
logger.infof("Applications exported: " + result);
|
logger.infof("Applications exported: " + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void exportOAuthClients(KeycloakSession session, String fileName) {
|
protected void exportOAuthClients(ModelProvider model, String fileName) {
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = model.getRealms();
|
||||||
List<OAuthClientModel> allClients = new ArrayList<OAuthClientModel>();
|
List<OAuthClientModel> allClients = new ArrayList<OAuthClientModel>();
|
||||||
for (RealmModel realmModel : realms) {
|
for (RealmModel realmModel : realms) {
|
||||||
allClients.addAll(realmModel.getOAuthClients());
|
allClients.addAll(realmModel.getOAuthClients());
|
||||||
|
@ -156,8 +157,8 @@ public class ModelExporter {
|
||||||
logger.infof("OAuth clients exported: " + result);
|
logger.infof("OAuth clients exported: " + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void exportRoles(KeycloakSession session, String fileName) {
|
protected void exportRoles(ModelProvider model, String fileName) {
|
||||||
List<RoleModel> allRoles = getAllRoles(session);
|
List<RoleModel> allRoles = getAllRoles(model);
|
||||||
|
|
||||||
List<RoleEntity> result = new LinkedList<RoleEntity>();
|
List<RoleEntity> result = new LinkedList<RoleEntity>();
|
||||||
for (RoleModel roleModel : allRoles) {
|
for (RoleModel roleModel : allRoles) {
|
||||||
|
@ -198,8 +199,8 @@ public class ModelExporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void exportUsers(KeycloakSession session, String fileName) {
|
protected void exportUsers(ModelProvider model, String fileName) {
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = model.getRealms();
|
||||||
List<UserEntity> result = new LinkedList<UserEntity>();
|
List<UserEntity> result = new LinkedList<UserEntity>();
|
||||||
|
|
||||||
for (RealmModel realm : realms) {
|
for (RealmModel realm : realms) {
|
||||||
|
@ -277,8 +278,8 @@ public class ModelExporter {
|
||||||
|
|
||||||
|
|
||||||
// Does it makes sense to export user failures ?
|
// Does it makes sense to export user failures ?
|
||||||
protected void exportUserFailures(KeycloakSession session, String fileName) {
|
protected void exportUserFailures(ModelProvider model, String fileName) {
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = model.getRealms();
|
||||||
List<UsernameLoginFailureModel> allFailures = new ArrayList<UsernameLoginFailureModel>();
|
List<UsernameLoginFailureModel> allFailures = new ArrayList<UsernameLoginFailureModel>();
|
||||||
for (RealmModel realmModel : realms) {
|
for (RealmModel realmModel : realms) {
|
||||||
allFailures.addAll(realmModel.getAllUserLoginFailures());
|
allFailures.addAll(realmModel.getAllUserLoginFailures());
|
||||||
|
@ -306,8 +307,8 @@ public class ModelExporter {
|
||||||
return scopeIds;
|
return scopeIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ApplicationModel> getAllApplications(KeycloakSession session) {
|
private List<ApplicationModel> getAllApplications(ModelProvider model) {
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = model.getRealms();
|
||||||
List<ApplicationModel> allApplications = new ArrayList<ApplicationModel>();
|
List<ApplicationModel> allApplications = new ArrayList<ApplicationModel>();
|
||||||
for (RealmModel realmModel : realms) {
|
for (RealmModel realmModel : realms) {
|
||||||
allApplications.addAll(realmModel.getApplications());
|
allApplications.addAll(realmModel.getApplications());
|
||||||
|
@ -315,15 +316,15 @@ public class ModelExporter {
|
||||||
return allApplications;
|
return allApplications;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<RoleModel> getAllRoles(KeycloakSession session) {
|
private List<RoleModel> getAllRoles(ModelProvider model) {
|
||||||
List<RoleModel> allRoles = new ArrayList<RoleModel>();
|
List<RoleModel> allRoles = new ArrayList<RoleModel>();
|
||||||
|
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = model.getRealms();
|
||||||
for (RealmModel realmModel : realms) {
|
for (RealmModel realmModel : realms) {
|
||||||
allRoles.addAll(realmModel.getRoles());
|
allRoles.addAll(realmModel.getRoles());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ApplicationModel> allApplications = getAllApplications(session);
|
List<ApplicationModel> allApplications = getAllApplications(model);
|
||||||
for (ApplicationModel appModel : allApplications) {
|
for (ApplicationModel appModel : allApplications) {
|
||||||
allRoles.addAll(appModel.getRoles());
|
allRoles.addAll(appModel.getRoles());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.keycloak.models.AuthenticationProviderModel;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.Config;
|
import org.keycloak.Config;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.OAuthClientModel;
|
import org.keycloak.models.OAuthClientModel;
|
||||||
import org.keycloak.models.PasswordPolicy;
|
import org.keycloak.models.PasswordPolicy;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
|
@ -47,34 +48,31 @@ public class ModelImporter {
|
||||||
private ImportReader importReader;
|
private ImportReader importReader;
|
||||||
private ExportImportPropertiesManager propertiesManager;
|
private ExportImportPropertiesManager propertiesManager;
|
||||||
|
|
||||||
public void importModel(KeycloakSession session, ImportReader importReader) {
|
public void importModel(ModelProvider model, ImportReader importReader) {
|
||||||
// Initialize needed objects
|
// Initialize needed objects
|
||||||
this.importReader = importReader;
|
this.importReader = importReader;
|
||||||
this.propertiesManager = new ExportImportPropertiesManager();
|
this.propertiesManager = new ExportImportPropertiesManager();
|
||||||
|
|
||||||
// Delete all the data from current model
|
importRealms(model, "realms.json");
|
||||||
session.removeAllData();
|
importApplications(model, "applications.json");
|
||||||
|
importRoles(model, "roles.json");
|
||||||
importRealms(session, "realms.json");
|
|
||||||
importApplications(session, "applications.json");
|
|
||||||
importRoles(session, "roles.json");
|
|
||||||
|
|
||||||
// Now we have all realms,applications and roles filled. So fill other objects (default roles, scopes etc)
|
// Now we have all realms,applications and roles filled. So fill other objects (default roles, scopes etc)
|
||||||
importRealmsStep2(session, "realms.json");
|
importRealmsStep2(model, "realms.json");
|
||||||
importApplicationsStep2(session, "applications.json");
|
importApplicationsStep2(model, "applications.json");
|
||||||
|
|
||||||
importOAuthClients(session, "oauthClients.json");
|
importOAuthClients(model, "oauthClients.json");
|
||||||
importUsers(session, "users.json");
|
importUsers(model, "users.json");
|
||||||
importUserFailures(session, "userFailures.json");
|
importUserFailures(model, "userFailures.json");
|
||||||
|
|
||||||
this.importReader.closeImportReader();
|
this.importReader.closeImportReader();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void importRealms(KeycloakSession session, String fileName) {
|
protected void importRealms(ModelProvider model, String fileName) {
|
||||||
List<RealmEntity> realms = this.importReader.readEntities(fileName, RealmEntity.class);
|
List<RealmEntity> realms = this.importReader.readEntities(fileName, RealmEntity.class);
|
||||||
|
|
||||||
for (RealmEntity realmEntity : realms) {
|
for (RealmEntity realmEntity : realms) {
|
||||||
RealmModel realm = session.createRealm(realmEntity.getId(), realmEntity.getName());
|
RealmModel realm = model.createRealm(realmEntity.getId(), realmEntity.getName());
|
||||||
|
|
||||||
this.propertiesManager.setBasicPropertiesToModel(realm, realmEntity);
|
this.propertiesManager.setBasicPropertiesToModel(realm, realmEntity);
|
||||||
|
|
||||||
|
@ -103,10 +101,10 @@ public class ModelImporter {
|
||||||
logger.infof("Realms imported: " + realms);
|
logger.infof("Realms imported: " + realms);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void importApplications(KeycloakSession session, String fileName) {
|
protected void importApplications(ModelProvider model, String fileName) {
|
||||||
List<ApplicationEntity> apps = this.importReader.readEntities(fileName, ApplicationEntity.class);
|
List<ApplicationEntity> apps = this.importReader.readEntities(fileName, ApplicationEntity.class);
|
||||||
for (ApplicationEntity appEntity : apps) {
|
for (ApplicationEntity appEntity : apps) {
|
||||||
RealmModel realm = session.getRealm(appEntity.getRealmId());
|
RealmModel realm = model.getRealm(appEntity.getRealmId());
|
||||||
ApplicationModel app = realm.addApplication(appEntity.getId(), appEntity.getName());
|
ApplicationModel app = realm.addApplication(appEntity.getId(), appEntity.getName());
|
||||||
|
|
||||||
this.propertiesManager.setBasicPropertiesToModel(app , appEntity);
|
this.propertiesManager.setBasicPropertiesToModel(app , appEntity);
|
||||||
|
@ -117,7 +115,7 @@ public class ModelImporter {
|
||||||
logger.infof("Applications imported: " + apps);
|
logger.infof("Applications imported: " + apps);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void importRoles(KeycloakSession session, String fileName) {
|
protected void importRoles(ModelProvider model, String fileName) {
|
||||||
// helper map for composite roles
|
// helper map for composite roles
|
||||||
Map<String, RoleEntity> rolesMap = new HashMap<String, RoleEntity>();
|
Map<String, RoleEntity> rolesMap = new HashMap<String, RoleEntity>();
|
||||||
|
|
||||||
|
@ -125,10 +123,10 @@ public class ModelImporter {
|
||||||
for (RoleEntity roleEntity : roles) {
|
for (RoleEntity roleEntity : roles) {
|
||||||
RoleModel role = null;
|
RoleModel role = null;
|
||||||
if (roleEntity.getRealmId() != null) {
|
if (roleEntity.getRealmId() != null) {
|
||||||
RealmModel realm = session.getRealm(roleEntity.getRealmId());
|
RealmModel realm = model.getRealm(roleEntity.getRealmId());
|
||||||
role = realm.addRole(roleEntity.getId(), roleEntity.getName());
|
role = realm.addRole(roleEntity.getId(), roleEntity.getName());
|
||||||
} else if (roleEntity.getApplicationId() != null) {
|
} else if (roleEntity.getApplicationId() != null) {
|
||||||
ApplicationModel app = findApplicationById(session, roleEntity.getApplicationId());
|
ApplicationModel app = findApplicationById(model, roleEntity.getApplicationId());
|
||||||
role = app.addRole(roleEntity.getId(), roleEntity.getName());
|
role = app.addRole(roleEntity.getId(), roleEntity.getName());
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Role " + roleEntity.getId() + " doesn't have realmId nor applicationId");
|
throw new IllegalStateException("Role " + roleEntity.getId() + " doesn't have realmId nor applicationId");
|
||||||
|
@ -140,7 +138,7 @@ public class ModelImporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// All roles were added. Fill composite roles now
|
// All roles were added. Fill composite roles now
|
||||||
for (RealmModel realm : session.getRealms()) {
|
for (RealmModel realm : model.getRealms()) {
|
||||||
|
|
||||||
// realm roles
|
// realm roles
|
||||||
fillCompositeRoles(rolesMap, realm, realm);
|
fillCompositeRoles(rolesMap, realm, realm);
|
||||||
|
@ -172,12 +170,12 @@ public class ModelImporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void importRealmsStep2(KeycloakSession session, String fileName) {
|
protected void importRealmsStep2(ModelProvider model, String fileName) {
|
||||||
List<RealmEntity> realms = this.importReader.readEntities(fileName, RealmEntity.class);
|
List<RealmEntity> realms = this.importReader.readEntities(fileName, RealmEntity.class);
|
||||||
RealmModel adminRealm = session.getRealm(Config.getAdminRealm());
|
RealmModel adminRealm = model.getRealm(Config.getAdminRealm());
|
||||||
|
|
||||||
for (RealmEntity realmEntity : realms) {
|
for (RealmEntity realmEntity : realms) {
|
||||||
RealmModel realm = session.getRealm(realmEntity.getId());
|
RealmModel realm = model.getRealm(realmEntity.getId());
|
||||||
|
|
||||||
// admin app
|
// admin app
|
||||||
String adminAppId = realmEntity.getAdminAppId();
|
String adminAppId = realmEntity.getAdminAppId();
|
||||||
|
@ -190,10 +188,10 @@ public class ModelImporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void importApplicationsStep2(KeycloakSession session, String fileName) {
|
protected void importApplicationsStep2(ModelProvider model, String fileName) {
|
||||||
List<ApplicationEntity> apps = this.importReader.readEntities(fileName, ApplicationEntity.class);
|
List<ApplicationEntity> apps = this.importReader.readEntities(fileName, ApplicationEntity.class);
|
||||||
for (ApplicationEntity appEntity : apps) {
|
for (ApplicationEntity appEntity : apps) {
|
||||||
RealmModel realm = session.getRealm(appEntity.getRealmId());
|
RealmModel realm = model.getRealm(appEntity.getRealmId());
|
||||||
ApplicationModel application = realm.getApplicationById(appEntity.getId());
|
ApplicationModel application = realm.getApplicationById(appEntity.getId());
|
||||||
|
|
||||||
// Default roles
|
// Default roles
|
||||||
|
@ -211,10 +209,10 @@ public class ModelImporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void importOAuthClients(KeycloakSession session, String fileName) {
|
protected void importOAuthClients(ModelProvider model, String fileName) {
|
||||||
List<OAuthClientEntity> clients = this.importReader.readEntities(fileName, OAuthClientEntity.class);
|
List<OAuthClientEntity> clients = this.importReader.readEntities(fileName, OAuthClientEntity.class);
|
||||||
for (OAuthClientEntity clientEntity : clients) {
|
for (OAuthClientEntity clientEntity : clients) {
|
||||||
RealmModel realm = session.getRealm(clientEntity.getRealmId());
|
RealmModel realm = model.getRealm(clientEntity.getRealmId());
|
||||||
OAuthClientModel client = realm.addOAuthClient(clientEntity.getId(), clientEntity.getName());
|
OAuthClientModel client = realm.addOAuthClient(clientEntity.getId(), clientEntity.getName());
|
||||||
|
|
||||||
this.propertiesManager.setBasicPropertiesToModel(client, clientEntity);
|
this.propertiesManager.setBasicPropertiesToModel(client, clientEntity);
|
||||||
|
@ -228,8 +226,8 @@ public class ModelImporter {
|
||||||
logger.info("OAuth clients imported: " + clients);
|
logger.info("OAuth clients imported: " + clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ApplicationModel findApplicationById(KeycloakSession session, String applicationId) {
|
protected ApplicationModel findApplicationById(ModelProvider model, String applicationId) {
|
||||||
for (RealmModel realm : session.getRealms()) {
|
for (RealmModel realm : model.getRealms()) {
|
||||||
ApplicationModel appModel = realm.getApplicationById(applicationId);
|
ApplicationModel appModel = realm.getApplicationById(applicationId);
|
||||||
if (appModel != null) {
|
if (appModel != null) {
|
||||||
return appModel;
|
return appModel;
|
||||||
|
@ -239,10 +237,10 @@ public class ModelImporter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importUsers(KeycloakSession session, String fileName) {
|
public void importUsers(ModelProvider model, String fileName) {
|
||||||
List<UserEntity> users = this.importReader.readEntities(fileName, UserEntity.class);
|
List<UserEntity> users = this.importReader.readEntities(fileName, UserEntity.class);
|
||||||
for (UserEntity userEntity : users) {
|
for (UserEntity userEntity : users) {
|
||||||
RealmModel realm = session.getRealm(userEntity.getRealmId());
|
RealmModel realm = model.getRealm(userEntity.getRealmId());
|
||||||
UserModel user = realm.addUser(userEntity.getId(), userEntity.getUsername(), false);
|
UserModel user = realm.addUser(userEntity.getId(), userEntity.getUsername(), false);
|
||||||
|
|
||||||
// We need to remove defaultRoles here as realm.addUser is automatically adding them. We may add them later during roles mapping processing
|
// We need to remove defaultRoles here as realm.addUser is automatically adding them. We may add them later during roles mapping processing
|
||||||
|
@ -313,16 +311,16 @@ public class ModelImporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importUserFailures(KeycloakSession session, String fileName) {
|
public void importUserFailures(ModelProvider model, String fileName) {
|
||||||
List<UsernameLoginFailureEntity> userFailures = this.importReader.readEntities(fileName, UsernameLoginFailureEntity.class);
|
List<UsernameLoginFailureEntity> userFailures = this.importReader.readEntities(fileName, UsernameLoginFailureEntity.class);
|
||||||
for (UsernameLoginFailureEntity entity : userFailures) {
|
for (UsernameLoginFailureEntity entity : userFailures) {
|
||||||
RealmModel realm = session.getRealm(entity.getRealmId());
|
RealmModel realm = model.getRealm(entity.getRealmId());
|
||||||
UsernameLoginFailureModel model = realm.addUserLoginFailure(entity.getUsername());
|
UsernameLoginFailureModel loginFailureModel = realm.addUserLoginFailure(entity.getUsername());
|
||||||
|
|
||||||
this.propertiesManager.setBasicPropertiesToModel(model , entity);
|
this.propertiesManager.setBasicPropertiesToModel(loginFailureModel , entity);
|
||||||
|
|
||||||
for (int i=0 ; i<entity.getNumFailures() ; i++) {
|
for (int i=0 ; i<entity.getNumFailures() ; i++) {
|
||||||
model.incrementFailures();
|
loginFailureModel.incrementFailures();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public abstract class ExportImportTestBase {
|
||||||
exportModel(factory);
|
exportModel(factory);
|
||||||
|
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
realm = session.getRealm("demo");
|
realm = session.getModel().getRealm("demo");
|
||||||
String wburkeId = realm.getUser("wburke").getId();
|
String wburkeId = realm.getUser("wburke").getId();
|
||||||
String appId = realm.getApplicationByName("Application").getId();
|
String appId = realm.getApplicationByName("Application").getId();
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public abstract class ExportImportTestBase {
|
||||||
|
|
||||||
// Verify it's imported in mongo (reusing ImportTest)
|
// Verify it's imported in mongo (reusing ImportTest)
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
RealmModel importedRealm = session.getRealm("demo");
|
RealmModel importedRealm = session.getModel().getRealm("demo");
|
||||||
System.out.println("Exported realm: " + realm + ", Imported realm: " + importedRealm);
|
System.out.println("Exported realm: " + realm + ", Imported realm: " + importedRealm);
|
||||||
|
|
||||||
Assert.assertEquals(wburkeId, importedRealm.getUser("wburke").getId());
|
Assert.assertEquals(wburkeId, importedRealm.getUser("wburke").getId());
|
||||||
|
|
|
@ -23,45 +23,8 @@ public interface KeycloakSession {
|
||||||
|
|
||||||
<T extends Provider> Set<T> getAllProviders(Class<T> clazz);
|
<T extends Provider> Set<T> getAllProviders(Class<T> clazz);
|
||||||
|
|
||||||
RealmModel createRealm(String name);
|
ModelProvider getModel();
|
||||||
RealmModel createRealm(String id, String name);
|
|
||||||
RealmModel getRealm(String id);
|
|
||||||
RealmModel getRealmByName(String name);
|
|
||||||
|
|
||||||
UserModel getUserById(String id, RealmModel realm);
|
|
||||||
UserModel getUserByUsername(String username, RealmModel realm);
|
|
||||||
UserModel getUserByEmail(String email, RealmModel realm);
|
|
||||||
UserModel getUserBySocialLink(SocialLinkModel socialLink, RealmModel realm);
|
|
||||||
List<UserModel> getUsers(RealmModel realm);
|
|
||||||
List<UserModel> searchForUser(String search, RealmModel realm);
|
|
||||||
List<UserModel> searchForUserByAttributes(Map<String, String> attributes, RealmModel realm);
|
|
||||||
|
|
||||||
Set<SocialLinkModel> getSocialLinks(UserModel user, RealmModel realm);
|
|
||||||
SocialLinkModel getSocialLink(UserModel user, String socialProvider, RealmModel realm);
|
|
||||||
|
|
||||||
|
|
||||||
RoleModel getRoleById(String id, RealmModel realm);
|
|
||||||
ApplicationModel getApplicationById(String id, RealmModel realm);
|
|
||||||
OAuthClientModel getOAuthClientById(String id, RealmModel realm);
|
|
||||||
List<RealmModel> getRealms();
|
|
||||||
boolean removeRealm(String id);
|
|
||||||
|
|
||||||
UsernameLoginFailureModel getUserLoginFailure(String username, RealmModel realm);
|
|
||||||
UsernameLoginFailureModel addUserLoginFailure(String username, RealmModel realm);
|
|
||||||
List<UsernameLoginFailureModel> getAllUserLoginFailures(RealmModel realm);
|
|
||||||
|
|
||||||
UserSessionModel createUserSession(RealmModel realm, UserModel user, String ipAddress);
|
|
||||||
UserSessionModel getUserSession(String id, RealmModel realm);
|
|
||||||
List<UserSessionModel> getUserSessions(UserModel user, RealmModel realm);
|
|
||||||
Set<UserSessionModel> getUserSessions(RealmModel realm, ClientModel client);
|
|
||||||
int getActiveUserSessions(RealmModel realm, ClientModel client);
|
|
||||||
void removeUserSession(UserSessionModel session);
|
|
||||||
void removeUserSessions(RealmModel realm, UserModel user);
|
|
||||||
void removeExpiredUserSessions(RealmModel realm);
|
|
||||||
void removeUserSessions(RealmModel realm);
|
|
||||||
|
|
||||||
|
|
||||||
void removeAllData();
|
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,5 @@ public interface ModelProvider extends Provider {
|
||||||
void removeExpiredUserSessions(RealmModel realm);
|
void removeExpiredUserSessions(RealmModel realm);
|
||||||
void removeUserSessions(RealmModel realm);
|
void removeUserSessions(RealmModel realm);
|
||||||
|
|
||||||
|
|
||||||
void removeAllData();
|
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,10 +245,6 @@ public class HybridModelProvider implements ModelProvider {
|
||||||
sessions().removeUserSessions(realm.getId());
|
sessions().removeUserSessions(realm.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAllData() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,13 +291,6 @@ public class DefaultCacheModelProvider implements CacheModelProvider {
|
||||||
return didIt;
|
return didIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAllData() {
|
|
||||||
cache.clear();
|
|
||||||
getDelegate().removeAllData();
|
|
||||||
clearAll = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (delegate != null) delegate.close();
|
if (delegate != null) delegate.close();
|
||||||
|
|
|
@ -156,11 +156,6 @@ public class NoCacheModelProvider implements CacheModelProvider {
|
||||||
return getDelegate().removeRealm(id);
|
return getDelegate().removeRealm(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAllData() {
|
|
||||||
getDelegate().removeAllData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (delegate != null) delegate.close();
|
if (delegate != null) delegate.close();
|
||||||
|
|
|
@ -144,15 +144,6 @@ public class JpaModelProvider implements ModelProvider {
|
||||||
if (em.isOpen()) em.close();
|
if (em.isOpen()) em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAllData() {
|
|
||||||
// Should be sufficient to delete all realms. Rest data should be removed in cascade
|
|
||||||
List<RealmModel> realms = getRealms();
|
|
||||||
for (RealmModel realm : realms) {
|
|
||||||
removeRealm(realm.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUserBySocialLink(SocialLinkModel socialLink, RealmModel realm) {
|
public UserModel getUserBySocialLink(SocialLinkModel socialLink, RealmModel realm) {
|
||||||
TypedQuery<UserEntity> query = em.createNamedQuery("findUserByLinkAndRealm", UserEntity.class);
|
TypedQuery<UserEntity> query = em.createNamedQuery("findUserByLinkAndRealm", UserEntity.class);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.CredentialValidation;
|
import org.keycloak.models.CredentialValidation;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.ModelDuplicateException;
|
import org.keycloak.models.ModelDuplicateException;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.RoleContainerModel;
|
import org.keycloak.models.RoleContainerModel;
|
||||||
import org.keycloak.models.UserCredentialValueModel;
|
import org.keycloak.models.UserCredentialValueModel;
|
||||||
import org.keycloak.models.UserSessionModel;
|
import org.keycloak.models.UserSessionModel;
|
||||||
|
@ -66,10 +67,12 @@ public class RealmAdapter implements RealmModel {
|
||||||
protected volatile transient PublicKey publicKey;
|
protected volatile transient PublicKey publicKey;
|
||||||
protected volatile transient PrivateKey privateKey;
|
protected volatile transient PrivateKey privateKey;
|
||||||
protected KeycloakSession session;
|
protected KeycloakSession session;
|
||||||
|
protected ModelProvider model;
|
||||||
private PasswordPolicy passwordPolicy;
|
private PasswordPolicy passwordPolicy;
|
||||||
|
|
||||||
public RealmAdapter(KeycloakSession session, EntityManager em, RealmEntity realm) {
|
public RealmAdapter(KeycloakSession session, EntityManager em, RealmEntity realm) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
this.model = session.getModel();
|
||||||
this.em = em;
|
this.em = em;
|
||||||
this.realm = realm;
|
this.realm = realm;
|
||||||
}
|
}
|
||||||
|
@ -426,32 +429,32 @@ public class RealmAdapter implements RealmModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUser(String name) {
|
public UserModel getUser(String name) {
|
||||||
return session.getUserByUsername(name, this);
|
return model.getUserByUsername(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UsernameLoginFailureModel getUserLoginFailure(String username) {
|
public UsernameLoginFailureModel getUserLoginFailure(String username) {
|
||||||
return session.getUserLoginFailure(username, this);
|
return model.getUserLoginFailure(username, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UsernameLoginFailureModel addUserLoginFailure(String username) {
|
public UsernameLoginFailureModel addUserLoginFailure(String username) {
|
||||||
return session.addUserLoginFailure(username, this);
|
return model.addUserLoginFailure(username, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UsernameLoginFailureModel> getAllUserLoginFailures() {
|
public List<UsernameLoginFailureModel> getAllUserLoginFailures() {
|
||||||
return session.getAllUserLoginFailures(this);
|
return model.getAllUserLoginFailures(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUserByEmail(String email) {
|
public UserModel getUserByEmail(String email) {
|
||||||
return session.getUserByEmail(email, this);
|
return model.getUserByEmail(email, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUserById(String id) {
|
public UserModel getUserById(String id) {
|
||||||
return session.getUserById(id, this);
|
return model.getUserById(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -661,7 +664,7 @@ public class RealmAdapter implements RealmModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApplicationModel getApplicationById(String id) {
|
public ApplicationModel getApplicationById(String id) {
|
||||||
return session.getApplicationById(id, this);
|
return model.getApplicationById(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -671,17 +674,17 @@ public class RealmAdapter implements RealmModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUserBySocialLink(SocialLinkModel socialLink) {
|
public UserModel getUserBySocialLink(SocialLinkModel socialLink) {
|
||||||
return session.getUserBySocialLink(socialLink, this);
|
return model.getUserBySocialLink(socialLink, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<SocialLinkModel> getSocialLinks(UserModel user) {
|
public Set<SocialLinkModel> getSocialLinks(UserModel user) {
|
||||||
return session.getSocialLinks(user, this);
|
return model.getSocialLinks(user, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SocialLinkModel getSocialLink(UserModel user, String socialProvider) {
|
public SocialLinkModel getSocialLink(UserModel user, String socialProvider) {
|
||||||
return session.getSocialLink(user, socialProvider, this);
|
return model.getSocialLink(user, socialProvider, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -744,17 +747,17 @@ public class RealmAdapter implements RealmModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserModel> getUsers() {
|
public List<UserModel> getUsers() {
|
||||||
return session.getUsers(this);
|
return model.getUsers(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserModel> searchForUser(String search) {
|
public List<UserModel> searchForUser(String search) {
|
||||||
return session.searchForUser(search, this);
|
return model.searchForUser(search, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserModel> searchForUserByAttributes(Map<String, String> attributes) {
|
public List<UserModel> searchForUserByAttributes(Map<String, String> attributes) {
|
||||||
return session.searchForUserByAttributes(attributes, this);
|
return model.searchForUserByAttributes(attributes, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -798,7 +801,7 @@ public class RealmAdapter implements RealmModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OAuthClientModel getOAuthClientById(String id) {
|
public OAuthClientModel getOAuthClientById(String id) {
|
||||||
return session.getOAuthClientById(id, this);
|
return model.getOAuthClientById(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -960,7 +963,7 @@ public class RealmAdapter implements RealmModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RoleModel getRoleById(String id) {
|
public RoleModel getRoleById(String id) {
|
||||||
return session.getRoleById(id, this);
|
return model.getRoleById(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1105,38 +1108,38 @@ public class RealmAdapter implements RealmModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserSessionModel createUserSession(UserModel user, String ipAddress) {
|
public UserSessionModel createUserSession(UserModel user, String ipAddress) {
|
||||||
return session.createUserSession(this, user, ipAddress);
|
return model.createUserSession(this, user, ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserSessionModel getUserSession(String id) {
|
public UserSessionModel getUserSession(String id) {
|
||||||
return session.getUserSession(id, this);
|
return model.getUserSession(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserSessionModel> getUserSessions(UserModel user) {
|
public List<UserSessionModel> getUserSessions(UserModel user) {
|
||||||
return session.getUserSessions(user, this);
|
return model.getUserSessions(user, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUserSession(UserSessionModel session) {
|
public void removeUserSession(UserSessionModel session) {
|
||||||
this.session.removeUserSession(session);
|
this.model.removeUserSession(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUserSessions() {
|
public void removeUserSessions() {
|
||||||
session.removeUserSessions(this);
|
model.removeUserSessions(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUserSessions(UserModel user) {
|
public void removeUserSessions(UserModel user) {
|
||||||
session.removeUserSessions(this, user);
|
model.removeUserSessions(this, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeExpiredUserSessions() {
|
public void removeExpiredUserSessions() {
|
||||||
session.removeExpiredUserSessions(this);
|
model.removeExpiredUserSessions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,4 @@ public interface MongoStore {
|
||||||
|
|
||||||
<S> boolean pullItemFromList(MongoIdentifiableEntity entity, String listPropertyName, S itemToPull, MongoStoreInvocationContext context);
|
<S> boolean pullItemFromList(MongoIdentifiableEntity entity, String listPropertyName, S itemToPull, MongoStoreInvocationContext context);
|
||||||
|
|
||||||
/**
|
|
||||||
* Completely remove all data from DB
|
|
||||||
*/
|
|
||||||
void removeAllEntities();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,13 +417,6 @@ public class MongoStoreImpl implements MongoStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAllEntities() {
|
|
||||||
Set<Class<?>> managedTypes = this.entityInfoCache.keySet();
|
|
||||||
Class<? extends MongoEntity>[] arrayTemplate = (Class<? extends MongoEntity>[])new Class<?>[0];
|
|
||||||
this.clearManagedCollections(managedTypes.toArray(arrayTemplate));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Possibility to add user-defined mappers
|
// Possibility to add user-defined mappers
|
||||||
public void addAppObjectConverter(Mapper<?, ?> mapper) {
|
public void addAppObjectConverter(Mapper<?, ?> mapper) {
|
||||||
mapperRegistry.addAppObjectMapper(mapper);
|
mapperRegistry.addAppObjectMapper(mapper);
|
||||||
|
|
|
@ -7,8 +7,6 @@ import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.models.UserModel;
|
|
||||||
import org.keycloak.models.UserSessionModel;
|
|
||||||
import org.keycloak.models.mongo.api.context.MongoStoreInvocationContext;
|
import org.keycloak.models.mongo.api.context.MongoStoreInvocationContext;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
import org.keycloak.models.mongo.keycloak.entities.MongoApplicationEntity;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
package org.keycloak.models.mongo.keycloak.adapters;
|
package org.keycloak.models.mongo.keycloak.adapters;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.QueryBuilder;
|
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.models.UserSessionModel;
|
import org.keycloak.models.UserSessionModel;
|
||||||
|
@ -16,9 +10,13 @@ import org.keycloak.models.entities.ClientEntity;
|
||||||
import org.keycloak.models.mongo.api.MongoIdentifiableEntity;
|
import org.keycloak.models.mongo.api.MongoIdentifiableEntity;
|
||||||
import org.keycloak.models.mongo.api.context.MongoStoreInvocationContext;
|
import org.keycloak.models.mongo.api.context.MongoStoreInvocationContext;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoUserSessionEntity;
|
|
||||||
import org.keycloak.models.mongo.utils.MongoModelUtils;
|
import org.keycloak.models.mongo.utils.MongoModelUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||||
*/
|
*/
|
||||||
|
@ -27,12 +25,14 @@ public abstract class ClientAdapter<T extends MongoIdentifiableEntity> extends A
|
||||||
protected final T clientEntity;
|
protected final T clientEntity;
|
||||||
private final RealmModel realm;
|
private final RealmModel realm;
|
||||||
protected KeycloakSession session;
|
protected KeycloakSession session;
|
||||||
|
private final ModelProvider model;
|
||||||
|
|
||||||
public ClientAdapter(KeycloakSession session, RealmModel realm, T clientEntity, MongoStoreInvocationContext invContext) {
|
public ClientAdapter(KeycloakSession session, RealmModel realm, T clientEntity, MongoStoreInvocationContext invContext) {
|
||||||
super(invContext);
|
super(invContext);
|
||||||
this.clientEntity = clientEntity;
|
this.clientEntity = clientEntity;
|
||||||
this.realm = realm;
|
this.realm = realm;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
this.model = session.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -176,12 +176,12 @@ public abstract class ClientAdapter<T extends MongoIdentifiableEntity> extends A
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UserSessionModel> getUserSessions() {
|
public Set<UserSessionModel> getUserSessions() {
|
||||||
return session.getUserSessions(realm, this);
|
return model.getUserSessions(realm, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getActiveUserSessions() {
|
public int getActiveUserSessions() {
|
||||||
return session.getActiveUserSessions(realm, this);
|
return model.getActiveUserSessions(realm, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -67,11 +67,6 @@ public class MongoModelProvider implements ModelProvider {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAllData() {
|
|
||||||
getMongoStore().removeAllEntities();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RealmModel createRealm(String name) {
|
public RealmModel createRealm(String name) {
|
||||||
return createRealm(KeycloakModelUtils.generateId(), name);
|
return createRealm(KeycloakModelUtils.generateId(), name);
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package org.keycloak.models.mongo.keycloak.adapters;
|
package org.keycloak.models.mongo.keycloak.adapters;
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
import com.mongodb.QueryBuilder;
|
import com.mongodb.QueryBuilder;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
import org.keycloak.models.ApplicationModel;
|
import org.keycloak.models.ApplicationModel;
|
||||||
import org.keycloak.models.AuthenticationLinkModel;
|
|
||||||
import org.keycloak.models.AuthenticationProviderModel;
|
import org.keycloak.models.AuthenticationProviderModel;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.CredentialValidation;
|
import org.keycloak.models.CredentialValidation;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.OAuthClientModel;
|
import org.keycloak.models.OAuthClientModel;
|
||||||
import org.keycloak.models.PasswordPolicy;
|
import org.keycloak.models.PasswordPolicy;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
|
@ -21,9 +20,7 @@ import org.keycloak.models.UserCredentialValueModel;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.models.UserSessionModel;
|
import org.keycloak.models.UserSessionModel;
|
||||||
import org.keycloak.models.UsernameLoginFailureModel;
|
import org.keycloak.models.UsernameLoginFailureModel;
|
||||||
import org.keycloak.models.entities.AuthenticationLinkEntity;
|
|
||||||
import org.keycloak.models.entities.AuthenticationProviderEntity;
|
import org.keycloak.models.entities.AuthenticationProviderEntity;
|
||||||
import org.keycloak.models.entities.CredentialEntity;
|
|
||||||
import org.keycloak.models.entities.RequiredCredentialEntity;
|
import org.keycloak.models.entities.RequiredCredentialEntity;
|
||||||
import org.keycloak.models.entities.SocialLinkEntity;
|
import org.keycloak.models.entities.SocialLinkEntity;
|
||||||
import org.keycloak.models.mongo.api.context.MongoStoreInvocationContext;
|
import org.keycloak.models.mongo.api.context.MongoStoreInvocationContext;
|
||||||
|
@ -32,13 +29,8 @@ import org.keycloak.models.mongo.keycloak.entities.MongoOAuthClientEntity;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoRealmEntity;
|
import org.keycloak.models.mongo.keycloak.entities.MongoRealmEntity;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
import org.keycloak.models.mongo.keycloak.entities.MongoRoleEntity;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoUserEntity;
|
import org.keycloak.models.mongo.keycloak.entities.MongoUserEntity;
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoUserSessionEntity;
|
|
||||||
import org.keycloak.models.mongo.keycloak.entities.MongoUsernameLoginFailureEntity;
|
|
||||||
import org.keycloak.models.mongo.utils.MongoModelUtils;
|
|
||||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||||
import org.keycloak.models.utils.Pbkdf2PasswordEncoder;
|
|
||||||
import org.keycloak.models.utils.TimeBasedOTP;
|
import org.keycloak.models.utils.TimeBasedOTP;
|
||||||
import org.keycloak.util.Time;
|
|
||||||
|
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
|
@ -47,11 +39,9 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||||
|
@ -61,6 +51,7 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
private static final Logger logger = Logger.getLogger(RealmAdapter.class);
|
private static final Logger logger = Logger.getLogger(RealmAdapter.class);
|
||||||
|
|
||||||
private final MongoRealmEntity realm;
|
private final MongoRealmEntity realm;
|
||||||
|
private final ModelProvider model;
|
||||||
|
|
||||||
protected volatile transient PublicKey publicKey;
|
protected volatile transient PublicKey publicKey;
|
||||||
protected volatile transient PrivateKey privateKey;
|
protected volatile transient PrivateKey privateKey;
|
||||||
|
@ -72,6 +63,7 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
super(invocationContext);
|
super(invocationContext);
|
||||||
this.realm = realmEntity;
|
this.realm = realmEntity;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
this.model = session.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -450,33 +442,33 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUser(String name) {
|
public UserModel getUser(String name) {
|
||||||
return session.getUserByUsername(name, this);
|
return model.getUserByUsername(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UsernameLoginFailureModel getUserLoginFailure(String name) {
|
public UsernameLoginFailureModel getUserLoginFailure(String name) {
|
||||||
return session.getUserLoginFailure(name, this);
|
return model.getUserLoginFailure(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UsernameLoginFailureModel addUserLoginFailure(String username) {
|
public UsernameLoginFailureModel addUserLoginFailure(String username) {
|
||||||
return session.addUserLoginFailure(username, this);
|
return model.addUserLoginFailure(username, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UsernameLoginFailureModel> getAllUserLoginFailures() {
|
public List<UsernameLoginFailureModel> getAllUserLoginFailures() {
|
||||||
return session.getAllUserLoginFailures(this);
|
return model.getAllUserLoginFailures(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUserByEmail(String email) {
|
public UserModel getUserByEmail(String email) {
|
||||||
return session.getUserByEmail(email, this);
|
return model.getUserByEmail(email, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUserById(String id) {
|
public UserModel getUserById(String id) {
|
||||||
return session.getUserById(id, this);
|
return model.getUserById(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -584,7 +576,7 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RoleModel getRoleById(String id) {
|
public RoleModel getRoleById(String id) {
|
||||||
return session.getRoleById(id, this);
|
return model.getRoleById(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -636,7 +628,7 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApplicationModel getApplicationById(String id) {
|
public ApplicationModel getApplicationById(String id) {
|
||||||
return session.getApplicationById(id, this);
|
return model.getApplicationById(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -727,7 +719,7 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OAuthClientModel getOAuthClientById(String id) {
|
public OAuthClientModel getOAuthClientById(String id) {
|
||||||
return session.getOAuthClientById(id, this);
|
return model.getOAuthClientById(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -830,17 +822,17 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserModel getUserBySocialLink(SocialLinkModel socialLink) {
|
public UserModel getUserBySocialLink(SocialLinkModel socialLink) {
|
||||||
return session.getUserBySocialLink(socialLink, this);
|
return model.getUserBySocialLink(socialLink, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<SocialLinkModel> getSocialLinks(UserModel user) {
|
public Set<SocialLinkModel> getSocialLinks(UserModel user) {
|
||||||
return session.getSocialLinks(user, this);
|
return model.getSocialLinks(user, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SocialLinkModel getSocialLink(UserModel user, String socialProvider) {
|
public SocialLinkModel getSocialLink(UserModel user, String socialProvider) {
|
||||||
return session.getSocialLink(user, socialProvider, this);
|
return model.getSocialLink(user, socialProvider, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -893,18 +885,18 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserModel> getUsers() {
|
public List<UserModel> getUsers() {
|
||||||
return session.getUsers(this);
|
return model.getUsers(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserModel> searchForUser(String search) {
|
public List<UserModel> searchForUser(String search) {
|
||||||
return session.searchForUser(search, this);
|
return model.searchForUser(search, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserModel> searchForUserByAttributes(Map<String, String> attributes) {
|
public List<UserModel> searchForUserByAttributes(Map<String, String> attributes) {
|
||||||
return session.searchForUserByAttributes(attributes, this);
|
return model.searchForUserByAttributes(attributes, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1023,37 +1015,37 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserSessionModel createUserSession(UserModel user, String ipAddress) {
|
public UserSessionModel createUserSession(UserModel user, String ipAddress) {
|
||||||
return session.createUserSession(this, user, ipAddress);
|
return model.createUserSession(this, user, ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserSessionModel getUserSession(String id) {
|
public UserSessionModel getUserSession(String id) {
|
||||||
return session.getUserSession(id, this);
|
return model.getUserSession(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserSessionModel> getUserSessions(UserModel user) {
|
public List<UserSessionModel> getUserSessions(UserModel user) {
|
||||||
return session.getUserSessions(user, this);
|
return model.getUserSessions(user, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUserSession(UserSessionModel session) {
|
public void removeUserSession(UserSessionModel session) {
|
||||||
this.session.removeUserSession(session);
|
this.model.removeUserSession(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUserSessions(UserModel user) {
|
public void removeUserSessions(UserModel user) {
|
||||||
this.session.removeUserSessions(this, user);
|
this.model.removeUserSessions(this, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUserSessions() {
|
public void removeUserSessions() {
|
||||||
this.session.removeUserSessions(this);
|
this.model.removeUserSessions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeExpiredUserSessions() {
|
public void removeExpiredUserSessions() {
|
||||||
this.session.removeExpiredUserSessions(this);
|
this.model.removeExpiredUserSessions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.junit.BeforeClass;
|
||||||
import org.keycloak.Config;
|
import org.keycloak.Config;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.KeycloakSessionFactory;
|
import org.keycloak.models.KeycloakSessionFactory;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.representations.idm.RealmRepresentation;
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
|
@ -30,6 +31,7 @@ public class AbstractModelTest {
|
||||||
|
|
||||||
protected KeycloakSession session;
|
protected KeycloakSession session;
|
||||||
protected RealmManager realmManager;
|
protected RealmManager realmManager;
|
||||||
|
protected ModelProvider model;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
|
@ -54,6 +56,7 @@ public class AbstractModelTest {
|
||||||
public void before() throws Exception {
|
public void before() throws Exception {
|
||||||
session = sessionFactory.create();
|
session = sessionFactory.create();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
model = session.getModel();
|
||||||
realmManager = new RealmManager(session);
|
realmManager = new RealmManager(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +68,10 @@ public class AbstractModelTest {
|
||||||
session = sessionFactory.create();
|
session = sessionFactory.create();
|
||||||
try {
|
try {
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
model = session.getModel();
|
||||||
|
|
||||||
RealmManager rm = new RealmManager(session);
|
RealmManager rm = new RealmManager(session);
|
||||||
for (RealmModel realm : session.getRealms()) {
|
for (RealmModel realm : model.getRealms()) {
|
||||||
if (!realm.getName().equals(Config.getAdminRealm())) {
|
if (!realm.getName().equals(Config.getAdminRealm())) {
|
||||||
rm.removeRealm(realm);
|
rm.removeRealm(realm);
|
||||||
}
|
}
|
||||||
|
@ -98,6 +102,7 @@ public class AbstractModelTest {
|
||||||
|
|
||||||
session = sessionFactory.create();
|
session = sessionFactory.create();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
model = session.getModel();
|
||||||
realmManager = new RealmManager(session);
|
realmManager = new RealmManager(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class AdapterTest extends AbstractModelTest {
|
||||||
realmModel.getId();
|
realmModel.getId();
|
||||||
|
|
||||||
commit();
|
commit();
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = model.getRealms();
|
||||||
Assert.assertEquals(realms.size(), 2);
|
Assert.assertEquals(realms.size(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ public class AdapterTest extends AbstractModelTest {
|
||||||
|
|
||||||
commit();
|
commit();
|
||||||
|
|
||||||
realmModel = session.getRealm("JUGGLER");
|
realmModel = model.getRealm("JUGGLER");
|
||||||
Assert.assertTrue(realmModel.removeUser("bburke"));
|
Assert.assertTrue(realmModel.removeUser("bburke"));
|
||||||
Assert.assertFalse(realmModel.removeUser("bburke"));
|
Assert.assertFalse(realmModel.removeUser("bburke"));
|
||||||
assertNull(realmModel.getUser("bburke"));
|
assertNull(realmModel.getUser("bburke"));
|
||||||
|
@ -235,7 +235,7 @@ public class AdapterTest extends AbstractModelTest {
|
||||||
app.addScopeMapping(realmRole);
|
app.addScopeMapping(realmRole);
|
||||||
|
|
||||||
commit();
|
commit();
|
||||||
realmModel = session.getRealm("JUGGLER");
|
realmModel = model.getRealm("JUGGLER");
|
||||||
|
|
||||||
Assert.assertTrue(realmManager.removeRealm(realmModel));
|
Assert.assertTrue(realmManager.removeRealm(realmModel));
|
||||||
Assert.assertFalse(realmManager.removeRealm(realmModel));
|
Assert.assertFalse(realmManager.removeRealm(realmModel));
|
||||||
|
@ -261,7 +261,7 @@ public class AdapterTest extends AbstractModelTest {
|
||||||
app.addScopeMapping(realmRole);
|
app.addScopeMapping(realmRole);
|
||||||
|
|
||||||
commit();
|
commit();
|
||||||
realmModel = session.getRealm("JUGGLER");
|
realmModel = model.getRealm("JUGGLER");
|
||||||
app = realmModel.getApplicationByName("test-app");
|
app = realmModel.getApplicationByName("test-app");
|
||||||
|
|
||||||
Assert.assertTrue(realmModel.removeRoleById(realmRole.getId()));
|
Assert.assertTrue(realmModel.removeRoleById(realmRole.getId()));
|
||||||
|
@ -513,7 +513,7 @@ public class AdapterTest extends AbstractModelTest {
|
||||||
|
|
||||||
commit();
|
commit();
|
||||||
|
|
||||||
realmModel = session.getRealmByName("JUGGLER");
|
realmModel = model.getRealmByName("JUGGLER");
|
||||||
app1 = realmModel.getApplicationByName("app1");
|
app1 = realmModel.getApplicationByName("app1");
|
||||||
app2 = realmModel.getApplicationByName("app2");
|
app2 = realmModel.getApplicationByName("app2");
|
||||||
client = realmModel.getOAuthClient("client");
|
client = realmModel.getOAuthClient("client");
|
||||||
|
|
|
@ -49,8 +49,8 @@ public class MultipleRealmsTest extends AbstractModelTest {
|
||||||
Assert.assertEquals(2, realm1.searchForUser("user").size());
|
Assert.assertEquals(2, realm1.searchForUser("user").size());
|
||||||
|
|
||||||
commit();
|
commit();
|
||||||
realm1 = session.getRealm("id1");
|
realm1 = model.getRealm("id1");
|
||||||
realm2 = session.getRealm("id2");
|
realm2 = model.getRealm("id2");
|
||||||
|
|
||||||
realm1.removeUser("user1");
|
realm1.removeUser("user1");
|
||||||
realm1.removeUser("user2");
|
realm1.removeUser("user2");
|
||||||
|
@ -60,10 +60,10 @@ public class MultipleRealmsTest extends AbstractModelTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetById() {
|
public void testGetById() {
|
||||||
Assert.assertEquals(realm1, session.getRealm("id1"));
|
Assert.assertEquals(realm1, model.getRealm("id1"));
|
||||||
Assert.assertEquals(realm1, session.getRealmByName("realm1"));
|
Assert.assertEquals(realm1, model.getRealmByName("realm1"));
|
||||||
Assert.assertEquals(realm2, session.getRealm("id2"));
|
Assert.assertEquals(realm2, model.getRealm("id2"));
|
||||||
Assert.assertEquals(realm2, session.getRealmByName("realm2"));
|
Assert.assertEquals(realm2, model.getRealmByName("realm2"));
|
||||||
|
|
||||||
ApplicationModel r1app1 = realm1.getApplicationByName("app1");
|
ApplicationModel r1app1 = realm1.getApplicationByName("app1");
|
||||||
ApplicationModel r1app2 = realm1.getApplicationByName("app2");
|
ApplicationModel r1app2 = realm1.getApplicationByName("app2");
|
||||||
|
|
|
@ -1,24 +1,14 @@
|
||||||
package org.keycloak.services;
|
package org.keycloak.services;
|
||||||
|
|
||||||
import org.keycloak.models.ApplicationModel;
|
|
||||||
import org.keycloak.models.ClientModel;
|
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.KeycloakTransaction;
|
import org.keycloak.models.KeycloakTransaction;
|
||||||
import org.keycloak.models.ModelProvider;
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.OAuthClientModel;
|
|
||||||
import org.keycloak.models.RealmModel;
|
|
||||||
import org.keycloak.models.RoleModel;
|
|
||||||
import org.keycloak.models.SocialLinkModel;
|
|
||||||
import org.keycloak.models.UserModel;
|
|
||||||
import org.keycloak.models.UserSessionModel;
|
|
||||||
import org.keycloak.models.UsernameLoginFailureModel;
|
|
||||||
import org.keycloak.models.cache.CacheModelProvider;
|
import org.keycloak.models.cache.CacheModelProvider;
|
||||||
import org.keycloak.provider.Provider;
|
import org.keycloak.provider.Provider;
|
||||||
import org.keycloak.provider.ProviderFactory;
|
import org.keycloak.provider.ProviderFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -27,8 +17,8 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class DefaultKeycloakSession implements KeycloakSession {
|
public class DefaultKeycloakSession implements KeycloakSession {
|
||||||
|
|
||||||
private DefaultKeycloakSessionFactory factory;
|
private final DefaultKeycloakSessionFactory factory;
|
||||||
private Map<Integer, Provider> providers = new HashMap<Integer, Provider>();
|
private final Map<Integer, Provider> providers = new HashMap<Integer, Provider>();
|
||||||
private final ModelProvider model;
|
private final ModelProvider model;
|
||||||
|
|
||||||
public DefaultKeycloakSession(DefaultKeycloakSessionFactory factory) {
|
public DefaultKeycloakSession(DefaultKeycloakSessionFactory factory) {
|
||||||
|
@ -85,159 +75,8 @@ public class DefaultKeycloakSession implements KeycloakSession {
|
||||||
return providers;
|
return providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public ModelProvider getModel() {
|
||||||
public RealmModel createRealm(String name) {
|
return model;
|
||||||
return model.createRealm(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RealmModel createRealm(String id, String name) {
|
|
||||||
return model.createRealm(id, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RealmModel getRealm(String id) {
|
|
||||||
return model.getRealm(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RealmModel getRealmByName(String name) {
|
|
||||||
return model.getRealmByName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserModel getUserById(String id, RealmModel realm) {
|
|
||||||
return model.getUserById(id, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserModel getUserByUsername(String username, RealmModel realm) {
|
|
||||||
return model.getUserByUsername(username, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserModel getUserByEmail(String email, RealmModel realm) {
|
|
||||||
return model.getUserByEmail(email, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserModel getUserBySocialLink(SocialLinkModel socialLink, RealmModel realm) {
|
|
||||||
return model.getUserBySocialLink(socialLink, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<UserModel> getUsers(RealmModel realm) {
|
|
||||||
return model.getUsers(realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<UserModel> searchForUser(String search, RealmModel realm) {
|
|
||||||
return model.searchForUser(search, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<UserModel> searchForUserByAttributes(Map<String, String> attributes, RealmModel realm) {
|
|
||||||
return model.searchForUserByAttributes(attributes, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<SocialLinkModel> getSocialLinks(UserModel user, RealmModel realm) {
|
|
||||||
return model.getSocialLinks(user, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SocialLinkModel getSocialLink(UserModel user, String socialProvider, RealmModel realm) {
|
|
||||||
return model.getSocialLink(user, socialProvider, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RoleModel getRoleById(String id, RealmModel realm) {
|
|
||||||
return model.getRoleById(id, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationModel getApplicationById(String id, RealmModel realm) {
|
|
||||||
return model.getApplicationById(id, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OAuthClientModel getOAuthClientById(String id, RealmModel realm) {
|
|
||||||
return model.getOAuthClientById(id, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<RealmModel> getRealms() {
|
|
||||||
return model.getRealms();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean removeRealm(String id) {
|
|
||||||
return model.removeRealm(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UsernameLoginFailureModel getUserLoginFailure(String username, RealmModel realm) {
|
|
||||||
return model.getUserLoginFailure(username, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UsernameLoginFailureModel addUserLoginFailure(String username, RealmModel realm) {
|
|
||||||
return model.addUserLoginFailure(username, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<UsernameLoginFailureModel> getAllUserLoginFailures(RealmModel realm) {
|
|
||||||
return model.getAllUserLoginFailures(realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserSessionModel createUserSession(RealmModel realm, UserModel user, String ipAddress) {
|
|
||||||
return model.createUserSession(realm, user, ipAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserSessionModel getUserSession(String id, RealmModel realm) {
|
|
||||||
return model.getUserSession(id, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<UserSessionModel> getUserSessions(UserModel user, RealmModel realm) {
|
|
||||||
return model.getUserSessions(user, realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<UserSessionModel> getUserSessions(RealmModel realm, ClientModel client) {
|
|
||||||
return model.getUserSessions(realm, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getActiveUserSessions(RealmModel realm, ClientModel client) {
|
|
||||||
return model.getActiveUserSessions(realm, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeUserSession(UserSessionModel session) {
|
|
||||||
model.removeUserSession(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeUserSessions(RealmModel realm, UserModel user) {
|
|
||||||
model.removeUserSessions(realm, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeExpiredUserSessions(RealmModel realm) {
|
|
||||||
model.removeExpiredUserSessions(realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeUserSessions(RealmModel realm) {
|
|
||||||
model.removeUserSessions(realm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAllData() {
|
|
||||||
model.removeAllData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.keycloak.models.AuthenticationProviderModel;
|
||||||
import org.keycloak.models.Constants;
|
import org.keycloak.models.Constants;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.KeycloakSessionFactory;
|
import org.keycloak.models.KeycloakSessionFactory;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.models.UserCredentialModel;
|
import org.keycloak.models.UserCredentialModel;
|
||||||
|
@ -39,7 +40,7 @@ public class ApplianceBootstrap {
|
||||||
|
|
||||||
public void bootstrap(KeycloakSession session, String contextPath) {
|
public void bootstrap(KeycloakSession session, String contextPath) {
|
||||||
String adminRealmName = Config.getAdminRealm();
|
String adminRealmName = Config.getAdminRealm();
|
||||||
if (session.getRealm(adminRealmName) != null) {
|
if (session.getModel().getRealm(adminRealmName) != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class BruteForceProtector implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RealmModel getRealmModel(KeycloakSession session, LoginEvent event) {
|
protected RealmModel getRealmModel(KeycloakSession session, LoginEvent event) {
|
||||||
RealmModel realm = session.getRealm(event.realmId);
|
RealmModel realm = session.getModel().getRealm(event.realmId);
|
||||||
if (realm == null) return null;
|
if (realm == null) return null;
|
||||||
return realm;
|
return realm;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.Config;
|
import org.keycloak.Config;
|
||||||
import org.keycloak.models.Constants;
|
import org.keycloak.models.Constants;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.OAuthClientModel;
|
import org.keycloak.models.OAuthClientModel;
|
||||||
import org.keycloak.models.PasswordPolicy;
|
import org.keycloak.models.PasswordPolicy;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
|
@ -53,6 +54,7 @@ public class RealmManager {
|
||||||
protected static final Logger logger = Logger.getLogger(RealmManager.class);
|
protected static final Logger logger = Logger.getLogger(RealmManager.class);
|
||||||
|
|
||||||
protected KeycloakSession session;
|
protected KeycloakSession session;
|
||||||
|
protected ModelProvider model;
|
||||||
protected String contextPath = "";
|
protected String contextPath = "";
|
||||||
|
|
||||||
public String getContextPath() {
|
public String getContextPath() {
|
||||||
|
@ -65,6 +67,7 @@ public class RealmManager {
|
||||||
|
|
||||||
public RealmManager(KeycloakSession session) {
|
public RealmManager(KeycloakSession session) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
this.model = session.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmModel getKeycloakAdminstrationRealm() {
|
public RealmModel getKeycloakAdminstrationRealm() {
|
||||||
|
@ -72,11 +75,11 @@ public class RealmManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmModel getRealm(String id) {
|
public RealmModel getRealm(String id) {
|
||||||
return session.getRealm(id);
|
return model.getRealm(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmModel getRealmByName(String name) {
|
public RealmModel getRealmByName(String name) {
|
||||||
return session.getRealmByName(name);
|
return model.getRealmByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmModel createRealm(String name) {
|
public RealmModel createRealm(String name) {
|
||||||
|
@ -85,7 +88,7 @@ public class RealmManager {
|
||||||
|
|
||||||
public RealmModel createRealm(String id, String name) {
|
public RealmModel createRealm(String id, String name) {
|
||||||
if (id == null) id = KeycloakModelUtils.generateId();
|
if (id == null) id = KeycloakModelUtils.generateId();
|
||||||
RealmModel realm = session.createRealm(id, name);
|
RealmModel realm = model.createRealm(id, name);
|
||||||
realm.setName(name);
|
realm.setName(name);
|
||||||
|
|
||||||
// setup defaults
|
// setup defaults
|
||||||
|
@ -143,7 +146,7 @@ public class RealmManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeRealm(RealmModel realm) {
|
public boolean removeRealm(RealmModel realm) {
|
||||||
boolean removed = session.removeRealm(realm.getId());
|
boolean removed = model.removeRealm(realm.getId());
|
||||||
if (removed) {
|
if (removed) {
|
||||||
getKeycloakAdminstrationRealm().removeApplication(realm.getMasterAdminApp().getId());
|
getKeycloakAdminstrationRealm().removeApplication(realm.getMasterAdminApp().getId());
|
||||||
}
|
}
|
||||||
|
@ -244,7 +247,7 @@ public class RealmManager {
|
||||||
RoleModel createRealmRole = realm.addRole(AdminRoles.CREATE_REALM);
|
RoleModel createRealmRole = realm.addRole(AdminRoles.CREATE_REALM);
|
||||||
adminRole.addCompositeRole(createRealmRole);
|
adminRole.addCompositeRole(createRealmRole);
|
||||||
} else {
|
} else {
|
||||||
adminRealm = session.getRealmByName(Config.getAdminRealm());
|
adminRealm = model.getRealmByName(Config.getAdminRealm());
|
||||||
adminRole = adminRealm.getRole(AdminRoles.ADMIN);
|
adminRole = adminRealm.getRole(AdminRoles.ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.keycloak.models.AdminRoles;
|
||||||
import org.keycloak.models.ApplicationModel;
|
import org.keycloak.models.ApplicationModel;
|
||||||
import org.keycloak.models.Constants;
|
import org.keycloak.models.Constants;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.ModelProvider;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
|
@ -224,7 +225,7 @@ public class AdminConsole {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMasterRealmAccess(RealmModel masterRealm, UserModel user, Map<String, Set<String>> realmAdminAccess) {
|
private void addMasterRealmAccess(RealmModel masterRealm, UserModel user, Map<String, Set<String>> realmAdminAccess) {
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = session.getModel().getRealms();
|
||||||
for (RealmModel realm : realms) {
|
for (RealmModel realm : realms) {
|
||||||
ApplicationModel realmAdminApp = realm.getMasterAdminApp();
|
ApplicationModel realmAdminApp = realm.getMasterAdminApp();
|
||||||
Set<RoleModel> roles = realmAdminApp.getRoles();
|
Set<RoleModel> roles = realmAdminApp.getRoles();
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class RealmsAdminResource {
|
||||||
RealmManager realmManager = new RealmManager(session);
|
RealmManager realmManager = new RealmManager(session);
|
||||||
List<RealmRepresentation> reps = new ArrayList<RealmRepresentation>();
|
List<RealmRepresentation> reps = new ArrayList<RealmRepresentation>();
|
||||||
if (auth.getRealm().equals(realmManager.getKeycloakAdminstrationRealm())) {
|
if (auth.getRealm().equals(realmManager.getKeycloakAdminstrationRealm())) {
|
||||||
List<RealmModel> realms = session.getRealms();
|
List<RealmModel> realms = session.getModel().getRealms();
|
||||||
for (RealmModel realm : realms) {
|
for (RealmModel realm : realms) {
|
||||||
addRealmRep(reps, realm, realm.getMasterAdminApp());
|
addRealmRep(reps, realm, realm.getMasterAdminApp());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class ClearExpiredAuditEvents implements ScheduledTask {
|
||||||
public void run(KeycloakSession session) {
|
public void run(KeycloakSession session) {
|
||||||
AuditProvider audit = session.getProvider(AuditProvider.class);
|
AuditProvider audit = session.getProvider(AuditProvider.class);
|
||||||
if (audit != null) {
|
if (audit != null) {
|
||||||
for (RealmModel realm : session.getRealms()) {
|
for (RealmModel realm : session.getModel().getRealms()) {
|
||||||
if (realm.isAuditEnabled() && realm.getAuditExpiration() > 0) {
|
if (realm.isAuditEnabled() && realm.getAuditExpiration() > 0) {
|
||||||
long olderThan = System.currentTimeMillis() - realm.getAuditExpiration() * 1000;
|
long olderThan = System.currentTimeMillis() - realm.getAuditExpiration() * 1000;
|
||||||
audit.clear(realm.getId(), olderThan);
|
audit.clear(realm.getId(), olderThan);
|
||||||
|
|
|
@ -10,7 +10,7 @@ public class ClearExpiredUserSessions implements ScheduledTask {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(KeycloakSession session) {
|
public void run(KeycloakSession session) {
|
||||||
for (RealmModel realm : session.getRealms()) {
|
for (RealmModel realm : session.getModel().getRealms()) {
|
||||||
realm.removeExpiredUserSessions();
|
realm.removeExpiredUserSessions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ public class AdapterTest {
|
||||||
Assert.assertTrue(pageSource.contains("Bill Burke") && pageSource.contains("Stian Thorgersen"));
|
Assert.assertTrue(pageSource.contains("Bill Burke") && pageSource.contains("Stian Thorgersen"));
|
||||||
|
|
||||||
KeycloakSession session = keycloakRule.startSession();
|
KeycloakSession session = keycloakRule.startSession();
|
||||||
RealmModel realm = session.getRealmByName("demo");
|
RealmModel realm = session.getModel().getRealmByName("demo");
|
||||||
int originalIdle = realm.getSsoSessionIdleTimeout();
|
int originalIdle = realm.getSsoSessionIdleTimeout();
|
||||||
realm.setSsoSessionIdleTimeout(1);
|
realm.setSsoSessionIdleTimeout(1);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -245,7 +245,7 @@ public class AdapterTest {
|
||||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("demo");
|
realm = session.getModel().getRealmByName("demo");
|
||||||
realm.setSsoSessionIdleTimeout(originalIdle);
|
realm.setSsoSessionIdleTimeout(originalIdle);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
@ -265,7 +265,7 @@ public class AdapterTest {
|
||||||
Assert.assertTrue(pageSource.contains("Bill Burke") && pageSource.contains("Stian Thorgersen"));
|
Assert.assertTrue(pageSource.contains("Bill Burke") && pageSource.contains("Stian Thorgersen"));
|
||||||
|
|
||||||
KeycloakSession session = keycloakRule.startSession();
|
KeycloakSession session = keycloakRule.startSession();
|
||||||
RealmModel realm = session.getRealmByName("demo");
|
RealmModel realm = session.getModel().getRealmByName("demo");
|
||||||
int originalIdle = realm.getSsoSessionIdleTimeout();
|
int originalIdle = realm.getSsoSessionIdleTimeout();
|
||||||
realm.setSsoSessionIdleTimeout(1);
|
realm.setSsoSessionIdleTimeout(1);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -274,7 +274,7 @@ public class AdapterTest {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("demo");
|
realm = session.getModel().getRealmByName("demo");
|
||||||
realm.removeExpiredUserSessions();
|
realm.removeExpiredUserSessions();
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
@ -284,7 +284,7 @@ public class AdapterTest {
|
||||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("demo");
|
realm = session.getModel().getRealmByName("demo");
|
||||||
realm.setSsoSessionIdleTimeout(originalIdle);
|
realm.setSsoSessionIdleTimeout(originalIdle);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
@ -304,7 +304,7 @@ public class AdapterTest {
|
||||||
Assert.assertTrue(pageSource.contains("Bill Burke") && pageSource.contains("Stian Thorgersen"));
|
Assert.assertTrue(pageSource.contains("Bill Burke") && pageSource.contains("Stian Thorgersen"));
|
||||||
|
|
||||||
KeycloakSession session = keycloakRule.startSession();
|
KeycloakSession session = keycloakRule.startSession();
|
||||||
RealmModel realm = session.getRealmByName("demo");
|
RealmModel realm = session.getModel().getRealmByName("demo");
|
||||||
int original = realm.getSsoSessionMaxLifespan();
|
int original = realm.getSsoSessionMaxLifespan();
|
||||||
realm.setSsoSessionMaxLifespan(1);
|
realm.setSsoSessionMaxLifespan(1);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -318,7 +318,7 @@ public class AdapterTest {
|
||||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("demo");
|
realm = session.getModel().getRealmByName("demo");
|
||||||
realm.setSsoSessionMaxLifespan(original);
|
realm.setSsoSessionMaxLifespan(original);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class RefreshTokenTest {
|
||||||
String refreshId = oauth.verifyRefreshToken(tokenResponse.getRefreshToken()).getId();
|
String refreshId = oauth.verifyRefreshToken(tokenResponse.getRefreshToken()).getId();
|
||||||
|
|
||||||
KeycloakSession session = keycloakRule.startSession();
|
KeycloakSession session = keycloakRule.startSession();
|
||||||
RealmModel realm = session.getRealmByName("test");
|
RealmModel realm = session.getModel().getRealmByName("test");
|
||||||
UserSessionModel userSession = realm.getUserSession(sessionId);
|
UserSessionModel userSession = realm.getUserSession(sessionId);
|
||||||
int last = userSession.getLastSessionRefresh();
|
int last = userSession.getLastSessionRefresh();
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -199,7 +199,7 @@ public class RefreshTokenTest {
|
||||||
Assert.assertEquals(200, tokenResponse.getStatusCode());
|
Assert.assertEquals(200, tokenResponse.getStatusCode());
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("test");
|
realm = session.getModel().getRealmByName("test");
|
||||||
userSession = realm.getUserSession(sessionId);
|
userSession = realm.getUserSession(sessionId);
|
||||||
int next = userSession.getLastSessionRefresh();
|
int next = userSession.getLastSessionRefresh();
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -211,7 +211,7 @@ public class RefreshTokenTest {
|
||||||
|
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("test");
|
realm = session.getModel().getRealmByName("test");
|
||||||
int lastAccessTokenLifespan = realm.getAccessTokenLifespan();
|
int lastAccessTokenLifespan = realm.getAccessTokenLifespan();
|
||||||
realm.setAccessTokenLifespan(100000);
|
realm.setAccessTokenLifespan(100000);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -221,7 +221,7 @@ public class RefreshTokenTest {
|
||||||
tokenResponse = oauth.doRefreshTokenRequest(tokenResponse.getRefreshToken(), "password");
|
tokenResponse = oauth.doRefreshTokenRequest(tokenResponse.getRefreshToken(), "password");
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("test");
|
realm = session.getModel().getRealmByName("test");
|
||||||
userSession = realm.getUserSession(sessionId);
|
userSession = realm.getUserSession(sessionId);
|
||||||
next = userSession.getLastSessionRefresh();
|
next = userSession.getLastSessionRefresh();
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -231,7 +231,7 @@ public class RefreshTokenTest {
|
||||||
Assert.assertThat(next, allOf(greaterThan(last), lessThan(last + 6)));
|
Assert.assertThat(next, allOf(greaterThan(last), lessThan(last + 6)));
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("test");
|
realm = session.getModel().getRealmByName("test");
|
||||||
int originalIdle = realm.getSsoSessionIdleTimeout();
|
int originalIdle = realm.getSsoSessionIdleTimeout();
|
||||||
realm.setSsoSessionIdleTimeout(1);
|
realm.setSsoSessionIdleTimeout(1);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -249,7 +249,7 @@ public class RefreshTokenTest {
|
||||||
events.expectRefresh(refreshId, sessionId).error(Errors.INVALID_TOKEN);
|
events.expectRefresh(refreshId, sessionId).error(Errors.INVALID_TOKEN);
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("test");
|
realm = session.getModel().getRealmByName("test");
|
||||||
realm.setSsoSessionIdleTimeout(originalIdle);
|
realm.setSsoSessionIdleTimeout(originalIdle);
|
||||||
realm.setAccessTokenLifespan(lastAccessTokenLifespan);
|
realm.setAccessTokenLifespan(lastAccessTokenLifespan);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -274,7 +274,7 @@ public class RefreshTokenTest {
|
||||||
String refreshId = oauth.verifyRefreshToken(tokenResponse.getRefreshToken()).getId();
|
String refreshId = oauth.verifyRefreshToken(tokenResponse.getRefreshToken()).getId();
|
||||||
|
|
||||||
KeycloakSession session = keycloakRule.startSession();
|
KeycloakSession session = keycloakRule.startSession();
|
||||||
RealmModel realm = session.getRealmByName("test");
|
RealmModel realm = session.getModel().getRealmByName("test");
|
||||||
int maxLifespan = realm.getSsoSessionMaxLifespan();
|
int maxLifespan = realm.getSsoSessionMaxLifespan();
|
||||||
realm.setSsoSessionMaxLifespan(1);
|
realm.setSsoSessionMaxLifespan(1);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
|
@ -289,7 +289,7 @@ public class RefreshTokenTest {
|
||||||
assertNull(tokenResponse.getRefreshToken());
|
assertNull(tokenResponse.getRefreshToken());
|
||||||
|
|
||||||
session = keycloakRule.startSession();
|
session = keycloakRule.startSession();
|
||||||
realm = session.getRealmByName("test");
|
realm = session.getModel().getRealmByName("test");
|
||||||
realm.setSsoSessionMaxLifespan(maxLifespan);
|
realm.setSsoSessionMaxLifespan(maxLifespan);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
|
|
|
@ -40,7 +40,7 @@ public abstract class AbstractKeycloakRule extends ExternalResource {
|
||||||
KeycloakSession session = server.getSessionFactory().create();
|
KeycloakSession session = server.getSessionFactory().create();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
try {
|
try {
|
||||||
UserModel user = session.getRealmByName(realm).getUser(name);
|
UserModel user = session.getModel().getRealmByName(realm).getUser(name);
|
||||||
return user != null ? ModelToRepresentation.toRepresentation(user) : null;
|
return user != null ? ModelToRepresentation.toRepresentation(user) : null;
|
||||||
} finally {
|
} finally {
|
||||||
session.close();
|
session.close();
|
||||||
|
@ -51,7 +51,7 @@ public abstract class AbstractKeycloakRule extends ExternalResource {
|
||||||
KeycloakSession session = server.getSessionFactory().create();
|
KeycloakSession session = server.getSessionFactory().create();
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
try {
|
try {
|
||||||
return ModelToRepresentation.toRepresentation(session.getRealmByName(realm).getUserById(id));
|
return ModelToRepresentation.toRepresentation(session.getModel().getRealmByName(realm).getUserById(id));
|
||||||
} finally {
|
} finally {
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class KeycloakRule extends AbstractKeycloakRule {
|
||||||
|
|
||||||
public void removeUserSession(String sessionId) {
|
public void removeUserSession(String sessionId) {
|
||||||
KeycloakSession session = startSession();
|
KeycloakSession session = startSession();
|
||||||
RealmModel realm = session.getRealm("test");
|
RealmModel realm = session.getModel().getRealm("test");
|
||||||
UserSessionModel userSession = realm.getUserSession(sessionId);
|
UserSessionModel userSession = realm.getUserSession(sessionId);
|
||||||
assertNotNull(userSession);
|
assertNotNull(userSession);
|
||||||
realm.removeUserSession(userSession);
|
realm.removeUserSession(userSession);
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class BaseJMeterPerformanceTest extends AbstractJavaSamplerClient {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String adminRealmName = Config.getAdminRealm();
|
String adminRealmName = Config.getAdminRealm();
|
||||||
if (keycloakSession.getRealm(adminRealmName) == null) {
|
if (keycloakSession.getModel().getRealm(adminRealmName) == null) {
|
||||||
|
|
||||||
RealmManager manager = new RealmManager(keycloakSession);
|
RealmManager manager = new RealmManager(keycloakSession);
|
||||||
manager.setContextPath(contextPath);
|
manager.setContextPath(contextPath);
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class CreateUsersWorker implements Worker {
|
||||||
@Override
|
@Override
|
||||||
public void run(SampleResult result, KeycloakSession session) {
|
public void run(SampleResult result, KeycloakSession session) {
|
||||||
// We need to obtain realm first
|
// We need to obtain realm first
|
||||||
RealmModel realm = session.getRealm(realmId);
|
RealmModel realm = session.getModel().getRealm(realmId);
|
||||||
if (realm == null) {
|
if (realm == null) {
|
||||||
throw new IllegalStateException("Realm '" + realmId + "' not found");
|
throw new IllegalStateException("Realm '" + realmId + "' not found");
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class ReadUsersWorker implements Worker {
|
||||||
@Override
|
@Override
|
||||||
public void run(SampleResult result, KeycloakSession session) {
|
public void run(SampleResult result, KeycloakSession session) {
|
||||||
// We need to obtain realm first
|
// We need to obtain realm first
|
||||||
RealmModel realm = session.getRealm(realmId);
|
RealmModel realm = session.getModel().getRealm(realmId);
|
||||||
if (realm == null) {
|
if (realm == null) {
|
||||||
throw new IllegalStateException("Realm '" + realmId + "' not found");
|
throw new IllegalStateException("Realm '" + realmId + "' not found");
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class RemoveUsersWorker implements Worker {
|
||||||
|
|
||||||
int realmNumber = realmsOffset + workerId;
|
int realmNumber = realmsOffset + workerId;
|
||||||
String realmId = PerfTestUtils.getRealmName(realmNumber);
|
String realmId = PerfTestUtils.getRealmName(realmNumber);
|
||||||
realm = session.getRealm(realmId);
|
realm = session.getModel().getRealm(realmId);
|
||||||
if (realm == null) {
|
if (realm == null) {
|
||||||
throw new IllegalStateException("Realm '" + realmId + "' not found");
|
throw new IllegalStateException("Realm '" + realmId + "' not found");
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class PerfTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getUsersCount(String realmName, String prefix) {
|
private int getUsersCount(String realmName, String prefix) {
|
||||||
RealmModel realm = session.getRealmByName(realmName);
|
RealmModel realm = session.getModel().getRealmByName(realmName);
|
||||||
|
|
||||||
// TODO: method for count on model
|
// TODO: method for count on model
|
||||||
if (prefix == null) {
|
if (prefix == null) {
|
||||||
|
|
Loading…
Reference in a new issue