Java Code Examples for org.wso2.carbon.context.PrivilegedCarbonContext#getOSGiServices()

The following examples show how to use org.wso2.carbon.context.PrivilegedCarbonContext#getOSGiServices() . 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: DeviceMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
public static UserStoreCountRetriever getUserStoreCountRetrieverService()
        throws UserStoreCounterException {
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    List<Object> countRetrieverFactories = ctx.getOSGiServices(AbstractCountRetrieverFactory.class, null);
    RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
    RealmConfiguration realmConfiguration = realmService.getBootstrapRealmConfiguration();
    String userStoreType;
    //Ignoring Sonar warning as getUserStoreClass() returning string name of the class. So cannot use 'instanceof'.
    if (JDBCUserStoreManager.class.getName().equals(realmConfiguration.getUserStoreClass())) {
        userStoreType = JDBCCountRetrieverFactory.JDBC;
    } else {
        userStoreType = InternalCountRetrieverFactory.INTERNAL;
    }
    AbstractCountRetrieverFactory countRetrieverFactory = null;
    for (Object countRetrieverFactoryObj : countRetrieverFactories) {
        countRetrieverFactory = (AbstractCountRetrieverFactory) countRetrieverFactoryObj;
        if (userStoreType.equals(countRetrieverFactory.getCounterType())) {
            break;
        }
    }
    if (countRetrieverFactory == null) {
        return null;
    }
    return countRetrieverFactory.buildCountRetriever(realmConfiguration);
}
 
Example 2
Source File: DeviceMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
public static UserStoreCountRetriever getUserStoreCountRetrieverService()
        throws UserStoreCounterException, UserStoreException {
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    List<Object> countRetrieverFactories = ctx.getOSGiServices(AbstractCountRetrieverFactory.class, null);
    RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
    RealmConfiguration realmConfiguration = realmService.getBootstrapRealmConfiguration();
    String userStoreType;
    if(DeviceMgtAPIUtils.getUserStoreManager() instanceof JDBCUserStoreManager) {
        userStoreType = JDBCCountRetrieverFactory.JDBC;
    } else {
        userStoreType = InternalCountRetrieverFactory.INTERNAL;
    }
    AbstractCountRetrieverFactory countRetrieverFactory = null;
    for (Object countRetrieverFactoryObj : countRetrieverFactories) {
        countRetrieverFactory = (AbstractCountRetrieverFactory) countRetrieverFactoryObj;
        if (userStoreType.equals(countRetrieverFactory.getCounterType())) {
            break;
        }
    }
    if (countRetrieverFactory == null) {
        return null;
    }
    return countRetrieverFactory.buildCountRetriever(realmConfiguration);
}