/**
   * Read port from carbon.xml
   *
   * @return
   */
  private String readSSLPortFromCarbonConfig() {
    ServerConfigurationService carbonConfig =
        QpidServiceDataHolder.getInstance().getCarbonConfiguration();
    String port = carbonConfig.getFirstProperty(CARBON_CONFIG_QPID_SSL_PORT_NODE);

    return ((port != null) ? port.trim() : "");
  }
  public static Cipher getCipherOfSuperTenant() throws UserStoreException {
    Cipher cipher;
    ServerConfigurationService config = UserStoreConfigComponent.getServerConfigurationService();

    if (config == null) {
      String errMsg = "ServerConfigurationService is null - this situation can't occur";
      throw new UserStoreException(errMsg);
    }

    String filePath = config.getFirstProperty(UserStoreConfigurationConstants.SERVER_KEYSTORE_FILE);
    String keyStoreType =
        config.getFirstProperty(UserStoreConfigurationConstants.SERVER_KEYSTORE_TYPE);
    String password =
        config.getFirstProperty(UserStoreConfigurationConstants.SERVER_KEYSTORE_PASSWORD);
    String keyAlias =
        config.getFirstProperty(UserStoreConfigurationConstants.SERVER_KEYSTORE_KEY_ALIAS);

    KeyStore store;
    InputStream inputStream = null;

    try {
      inputStream = new FileInputStream(new File(filePath).getAbsolutePath());
      store = KeyStore.getInstance(keyStoreType);
      store.load(inputStream, password.toCharArray());
      Certificate[] certs = store.getCertificateChain(keyAlias);
      cipher = Cipher.getInstance("RSA", "BC");
      cipher.init(Cipher.ENCRYPT_MODE, certs[0].getPublicKey());
    } catch (FileNotFoundException e) {
      String errorMsg = "Keystore File Not Found in configured location";
      throw new UserStoreException(errorMsg, e);
    } catch (IOException e) {
      String errorMsg = "Keystore File IO operation failed";
      throw new UserStoreException(errorMsg, e);
    } catch (InvalidKeyException e) {
      String errorMsg = "Invalid key is used to access keystore";
      throw new UserStoreException(errorMsg, e);
    } catch (KeyStoreException e) {
      String errorMsg = "Faulty keystore";
      throw new UserStoreException(errorMsg, e);
    } catch (GeneralSecurityException e) {
      String errorMsg = "Some parameters assigned to access the " + "keystore is invalid";
      throw new UserStoreException(errorMsg, e);
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          log.error("Key store file closing failed");
        }
      }
    }
    return cipher;
  }
  private int readPortOffset() {
    ServerConfigurationService carbonConfig =
        QpidServiceDataHolder.getInstance().getCarbonConfiguration();
    String portOffset =
        System.getProperty(
            "portOffset", carbonConfig.getFirstProperty(CARBON_CONFIG_PORT_OFFSET_NODE));

    try {
      return ((portOffset != null)
          ? Integer.parseInt(portOffset.trim())
          : CARBON_DEFAULT_PORT_OFFSET);
    } catch (NumberFormatException e) {
      return CARBON_DEFAULT_PORT_OFFSET;
    }
  }