コード例 #1
0
  /**
   * Remove domain authentication and settings properties file
   *
   * @param domainToRemove domain to remove
   * @throws DomainDeletionException
   */
  private void removeDomainPropertiesFile(Domain domainToRemove) throws DomainDeletionException {
    SilverTrace.info(
        "admin",
        "SQLDomainService.removeDomainAuthenticationPropertiesFile()",
        "root.MSG_GEN_ENTER_METHOD");

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

    File domainPropertiesFile = new File(domainPropertiesPath);
    File authenticationPropertiesFile = new File(authenticationPropertiesPath);

    boolean domainPropertiesFileDeleted = domainPropertiesFile.delete();
    boolean authenticationPropertiesFileDeleted = authenticationPropertiesFile.delete();

    if ((!domainPropertiesFileDeleted) || (!authenticationPropertiesFileDeleted)) {
      SilverTrace.warn(
          "admin",
          "SQLDomainService.removeDomainAuthenticationPropertiesFile()",
          "admin.EX_DELETE_DOMAIN_PROPERTIES",
          "domainPropertiesFileDeleted:"
              + domainPropertiesFileDeleted
              + ", authenticationPropertiesFileDeleted:"
              + authenticationPropertiesFileDeleted);
    }
  }
コード例 #2
0
  @Override
  public void deleteDomainStorage(Domain domain) {
    String domainName = domain.getName();

    jdbcTemplate.update(generateUserTableDropStatement(domainName));
    jdbcTemplate.update(generateGroupTableDropStatement(domainName));
    jdbcTemplate.update(generateGroupUserRelTableDropStatement(domainName));
  }
コード例 #3
0
  @Override
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public void createDomainStorage(Domain domain) throws SQLDomainDAOException {
    String domainName = domain.getName();

    try {
      jdbcTemplate.update(generateUserTableCreateStatement(domainName));
      jdbcTemplate.update(generateGroupTableCreateStatement(domainName));
      jdbcTemplate.update(generateGroupUserRelTableCreateStatement(domainName));
    } catch (Exception e) {
      throw new SQLDomainDAOException(
          "SQLInternalDomainDAO.createDomainStorage", "admin.CANNOT_CREATE_DOMAIN_STORAGE", e);
    }
  }
コード例 #4
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;
  }
コード例 #5
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();
    }
  }