public void createdConfigurationContext(ConfigurationContext configurationContext) {
    /*String tenantDomain =
            PrivilegedCarbonContext.getCurrentContext(configurationContext).getTenantDomain();
    int tenantId =  PrivilegedCarbonContext.getCurrentContext(configurationContext).getTenantId();*/
    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {
      // first check which configuration should be active
      org.wso2.carbon.registry.core.Registry registry =
          (org.wso2.carbon.registry.core.Registry)
              PrivilegedCarbonContext.getThreadLocalCarbonContext()
                  .getRegistry(RegistryType.SYSTEM_CONFIGURATION);

      AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();

      // initialize the lock
      Lock lock = new ReentrantLock();
      axisConfig.addParameter("synapse.config.lock", lock);

      // creates the synapse configuration directory hierarchy if not exists
      // useful at the initial tenant creation
      File tenantAxis2Repo =
          new File(configurationContext.getAxisConfiguration().getRepository().getFile());
      File synapseConfigsDir = new File(tenantAxis2Repo, "synapse-configs");
      if (!synapseConfigsDir.exists()) {
        if (!synapseConfigsDir.mkdir()) {
          log.fatal(
              "Couldn't create the synapse-config root on the file system "
                  + "for the tenant domain : "
                  + tenantDomain);
          return;
        }
      }

      String synapseConfigsDirLocation = synapseConfigsDir.getAbsolutePath();
      // set the required configuration parameters to initialize the ESB
      axisConfig.addParameter(
          SynapseConstants.Axis2Param.SYNAPSE_CONFIG_LOCATION, synapseConfigsDirLocation);

      // init the multiple configuration tracker
      ConfigurationManager manger =
          new ConfigurationManager((UserRegistry) registry, configurationContext);
      manger.init();

      File synapseConfigDir =
          new File(synapseConfigsDir, manger.getTracker().getCurrentConfigurationName());
      File buildSequenceFile =
          new File(
              synapseConfigsDir
                  + "/"
                  + manger.getTracker().getCurrentConfigurationName()
                  + "/"
                  + MultiXMLConfigurationBuilder.SEQUENCES_DIR
                  + "/"
                  + buildSequenceName
                  + ".xml");
      // Here we will check build sequence exist in synapse artifact. If it is not available we will
      // create
      // sequence synapse configurations by using resource artifacts
      if (!buildSequenceFile.exists()) {
        createTenantSynapseConfigHierarchy(synapseConfigDir, tenantDomain);
      }
    } catch (Exception e) {
      log.error("Failed to create Tenant's synapse sequences.");
    }

    try {
      AppManagerUtil.loadTenantAPIPolicy(tenantDomain, tenantId);
    } catch (Exception e) {
      log.error("Failed to load tiers.xml to tenant's registry");
    }

    try {
      // load workflow-extension configuration to the registry
      AppManagerUtil.loadTenantWorkFlowExtensions(tenantId);
    } catch (Exception e) {
      log.error("Failed to load workflow-extension.xml to tenant " + tenantDomain + "'s registry");
    }

    try {
      // Add the creator & publisher roles if not exists
      // Apply permissons to appmgt collection for creator role
      UserRealm realm = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm();

      Permission[] creatorPermissions =
          new Permission[] {
            new Permission(AppMConstants.Permissions.LOGIN, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.WEB_APP_CREATE, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.WEB_APP_DELETE, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.WEB_APP_UPDATE, UserMgtConstants.EXECUTE_ACTION),
            new Permission(AppMConstants.Permissions.DOCUMENT_ADD, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.DOCUMENT_DELETE, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.DOCUMENT_EDIT, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.MOBILE_APP_CREATE, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.MOBILE_APP_DELETE, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.MOBILE_APP_UPDATE, UserMgtConstants.EXECUTE_ACTION)
          };

      AppManagerUtil.addNewRole(AppMConstants.CREATOR_ROLE, creatorPermissions, realm);

      Permission[] publisherPermissions =
          new Permission[] {
            new Permission(AppMConstants.Permissions.LOGIN, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.WEB_APP_PUBLISH, UserMgtConstants.EXECUTE_ACTION),
            new Permission(AppMConstants.Permissions.VIEW_STATS, UserMgtConstants.EXECUTE_ACTION),
            new Permission(
                AppMConstants.Permissions.MOBILE_APP_PUBLISH, UserMgtConstants.EXECUTE_ACTION)
          };

      AppManagerUtil.addNewRole(AppMConstants.PUBLISHER_ROLE, publisherPermissions, realm);
      //            AppManagerUtil.applyRolePermissionToCollection(AppMConstants.CREATOR_ROLE,
      // realm);

      // Add the store-admin role
      Permission[] storeAdminPermissions =
          new Permission[] {
            new Permission(AppMConstants.Permissions.LOGIN, UserMgtConstants.EXECUTE_ACTION)
          };
      AppManagerUtil.addNewRole(AppMConstants.STORE_ADMIN_ROLE, storeAdminPermissions, realm);
    } catch (Exception e) {
      log.error(
          "Failed to add permissions of appmgt/application data collection for creator role.");
    }

    try {
      AppManagerUtil.writeDefinedSequencesToTenantRegistry(tenantId);
    } catch (Exception e) {
      log.error("Failed to write defined sequences to tenant " + tenantDomain + "'s registry");
    }
  }
  /**
   * This method returns the set of APIs for given subscriber
   *
   * @param String user
   * @return List<API>
   * @throws org.wso2.carbon.appmgt.api.AppManagementException if failed to get SubscribedAPIs
   */
  public List<SubscribedAppExtension> getSubscribedApps(String user) throws AppManagementException {
    ArrayList<SubscribedAppExtension> subscribedApps = new ArrayList<SubscribedAppExtension>();
    Connection connection = null;
    PreparedStatement ps = null;
    ResultSet result = null;

    try {
      connection = APIMgtDBUtil.getConnection();

      String sqlQuery =
          "SELECT "
              + "   SUBS.SUBSCRIPTION_ID"
              + "   ,API.APP_PROVIDER AS APP_PROVIDER"
              + "   ,API.APP_NAME AS APP_NAME"
              + "   ,API.APP_VERSION AS APP_VERSION"
              + "   ,API.APP_ID AS APP_ID"
              + "   ,SUBS.SUBSCRIPTION_TIME AS SUBSCRIPTION_TIME"
              + "   ,SUBS.EVALUATION_PERIOD AS EVALUATION_PERIOD"
              + "   ,SUBS.EXPIRED_ON AS EXPIRED_ON"
              + "   ,SUBS.IS_PAID AS IS_PAID"
              + "   FROM "
              + "   APM_SUBSCRIBER SUB, APM_SUBSCRIPTION_EXT SUBS, APM_APP API "
              + "   WHERE "
              + "   SUB.USER_ID = ? "
              + "   AND SUB.TENANT_ID = ? "
              + "   AND SUB.SUBSCRIBER_ID=SUBS.SUBSCRIBER_ID "
              + "   AND API.APP_ID=SUBS.APP_ID";

      ps = connection.prepareStatement(sqlQuery);
      ps.setString(1, user);
      int tenantId = IdentityUtil.getTenantIdOFUser(user);
      ps.setInt(2, tenantId);
      result = ps.executeQuery();

      if (result == null) {
        return subscribedApps;
      }

      while (result.next()) {
        APIIdentifier apiIdentifier =
            new APIIdentifier(
                AppManagerUtil.replaceEmailDomain(result.getString("APP_PROVIDER")),
                result.getString("APP_NAME"),
                result.getString("APP_VERSION"));
        apiIdentifier.setApplicationId(result.getString("APP_ID"));
        SubscribedAppExtension subscribedAPI = new SubscribedAppExtension(apiIdentifier);
        subscribedAPI.setSubscriptionID(result.getInt("SUBSCRIPTION_ID"));
        subscribedAPI.setSubscriptionTime(result.getTimestamp("SUBSCRIPTION_TIME"));
        subscribedAPI.setEvaluationPeriod(result.getInt("EVALUATION_PERIOD"));
        subscribedAPI.setExpireOn(result.getTimestamp("EXPIRED_ON"));
        subscribedAPI.setPaid(result.getBoolean("IS_PAID"));
        subscribedApps.add(subscribedAPI);
      }
    } catch (SQLException e) {
      handleException("Failed to get SubscribedAPI of : " + user, e);
    } catch (IdentityException e) {
      handleException("Failed get tenant id of user " + user, e);
    } finally {
      APIMgtDBUtil.closeAllConnections(ps, connection, result);
    }
    return subscribedApps;
  }