org.wso2.carbon.utils.Axis2ConfigurationContextObserver Java Examples

The following examples show how to use org.wso2.carbon.utils.Axis2ConfigurationContextObserver. 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: EmailSenderServiceComponent.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) {
    try {
        if (log.isDebugEnabled()) {
            log.debug("Initializing email sender core bundle");
        }
        /* Initializing email sender configuration */
        EmailSenderConfig.init();

        /* Setting up default email templates */
        EmailUtils.setupEmailTemplates();

        /* Registering declarative service instances exposed by EmailSenderServiceComponent */
        this.registerServices(componentContext);

        if (log.isDebugEnabled()) {
            log.debug("Email sender core bundle has been successfully initialized");
        }
        componentContext.getBundleContext().registerService(Axis2ConfigurationContextObserver.class.getName(),
                                                            new EmailSenderAxis2ConfigContextObserver(), null);
    } catch (Throwable e) {
        log.error("Error occurred while initializing email sender core bundle", e);
    }
}
 
Example #2
Source File: STSServiceComponent.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
protected void activate(ComponentContext ctxt) {
    if (log.isDebugEnabled()) {
        log.debug("Carbon STS bundle is activated");
    }
    try {
        BundleContext bundleCtx = ctxt.getBundleContext();
        STSServiceDataHolder.getInstance().setBundle(bundleCtx.getBundle());
        // Publish the OSGi service
        Dictionary props = new Hashtable();
        props.put(CarbonConstants.AXIS2_CONFIG_SERVICE, AxisObserver.class.getName());
        ctxt.getBundleContext().registerService(AxisObserver.class.getName(),
                                                new STSDeploymentInterceptor(), props);

        // Publish an OSGi service to listen tenant configuration context creation events
        bundleCtx.registerService(Axis2ConfigurationContextObserver.class.getName(),
                                  new STSDeploymentListener(),
                                  null);
    } catch (Throwable e) {
        log.error("Error occurred while updating carbon STS service", e);
    }
}
 
Example #3
Source File: SecurityMgtServiceComponent.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
protected void activate(ComponentContext ctxt) {
    try {
        ConfigurationContext mainConfigCtx = configContextService.getServerConfigContext();
        AxisConfiguration mainAxisConfig = mainConfigCtx.getAxisConfiguration();
        BundleContext bundleCtx = ctxt.getBundleContext();
        String enablePoxSecurity = ServerConfiguration.getInstance()
                .getFirstProperty("EnablePoxSecurity");
        if (enablePoxSecurity == null || "true".equals(enablePoxSecurity)) {
            mainAxisConfig.engageModule(POX_SECURITY_MODULE);
        } else {
            log.info("POX Security Disabled");
        }

        bundleCtx.registerService(SecurityConfigAdmin.class.getName(),
                new SecurityConfigAdmin(mainAxisConfig,
                        registryService.getConfigSystemRegistry(),
                        null),
                null);
        bundleCtx.registerService(Axis2ConfigurationContextObserver.class.getName(),
                new SecurityAxis2ConfigurationContextObserver(),
                null);
        log.debug("Security Mgt bundle is activated");
    } catch (Throwable e) {
        log.error("Failed to activate SecurityMgtServiceComponent", e);
    }
}
 
Example #4
Source File: ForumRegistryComponent.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Activate
protected void activate(ComponentContext componentContext) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Forum Registry Component Activated");
    }
    try {
        TenantServiceCreator tenantServiceCreator = new TenantServiceCreator();
        BundleContext bundleContext = componentContext.getBundleContext();
        bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), tenantServiceCreator, null);
        createTopicsRootCollection(MultitenantConstants.SUPER_TENANT_ID);
        addRxtConfigs(MultitenantConstants.SUPER_TENANT_ID);
    } catch (ForumException e) {
        log.error("Could not activate Forum Registry Component " + e.getMessage());
        throw e;
    }
}
 
