Java Code Examples for org.wso2.carbon.identity.core.util.IdentityTenantUtil#setRealmService()

The following examples show how to use org.wso2.carbon.identity.core.util.IdentityTenantUtil#setRealmService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIMgtDAOTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath");
    APIManagerConfiguration config = new APIManagerConfiguration();
    initializeDatabase(dbConfigPath);
    config.load(dbConfigPath);
    ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(new APIManagerConfigurationServiceImpl
            (config));
    List<Notifier> notifierList = new ArrayList<>();
    SubscriptionsNotifier subscriptionsNotifier = new SubscriptionsNotifier();
    notifierList.add(subscriptionsNotifier);
    ServiceReferenceHolder.getInstance().getNotifiersMap().put(subscriptionsNotifier.getType(), notifierList);
    PowerMockito.mockStatic(KeyManagerHolder.class);
    keyManager = Mockito.mock(KeyManager.class);
    APIMgtDBUtil.initialize();
    apiMgtDAO = ApiMgtDAO.getInstance();
    IdentityTenantUtil.setRealmService(new TestRealmService());
    String identityConfigPath = System.getProperty("IdentityConfigurationPath");
    IdentityConfigParser.getInstance(identityConfigPath);
    OAuthServerConfiguration oAuthServerConfiguration = OAuthServerConfiguration.getInstance();
    ServiceReferenceHolder.getInstance().setOauthServerConfiguration(oAuthServerConfiguration);

}
 
Example 2
Source File: CarbonBasedTestListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
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);
        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;
}
 
Example 3
Source File: GraphBasedSequenceHandlerAbstractTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
protected void setUp() throws UserStoreException, NoSuchFieldException, IllegalAccessException,
        NoSuchMethodException, URISyntaxException {

    URL root = this.getClass().getClassLoader().getResource(".");
    File file = new File(root.getPath());
    System.setProperty("carbon.home", file.toString());
    resetAuthenticators();

    FrameworkServiceDataHolder.getInstance().setRealmService(mock(RealmService.class));

    CacheBackedIdPMgtDAO cacheBackedIdPMgtDAO = mock(CacheBackedIdPMgtDAO.class);
    Field daoField = IdentityProviderManager.class.getDeclaredField("dao");
    daoField.setAccessible(true);
    daoField.set(IdentityProviderManager.getInstance(), cacheBackedIdPMgtDAO);

    RealmService mockRealmService = mock(RealmService.class);
    TenantManager tenantManager = mock(TenantManager.class);
    when(tenantManager.getTenantId(anyString())).thenReturn(1);
    when(mockRealmService.getTenantManager()).thenReturn(tenantManager);
    IdentityTenantUtil.setRealmService(mockRealmService);

    Field configFilePathField = FileBasedConfigurationBuilder.class.getDeclaredField("configFilePath");
    configFilePathField.setAccessible(true);
    URL url = this.getClass().getResource(APPLICATION_AUTHENTICATION_FILE_NAME);
    configFilePathField.set(null, Paths.get(url.toURI()).toString());
}
 
Example 4
Source File: IdentityCoreServiceComponent.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param realmService
 */
@Reference(
        name = "user.realmservice.default",
        service = RealmService.class,
        cardinality = ReferenceCardinality.MANDATORY,
        policy = ReferencePolicy.DYNAMIC,
        unbind = "unsetRealmService"
)
protected void setRealmService(RealmService realmService) {
    IdentityTenantUtil.setRealmService(realmService);
    defaultKeystoreManagerExtension.setRealmService(realmService);
}
 
Example 5
Source File: IdentityCoreServiceComponent.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
/**
 * @param realmService
 */
protected void unsetRealmService(RealmService realmService) {
    defaultKeystoreManagerExtension.setRealmService(null);
    IdentityTenantUtil.setRealmService(null);
}
 
Example 6
Source File: IdentityCoreServiceComponent.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param realmService
 */
protected void setRealmService(RealmService realmService) {
    IdentityTenantUtil.setRealmService(realmService);
}
 
Example 7
Source File: IdentityCoreServiceComponent.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param realmService
 */
protected void unsetRealmService(RealmService realmService) {
    IdentityTenantUtil.setRealmService(null);
}