コード例 #1
0
  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");
    }
  }