Example #5
Source File: APIKeyMgtServiceComponent.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Activate
protected void activate(ComponentContext ctxt) {
    try {
        APIKeyMgtDataHolder.initData();
        log.debug("Key Manager User Operation Listener is enabled.");
        // Register subscription datastore related service
        serviceRegistration = ctxt.getBundleContext().registerService(
                Axis2ConfigurationContextObserver.class.getName(), new ServerStartupListener(), null);
        serviceRegistration = ctxt.getBundleContext().registerService(
                ServerStartupObserver.class.getName(), new ServerStartupListener(), null);

        // Register KeyManagerDataService
        serviceRegistration = ctxt.getBundleContext().registerService(KeyManagerDataService.class.getName(),
                new KeyManagerDataServiceImpl(), null);

        if (log.isDebugEnabled()) {
            log.debug("Identity API Key Mgt Bundle is started.");
        }
    } catch (Exception e) {
        log.error("Failed to initialize key management service.", e);
    }
}
 
Example #6
Source File: StatisticsServiceComponent.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
@Activate
protected void activate(ComponentContext ctxt) {

    try {
        // Engaging StatisticModule as an global module
        configContext.getAxisConfiguration().engageModule(StatisticsConstants.STATISTISTICS_MODULE_NAME);
        // Register Statistics MBean
        registerMBeans(serverConfig);
        // Registering StatisticsAdmin as an OSGi service.
        // Registering StatisticsAdmin as an OSGi service.
        BundleContext bundleCtx = ctxt.getBundleContext();
        statAdminServiceRegistration = bundleCtx.registerService(SystemStatisticsUtil.class.getName(), new
                SystemStatisticsUtil(), null);
        axisConfigCtxObserverServiceRegistration = bundleCtx.registerService(Axis2ConfigurationContextObserver
                .class.getName(), new StatisticsAxis2ConfigurationContextObserver(), null);
        log.debug("Statistics bundle is activated");
    } catch (Throwable e) {
        log.error("Failed to activate Statistics bundle", e);
    }
}
 
Example #7
Source File: UrlMappingDeploymentInterceptor.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
@Activate
protected void activate(ComponentContext ctxt) {

    BundleContext bundleCtx = ctxt.getBundleContext();
    // Publish the OSGi service
    Dictionary props = new Hashtable();
    props.put(CarbonConstants.AXIS2_CONFIG_SERVICE, AxisObserver.class.getName());
    bundleCtx.registerService(AxisObserver.class.getName(), this, props);
    PreAxisConfigurationPopulationObserver preAxisConfigObserver = new PreAxisConfigurationPopulationObserver() {

        public void createdAxisConfiguration(AxisConfiguration axisConfiguration) {

            init(axisConfiguration);
            axisConfiguration.addObservers(UrlMappingDeploymentInterceptor.this);
        }
    };
    bundleCtx.registerService(PreAxisConfigurationPopulationObserver.class.getName(), preAxisConfigObserver, null);
    // Publish an OSGi service to listen tenant configuration context creation events
    Dictionary properties = new Hashtable();
    properties.put(CarbonConstants.AXIS2_CONFIG_SERVICE, Axis2ConfigurationContextObserver.class.getName());
    bundleCtx.registerService(Axis2ConfigurationContextObserver.class.getName(), new UrlMappingServiceListener(),
            properties);
}
 
Example #8
Source File: IdentitySTSMgtServiceComponent.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception
 */
private void initialize() throws Exception {

    // Register a Axis2ConfigurationContextObserver to activate on loading tenants.
    bundleContext.registerService(
            Axis2ConfigurationContextObserver.class.getName(), new STSConfigurationContextObserver(), null);
    log.debug("Registered STSConfigurationContextObserver to configure STS service for tenants.");

    loadSecurityScenarios();
    STSConfigAdmin.configureService(configContext.getAxisConfiguration(),
                                    this.registryService.getConfigSystemRegistry());
    STSConfigAdmin.configureGenericSTS();
    configContext.getAxisConfiguration().addObservers(new STSObserver());
}
 
Example #9
Source File: ReportingComponent.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
@Activate
protected void activate(ComponentContext componentContext) {

    try {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        ReportingAxis2ConfigurationContextObserver observer = new ReportingAxis2ConfigurationContextObserver();
        componentContext.getBundleContext().registerService(Axis2ConfigurationContextObserver.class.getName(),
                observer, null);
        CommonUtil.addJrxmlConfigs(registryServiceInstance.getSystemRegistry());
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
    }
}
 
