| | |
| | | public abstract class Installer extends GuiApplication { |
| | | private TopologyCache lastLoadedCache; |
| | | |
| | | /* Indicates that we've detected that there is something installed */ |
| | | /** Indicates that we've detected that there is something installed. */ |
| | | boolean forceToDisplaySetup = false; |
| | | |
| | | /** When true indicates that the user has canceled this operation. */ |
| | | protected boolean canceled = false; |
| | | |
| | | // Constants used to do checks |
| | | private static final int MIN_DIRECTORY_MANAGER_PWD = 1; |
| | | |
| | |
| | | |
| | | private static final int MAX_NUMBER_ENTRIES = 10000; |
| | | |
| | | /** Set of progress steps that have been completed. */ |
| | | protected Set<InstallProgressStep> |
| | | completedProgress = new HashSet<InstallProgressStep>(); |
| | | |
| | | private List<WizardStep> lstSteps = new ArrayList<WizardStep>(); |
| | | |
| | | private final HashSet<WizardStep> SUBSTEPS = new HashSet<WizardStep>(); |
| | |
| | | private HashMap<WizardStep, WizardStep> hmPreviousSteps = |
| | | new HashMap<WizardStep, WizardStep>(); |
| | | |
| | | private char[] selfSignedCertPw = null; |
| | | |
| | | /** |
| | | * An static String that contains the class name of ConfigFileHandler. |
| | | */ |
| | | protected static final String CONFIG_CLASS_NAME = |
| | | "org.opends.server.extensions.ConfigFileHandler"; |
| | | |
| | | /** Alias of a self-signed certificate. */ |
| | | protected static final String SELF_SIGNED_CERT_ALIAS = "server-cert"; |
| | | |
| | | /** |
| | | * Creates a default instance. |
| | | */ |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isCancellable() { |
| | | return false; // TODO: have installer delete installed files upon cancel |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | |
| | | public boolean isFinished() |
| | | { |
| | | return getCurrentProgressStep() == InstallProgressStep.FINISHED_SUCCESSFULLY |
| | | || getCurrentProgressStep() == InstallProgressStep.FINISHED_CANCELED |
| | | || getCurrentProgressStep() == InstallProgressStep.FINISHED_WITH_ERROR; |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public void cancel() { |
| | | // do nothing; not cancellable |
| | | setStatus(InstallProgressStep.WAITING_TO_CANCEL); |
| | | notifyListeners(null); |
| | | this.canceled = true; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Uninstalls installed services. This is to be used when the user |
| | | * has elected to cancel an installation. |
| | | */ |
| | | protected void uninstallServices() { |
| | | if (completedProgress.contains( |
| | | InstallProgressStep.ENABLING_WINDOWS_SERVICE)) { |
| | | try { |
| | | new InstallerHelper().disableWindowsService(); |
| | | } catch (ApplicationException ae) { |
| | | LOG.log(Level.INFO, "Error disabling Windows service", ae); |
| | | } |
| | | } |
| | | |
| | | if (completedProgress.contains( |
| | | InstallProgressStep.CONFIGURING_REPLICATION)) { |
| | | // TODO: undo replication |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Creates a template file based in the contents of the UserData object. |
| | | * This template file is used to generate automatically data. To generate |
| | | * the template file the code will basically take into account the value of |
| | |
| | | getSelfSignedKeystorePath(), |
| | | CertificateManager.KEY_STORE_TYPE_JKS, |
| | | pwd); |
| | | certManager.generateSelfSignedCertificate("server-cert", |
| | | certManager.generateSelfSignedCertificate(SELF_SIGNED_CERT_ALIAS, |
| | | getSelfSignedCertificateSubjectDN(), |
| | | getSelfSignedCertificateValidity()); |
| | | exportCertificate(certManager, "server-cert", |
| | | exportCertificate(certManager, SELF_SIGNED_CERT_ALIAS, |
| | | getTemporaryCertificatePath()); |
| | | |
| | | trustManager = new CertificateManager( |
| | | getTrustManagerPath(), |
| | | CertificateManager.KEY_STORE_TYPE_JKS, |
| | | pwd); |
| | | trustManager.addCertificate("server-cert", |
| | | trustManager.addCertificate(SELF_SIGNED_CERT_ALIAS, |
| | | new File(getTemporaryCertificatePath())); |
| | | Utils.createFile(getKeystorePinPath(), pwd); |
| | | f = new File(getTemporaryCertificatePath()); |
| | |
| | | |
| | | if (result != 0) |
| | | { |
| | | String[] msgArgs = { Utils.stringArrayToString(args, " ") }; |
| | | throw new ApplicationException( |
| | | ApplicationException.Type.CONFIGURATION_ERROR, |
| | | getMsg("error-import-automatically-generated", msgArgs), null); |
| | | getMsg("error-import-ldif-tool-return-code", |
| | | Integer.toString(result)), null); |
| | | } |
| | | } catch (Throwable t) |
| | | { |
| | | throw new ApplicationException( |
| | | ApplicationException.Type.CONFIGURATION_ERROR, |
| | | getThrowableMsg("error-import-automatically-generated", null, t), t); |
| | | getThrowableMsg("error-import-automatically-generated", |
| | | new String[] { Utils.listToString(argList, " "), |
| | | t.getLocalizedMessage()}, t), t); |
| | | } |
| | | } |
| | | |
| | |
| | | getFormattedSummary(getMsg("summary-initialize-replicated-suffixes"))); |
| | | hmSummary.put(InstallProgressStep.ENABLING_WINDOWS_SERVICE, |
| | | getFormattedSummary(getMsg("summary-enabling-windows-service"))); |
| | | hmSummary.put(InstallProgressStep.WAITING_TO_CANCEL, |
| | | getFormattedSummary(getMsg("summary-waiting-to-cancel"))); |
| | | hmSummary.put(InstallProgressStep.CANCELING, |
| | | getFormattedSummary(getMsg("summary-canceling"))); |
| | | |
| | | Installation installation = getInstallation(); |
| | | String cmd = Utils.getPath(installation.getStatusPanelCommandFile()); |
| | |
| | | hmSummary.put(InstallProgressStep.FINISHED_SUCCESSFULLY, |
| | | getFormattedSuccess( |
| | | getMsg("summary-install-finished-successfully", args))); |
| | | hmSummary.put(InstallProgressStep.FINISHED_CANCELED, |
| | | getFormattedSuccess( |
| | | getMsg("summary-install-finished-canceled", args))); |
| | | hmSummary.put(InstallProgressStep.FINISHED_WITH_ERROR, |
| | | getFormattedError(getMsg("summary-install-finished-with-error", args))); |
| | | } |
| | | |
| | | /** |
| | | * Checks the value of <code>canceled</code> field and throws an |
| | | * ApplicationException if true. This indicates that the user has |
| | | * canceled this operation and the process of aborting should begin |
| | | * as soon as possible. |
| | | * |
| | | * @throws ApplicationException thrown if <code>canceled</code> |
| | | */ |
| | | protected void checkAbort() throws ApplicationException { |
| | | if (canceled) { |
| | | setStatus(InstallProgressStep.CANCELING); |
| | | notifyListeners(null); |
| | | throw new ApplicationException( |
| | | ApplicationException.Type.CANCEL, |
| | | getMsg("upgrade-canceled"), null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Writes the java home that we are using for the setup in a file. |
| | | * This way we can use this java home even if the user has not set JAVA_HOME |
| | | * when running the different scripts. |
| | |
| | | */ |
| | | protected void setStatus(InstallProgressStep status) |
| | | { |
| | | if (status != null) { |
| | | this.completedProgress.add(status); |
| | | } |
| | | this.status = status; |
| | | } |
| | | |
| | |
| | | * @return the keystore path to be used for generating a self-signed |
| | | * certificate. |
| | | */ |
| | | private String getSelfSignedKeystorePath() |
| | | protected String getSelfSignedKeystorePath() |
| | | { |
| | | String parentFile = Utils.getPath(getInstallationPath(), |
| | | Installation.CONFIG_PATH_RELATIVE); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the self-signed certificate password used for this session. This |
| | | * method calls <code>createSelfSignedCertificatePwd()</code> the first time |
| | | * this method is called. |
| | | * @return the self-signed certificate password used for this session. |
| | | */ |
| | | protected String getSelfSignedCertificatePwd() |
| | | { |
| | | if (selfSignedCertPw == null) { |
| | | selfSignedCertPw = createSelfSignedCertificatePwd(); |
| | | } |
| | | return new String(selfSignedCertPw); |
| | | } |
| | | |
| | | /** |
| | | * Returns a randomly generated password for the self-signed certificate |
| | | * keystore. |
| | | * @return a randomly generated password for the self-signed certificate |
| | | * keystore. |
| | | */ |
| | | private String getSelfSignedCertificatePwd() |
| | | { |
| | | private char[] createSelfSignedCertificatePwd() { |
| | | int pwdLength = 50; |
| | | char[] pwd = new char[pwdLength]; |
| | | Random random = new Random(); |
| | |
| | | char nextChar = getRandomChar(random,type); |
| | | pwd[pos] = nextChar; |
| | | } |
| | | |
| | | String pwdString = new String(pwd); |
| | | return pwdString; |
| | | return pwd; |
| | | } |
| | | |
| | | private void exportCertificate(CertificateManager certManager, String alias, |