use of org.wso2.carbon.identity.common.testng.realm.InMemoryTenantManager in project carbon-identity-framework by wso2.
the class CarbonBasedTestListener method createRealmService.
private RealmService createRealmService(WithRealmService withRealmService, boolean reuseIfAvailable) throws UserStoreException {
if (testSessionRealmService != null && reuseIfAvailable) {
return testSessionRealmService;
}
try {
int tenantId = withRealmService.tenantId();
String tenantDomain = withRealmService.tenantDomain();
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
testSessionRealmService = new InMemoryRealmService(tenantId);
UserStoreManager userStoreManager = testSessionRealmService.getTenantUserRealm(tenantId).getUserStoreManager();
((MockUserStoreManager) userStoreManager).addSecondaryUserStoreManager("PRIMARY", (MockUserStoreManager) userStoreManager);
IdentityTenantUtil.setRealmService(testSessionRealmService);
TenantManager tenantManager = new InMemoryTenantManager();
testSessionRealmService.setTenantManager(tenantManager);
RegistryDataHolder.getInstance().setRealmService(testSessionRealmService);
OSGiDataHolder.getInstance().setUserRealmService(testSessionRealmService);
Class[] singletonClasses = withRealmService.injectToSingletons();
for (Class singletonClass : singletonClasses) {
Object instance = getSingletonInstance(singletonClass);
if (instance != null) {
setInstanceValue(testSessionRealmService, RealmService.class, singletonClass, instance);
} else {
setInstanceValue(testSessionRealmService, RealmService.class, singletonClass, null);
}
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return testSessionRealmService;
}
use of org.wso2.carbon.identity.common.testng.realm.InMemoryTenantManager in project carbon-identity-framework by wso2.
the class InMemoryRealmService method setup.
public void setup() throws UserStoreException {
try {
RealmConfigXMLProcessor builder = new RealmConfigXMLProcessor();
InputStream inStream = this.getClass().getResourceAsStream("/users/user-mgt-users.xml");
try {
this.bootstrapRealmConfig = builder.buildRealmConfiguration(inStream);
} finally {
inStream.close();
}
} catch (Exception e) {
String msg = "Failed to initialize the user manager. ";
throw new UserStoreException(msg, e);
}
this.tenantManager = new InMemoryTenantManager();
}
Aggregations