Example #10
Source File: TransactionManagerComponent.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
@Activate
protected void activate(ComponentContext ctxt) throws TransactionManagerException {
    BundleContext bundleContext = ctxt.getBundleContext();
    bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), new TransactionManagerAxis2ConfigurationContextObserver(), null);
    // Register transaction-manager with JNDI for all available tenants.
    List<Integer> tenants = this.getAllTenantIds();
    for (int tid : tenants) {
        bindTransactionManagerWithJNDIForTenant(tid);
    }
    if (log.isDebugEnabled()) {
        log.debug("Transaction Manager bundle is activated ");
    }
    bundleContext.registerService(TransactionManagerDummyService.class.getName(), new TransactionManagerDummyService(), null);
}
 
Example #11
Source File: DiscoveryComponent.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
@Activate
protected void activate(ComponentContext context) {

    BundleContext bundleCtx = context.getBundleContext();
    if (cfgCtxSvc != null) {
        // Add the observers for new updates of services and activate/deactivate events
        // This will only register the observers in the main axis configuration
        AxisConfiguration mainAxisConfig = this.cfgCtxSvc.getServerConfigContext().getAxisConfiguration();
        try {
            if (DiscoveryMgtUtils.isServiceDiscoveryEnabled(mainAxisConfig)) {
                // register the service observer
                if (log.isDebugEnabled()) {
                    log.debug("Registering the Axis observer for WS-Discovery");
                }
                Util.registerServiceObserver(mainAxisConfig);
            }
        } catch (RegistryException e) {
            log.error("Error while checking whether service discovery is enabled", e);
        }
        // we always register the handler (handler can find out whether ws-d is enabled or not)
        if (log.isDebugEnabled()) {
            log.debug("Enabling the server shutdown handler for WS-Discovery");
        }
        DiscoveryShutdownHandler discoveryShutdownHandler = new DiscoveryShutdownHandler();
        bundleCtx.registerService(ServerShutdownHandler.class.getName(), discoveryShutdownHandler, null);
    } else {
        log.warn("Error while initializing WS-Discovery core component in super tenant. " + "ConfigurationContext" +
                " service is unavailable.");
    }
    // This will take care of registering observers in tenant axis configurations
    observerServiceRegistration = bundleCtx.registerService(Axis2ConfigurationContextObserver.class.getName(),
            new DiscoveryAxis2ConfigurationContextObserver(), null);
    // Init and publish the discovery service for other components
    registerDiscoveryService(context);
}
 
Example #12
Source File: EventBrokerHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public void startEventBroker() {
     try {
         // set incarnate this thread to supper tenat since carbon contexes can only be
         // run is supertenants
         PrivilegedCarbonContext.startTenantFlow();
         PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
         PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
         PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(CarbonConstants.REGISTRY_SYSTEM_USERNAME);

         EventBroker eventBroker = EventBrokerBuilder.createEventBroker();
         this.eventServiceRegistration =
                 this.context.getBundleContext().registerService(EventBroker.class.getName(), eventBroker, null);

         // register the tenat login listener
         EventAxis2ConfigurationContextObserver observer = new EventAxis2ConfigurationContextObserver();
         observer.setEventBroker(eventBroker);

         this.context.getBundleContext().registerService(
                 Axis2ConfigurationContextObserver.class.getName(), observer, null);
         if(log.isDebugEnabled()){ 
	log.info("Successfully registered the event broker");
}
     } catch (EventBrokerConfigurationException e) {
         log.error("Can not create the event broker", e);
     } finally {
         PrivilegedCarbonContext.endTenantFlow();
     }
 }
 
