Ejemplo n.º 1
0
  @Override
  public String createDomain(Domain domainToCreate)
      throws DomainConflictException, DomainCreationException {

    // Check domain name
    String domainName = domainToCreate.getName();
    try {
      checkDomainName(domainName);
    } catch (AdminException e) {
      throw new DomainCreationException(
          "SQLDomainService.createDomain", domainToCreate.toString(), e);
    }

    // Generates domain properties file
    generateDomainPropertiesFile(domainToCreate);

    // Generates domain authentication properties file
    generateDomainAuthenticationPropertiesFile(domainToCreate);

    // Create storage
    try {
      dao.createDomainStorage(domainToCreate);
    } catch (Exception e) {
      removePropertiesFiles(domainName);
      throw new DomainCreationException(
          "SQLDomainService.createDomain", domainToCreate.toString(), e);
    }

    // register new Domain
    // SQL Driver might be override for some purpose
    if (!StringUtil.isDefined(domainToCreate.getDriverClassName())) {
      domainToCreate.setDriverClassName("com.stratelia.silverpeas.domains.sqldriver.SQLDriver");
    }
    domainToCreate.setPropFileName("com.stratelia.silverpeas.domains.domain" + domainName);
    domainToCreate.setAuthenticationServer("autDomain" + domainName);
    domainToCreate.setTheTimeStamp("0");
    String domainId = registerDomain(domainToCreate);
    if (!StringUtil.isDefined(domainId)) {
      try {
        dao.deleteDomainStorage(domainToCreate);
      } catch (Exception e) {
        removePropertiesFiles(domainName);
      }
      removePropertiesFiles(domainName);
    }

    return domainId;
  }
Ejemplo n.º 2
0
  /**
   * Generates domain authentication properties file
   *
   * @param domainToCreate domain to create
   * @throws DomainCreationException
   */
  private void generateDomainAuthenticationPropertiesFile(Domain domainToCreate)
      throws DomainCreationException {
    SilverTrace.info(
        "admin",
        "SQLDomainService.generateDomainAuthenticationPropertiesFile()",
        "root.MSG_GEN_ENTER_METHOD");

    String domainName = domainToCreate.getName();
    String domainPropertiesPath = FileRepositoryManager.getDomainPropertiesPath(domainName);
    String authenticationPropertiesPath =
        FileRepositoryManager.getDomainAuthenticationPropertiesPath(domainName);

    boolean allowPasswordChange = templateSettings.getBoolean("allowPasswordChange", true);
    String cryptMethod =
        templateSettings.getString("database.SQLPasswordEncryption", Authentication.ENC_TYPE_MD5);

    SilverpeasTemplate template = getNewTemplate();
    template.setAttribute("SQLPasswordEncryption", cryptMethod);
    template.setAttribute("allowPasswordChange", allowPasswordChange);

    template.setAttribute("SQLDriverClass", adminSettings.getString("AdminDBDriver"));
    template.setAttribute("SQLJDBCUrl", adminSettings.getString("WaProductionDb"));
    template.setAttribute("SQLAccessLogin", adminSettings.getString("WaProductionUser"));
    template.setAttribute("SQLAccessPasswd", adminSettings.getString("WaProductionPswd"));
    template.setAttribute("SQLUserTableName", "Domain" + domainName + "_User");

    File domainPropertiesFile = new File(domainPropertiesPath);
    File authenticationPropertiesFile = new File(authenticationPropertiesPath);
    PrintWriter out = null;
    try {
      out = new PrintWriter(new FileWriter(authenticationPropertiesFile));
      out.print(template.applyFileTemplate("templateDomainAuthenticationSQL"));
    } catch (IOException e) {
      domainPropertiesFile.delete();
      authenticationPropertiesFile.delete();
      throw new DomainCreationException(
          "SQLDomainService.generateDomainAuthenticationPropertiesFile()",
          domainToCreate.toString(),
          e);
    } finally {
      out.close();
    }
  }