// Initializes the user registry.
private void init(
String userName, int tenantId, Registry registry,
RealmService realmService, String chroot) throws RegistryException {
RegistryContext registryContext = registry.getRegistryContext();
if (registryContext.isCacheEnabled() && registry instanceof EmbeddedRegistry) {
this.coreRegistry = new CacheBackedRegistry(registry);
} else {
this.coreRegistry = registry;
}
this.isAPPRemoteRegistry = registry instanceof RemoteRegistry;
this.chrootWrapper = new ChrootWrapper(chroot);
this.callerTenantId = tenantId;
this.tenantId = tenantId;
this.realmService = realmService;
// TODO : This code needs some careful thought, and fixing.
this.userName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
if (realmService != null) {
try {
this.userRealm = new RegistryRealm(realmService.getBootstrapRealm());
} catch (Exception e) {
String msg = "Failed in getting the bootstrap realm for the tenantId: " + tenantId
+ ".";
log.error(msg);
throw new RegistryException(msg, e);
}
}
if (tenantId != MultitenantConstants.SUPER_TENANT_ID) {
try {
UserRealm realm = null;
if (realmService != null) {
realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
}
if (realm == null) {
String msg = "Failed to obtain the user realm for tenant: " + tenantId + ".";
throw new RegistryException(msg);
}
this.userRealm = new RegistryRealm(realm);
} catch (UserStoreException e) {
String msg = "An error occurred while obtaining the user realm for the tenant: " +
tenantId + ".";
log.error(msg);
throw new RegistryException(msg, e);
}
}
// this is to get a system registry
try {
setSessionInformation();
// The root must be setup, in case the remote registry does not have it.
if (registryContext.isClone()) {
try {
addRootCollection();
} catch (Exception ignored) {
// There can be situations where the remote instance doesn't like creating the
// root collection, if it is already there. Hence, we can simply ignore this.
}
} else {
addRootCollection();
}
if (!registryContext.isClone()) {
addSystemCollections();
}
} finally {
clearSessionInformation();
}