Example #13
Source File: APIHandlerServiceComponent.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Activate
protected void activate(ComponentContext context) {

    BundleContext bundleContext = context.getBundleContext();
    if (log.isDebugEnabled()) {
        log.debug("API handlers component activated");
    }
    try {
        ConfigurationContext ctx =
                ConfigurationContextFactory.createConfigurationContextFromFileSystem(getClientRepoLocation(),
                        getAxis2ClientXmlLocation());
        ServiceReferenceHolder.getInstance().setAxis2ConfigurationContext(ctx);
        if (APIConstants.API_KEY_VALIDATOR_WS_CLIENT.equals(APISecurityUtils.getKeyValidatorClientType())) {
            clientPool = APIKeyValidatorClientPool.getInstance();
        }
        APIManagerConfiguration apiManagerConfiguration =
                ServiceReferenceHolder.getInstance().getAPIManagerConfiguration();
        String gatewayType = apiManagerConfiguration.getFirstProperty(APIConstants.API_GATEWAY_TYPE);
        GatewayStartupListener gatewayStartupListener = new GatewayStartupListener();
        bundleContext.registerService(ServerStartupObserver.class.getName(), gatewayStartupListener, null);
        bundleContext.registerService(ServerShutdownHandler.class, gatewayStartupListener, null);

        if ("Synapse".equalsIgnoreCase(gatewayType)) {
            // Register Tenant service creator to deploy tenant specific common synapse configurations
            TenantServiceCreator listener = new TenantServiceCreator();
            bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), listener, null);
            if (apiManagerConfiguration.getThrottleProperties().isEnabled()) {
                ServiceReferenceHolder.getInstance().setThrottleDataPublisher(new ThrottleDataPublisher());
                ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
                APIThrottleDataServiceImpl throttleDataServiceImpl =
                        new APIThrottleDataServiceImpl(throttleDataHolder);
                CacheInvalidationService cacheInvalidationService = new CacheInvalidationServiceImpl();
                // Register APIThrottleDataService so that ThrottleData maps are available to other components.
                ServiceReferenceHolder.getInstance().setCacheInvalidationService(cacheInvalidationService);
                ServiceReferenceHolder.getInstance().setAPIThrottleDataService(throttleDataServiceImpl);
                ServiceReferenceHolder.getInstance().setThrottleDataHolder(throttleDataHolder);
                ServiceReferenceHolder.getInstance().setRevokedTokenService(new RevokedTokenDataImpl());
                log.debug("APIThrottleDataService Registered...");
                // start web service throttle data retriever as separate thread and start it.
                if (apiManagerConfiguration.getThrottleProperties().getBlockCondition().isEnabled()) {
                    BlockingConditionRetriever webServiceThrottleDataRetriever = new BlockingConditionRetriever();
                    webServiceThrottleDataRetriever.startWebServiceThrottleDataRetriever();
                    KeyTemplateRetriever webServiceBlockConditionsRetriever = new KeyTemplateRetriever();
                    webServiceBlockConditionsRetriever.startKeyTemplateDataRetriever();

                    // Start web service based revoked JWT tokens retriever.
                    // Advanced throttle properties & blocking conditions have to be enabled for JWT token
                    // retrieval due to the throttle config dependency for this feature.
                    RevokedJWTTokensRetriever webServiceRevokedJWTTokensRetriever = new RevokedJWTTokensRetriever();
                    webServiceRevokedJWTTokensRetriever.startRevokedJWTTokensRetriever();
                }
            }

            // Set APIM Gateway JWT Generator

            registration =
                    context.getBundleContext().registerService(AbstractAPIMgtGatewayJWTGenerator.class.getName(),
                            new APIMgtGatewayJWTGeneratorImpl(), null);
            registration =
                    context.getBundleContext().registerService(AbstractAPIMgtGatewayJWTGenerator.class.getName(),
                            new APIMgtGatewayUrlSafeJWTGeneratorImpl(), null);
            // Start JWT revoked map cleaner.
            RevokedJWTMapCleaner revokedJWTMapCleaner = new RevokedJWTMapCleaner();
            revokedJWTMapCleaner.startJWTRevokedMapCleaner();
            ServiceReferenceHolder.getInstance().setTracer(ServiceReferenceHolder.getInstance().getTracingService()
                    .buildTracer(APIMgtGatewayConstants.SERVICE_NAME));
        }
    } catch (IOException e) {
        log.error("Error while initializing the API Gateway (APIHandlerServiceComponent) component", e);
    }
    // Create caches for the super tenant
    ServerConfiguration.getInstance().overrideConfigurationProperty("Cache.ForceLocalCache", "true");
    CacheProvider.createGatewayKeyCache();
    CacheProvider.createResourceCache();
    CacheProvider.createGatewayTokenCache();
    CacheProvider.createInvalidTokenCache();
    CacheProvider.createGatewayBasicAuthResourceCache();
    CacheProvider.createGatewayUsernameCache();
    CacheProvider.createInvalidUsernameCache();
    CacheProvider.createGatewayApiKeyCache();
    CacheProvider.createGatewayApiKeyDataCache();
    CacheProvider.getInvalidGatewayApiKeyCache();
    CacheProvider.getJWKSCache();
}