Search in sources :

Example 1 with InMemoryTenantManager

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;
}
Also used : MockUserStoreManager(org.wso2.carbon.identity.common.testng.realm.MockUserStoreManager) ITestClass(org.testng.ITestClass) MockUserStoreManager(org.wso2.carbon.identity.common.testng.realm.MockUserStoreManager) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) InMemoryTenantManager(org.wso2.carbon.identity.common.testng.realm.InMemoryTenantManager) TenantManager(org.wso2.carbon.user.api.TenantManager) InMemoryTenantManager(org.wso2.carbon.identity.common.testng.realm.InMemoryTenantManager) InMemoryRealmService(org.wso2.carbon.identity.common.testng.realm.InMemoryRealmService)

Example 2 with InMemoryTenantManager

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();
}
Also used : InputStream(java.io.InputStream) RealmConfigXMLProcessor(org.wso2.carbon.user.core.config.RealmConfigXMLProcessor) UserStoreException(org.wso2.carbon.user.core.UserStoreException) UserStoreException(org.wso2.carbon.user.core.UserStoreException)

Aggregations

InputStream (java.io.InputStream)1 ITestClass (org.testng.ITestClass)1 InMemoryRealmService (org.wso2.carbon.identity.common.testng.realm.InMemoryRealmService)1 InMemoryTenantManager (org.wso2.carbon.identity.common.testng.realm.InMemoryTenantManager)1 MockUserStoreManager (org.wso2.carbon.identity.common.testng.realm.MockUserStoreManager)1 TenantManager (org.wso2.carbon.user.api.TenantManager)1 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1 RealmConfigXMLProcessor (org.wso2.carbon.user.core.config.RealmConfigXMLProcessor)1