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

The following examples show how to use org.wso2.carbon.context.PrivilegedCarbonContext#getOSGiService() . 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 IntegrationClientService getIntegrationClientService() {
    if (integrationClientService == null) {
        synchronized (DeviceMgtAPIUtils.class) {
            if (integrationClientService == null) {
                PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
                integrationClientService = (IntegrationClientService) ctx.getOSGiService(IntegrationClientService.class, null);
                if (integrationClientService == null) {
                    String msg = "IntegrationClientService is not initialized";
                    log.error(msg);
                    throw new IllegalStateException(msg);
                }
            }
        }
    }
    return integrationClientService;
}
 
Example 2
Source File: ServiceUtils.java    From product-private-paas with Apache License 2.0 6 votes vote down vote up
private static ConfigurationContext getConfigContext() {

        // If a tenant has been set, then try to get the ConfigurationContext of that tenant
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ConfigurationContextService configurationContextService = (ConfigurationContextService) carbonContext
                .getOSGiService(ConfigurationContextService.class);
        ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext();
        String domain = carbonContext.getTenantDomain();
        if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) {
            return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext);
        } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
            return mainConfigContext;
        } else {
            throw new UnsupportedOperationException("Tenant domain unidentified. " +
                    "Upstream code needs to identify & set the tenant domain & tenant ID. " +
                    " The TenantDomain SOAP header could be set by the clients or " +
                    "tenant authentication should be carried out.");
        }
    }
 
Example 3
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 4
Source File: CertificateMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static JWTClientManagerService getJwtClientManagerService() {
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    JWTClientManagerService jwtClientManagerService = (JWTClientManagerService)
            ctx.getOSGiService(JWTClientManagerService.class, null);

    if (jwtClientManagerService == null) {
        String msg = "JWTClientManagerService Management service not initialized.";
        log.error(msg);
        throw new IllegalStateException(msg);
    }

    return jwtClientManagerService;
}
 
Example 5
Source File: DeviceMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static NotificationManagementService getNotificationManagementService() {
    NotificationManagementService notificationManagementService;
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    notificationManagementService = (NotificationManagementService) ctx.getOSGiService(
            NotificationManagementService.class, null);
    if (notificationManagementService == null) {
        throw new IllegalStateException("Notification Management service not initialized.");
    }
    return notificationManagementService;
}
 
Example 6
Source File: APIUtil.java    From product-iots with Apache License 2.0 5 votes vote down vote up
public static APIManagementProviderService getAPIManagementProviderService() {
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    APIManagementProviderService apiManagementProviderService =
            (APIManagementProviderService) ctx.getOSGiService(APIManagementProviderService.class, null);
    if (apiManagementProviderService == null) {
        String msg = "API management provider service has not initialized.";
        log.error(msg);
        throw new IllegalStateException(msg);
    }
    return apiManagementProviderService;
}
 
Example 7
Source File: DeviceMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static PolicyManagerService getPolicyManagementService() {
    PolicyManagerService policyManagementService;
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    policyManagementService =
            (PolicyManagerService) ctx.getOSGiService(PolicyManagerService.class, null);
    if (policyManagementService == null) {
        String msg = "PolicyImpl Management service not initialized.";
        log.error(msg);
        throw new IllegalStateException(msg);
    }
    return policyManagementService;
}
 
Example 8
Source File: APIUtil.java    From product-iots with Apache License 2.0 5 votes vote down vote up
/**
 * @return A Service to authorize device access requests
 */
public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() {
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    DeviceAccessAuthorizationService deviceAccessAuthorizationService =
            (DeviceAccessAuthorizationService) ctx.getOSGiService(DeviceAccessAuthorizationService.class, null);
    if (deviceAccessAuthorizationService == null) {
        String msg = "Device Authorization service has not initialized.";
        log.error(msg);
        throw new IllegalStateException(msg);
    }
    return deviceAccessAuthorizationService;
}
 
Example 9
Source File: DeviceMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static ApplicationManagementProviderService getAppManagementService() {
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    ApplicationManagementProviderService applicationManagementProviderService =
            (ApplicationManagementProviderService) ctx.getOSGiService(ApplicationManagementProviderService.class, null);
    if (applicationManagementProviderService == null) {
        throw new IllegalStateException("AuthenticationImpl management service has not initialized.");
    }
    return applicationManagementProviderService;
}
 
Example 10
Source File: APIUtil.java    From product-iots with Apache License 2.0 5 votes vote down vote up
/**
 * @return Device management service of current context
 */
public static DeviceManagementProviderService getDeviceManagementService() {
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    DeviceManagementProviderService deviceManagementProviderService =
            (DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
    if (deviceManagementProviderService == null) {
        String msg = "Device Management service has not initialized.";
        log.error(msg);
        throw new IllegalStateException(msg);
    }
    return deviceManagementProviderService;
}
 
Example 11
Source File: ServiceHolder.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public static TenantBillingService getBillingService() {
    PrivilegedCarbonContext carbonContext =
            PrivilegedCarbonContext.getThreadLocalCarbonContext();
    TenantBillingService tenantBillingService =
            (TenantBillingService) carbonContext.getOSGiService(TenantBillingService.class);
    return tenantBillingService;
}
 
Example 12
Source File: CertificateMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static SCEPManager getSCEPManagerService() {

        PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        SCEPManager scepManagerService = (SCEPManager)
                ctx.getOSGiService(SCEPManager.class, null);

        if (scepManagerService == null) {
            String msg = "SCEPManagerImpl Management service not initialized.";
            log.error(msg);
            throw new IllegalStateException(msg);
        }

        return scepManagerService;
    }
 
Example 13
Source File: DeviceMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static NotificationManagementService getNotificationManagementService() {
    NotificationManagementService notificationManagementService;
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    notificationManagementService = (NotificationManagementService) ctx.getOSGiService(
            NotificationManagementService.class, null);
    if (notificationManagementService == null) {
        throw new IllegalStateException("Notification Management service not initialized.");
    }
    return notificationManagementService;
}
 
Example 14
Source File: APIUtil.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static RegistryService getRegistryService() {
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    RegistryService registryService =
            (RegistryService) ctx.getOSGiService(RegistryService.class, null);
    if (registryService == null) {
        String msg = "registry service has not initialized.";
        log.error(msg);
        throw new IllegalStateException(msg);
    }
    return registryService;
}
 
Example 15
Source File: CertificateMgtAPIUtils.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static CertificateManagementService getCertificateManagementService() {

        PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        CertificateManagementService certificateManagementService = (CertificateManagementService)
                ctx.getOSGiService(CertificateManagementService.class, null);

        if (certificateManagementService == null) {
            String msg = "CertificateManagementAdminServiceImpl Management service not initialized.";
            log.error(msg);
            throw new IllegalStateException(msg);
        }

        return certificateManagementService;
    }
 
Example 16
Source File: ServiceHolder.java    From product-private-paas with Apache License 2.0 4 votes vote down vote up
public static RegistryService getRegistryService() {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    RegistryService registryService = (RegistryService) carbonContext.getOSGiService(RegistryService.class);
    return registryService;
}
 
Example 17
Source File: StratosUserManagerUtils.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public static TenantManager getTenantManager() {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class);
    return realmService.getTenantManager();
}
 
Example 18
Source File: ServiceHolder.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public static RealmService getRealmService() {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class);
    return realmService;
}
 
Example 19
Source File: ServiceHolder.java    From product-private-paas with Apache License 2.0 4 votes vote down vote up
public static TenantManager getTenantManager() {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class);
    return realmService.getTenantManager();
}
 
Example 20
Source File: ServiceHolder.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public static TenantManager getTenantManager() {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class);
    return realmService.getTenantManager();
}