mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Violette Roche-Montane
06.32.2014 ae2964516ff5296a50b354b4c1283879a637dc0c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2014 ForgeRock AS.
 */
package org.forgerock.opendj.server.setup.model;
 
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.util.Reject;
 
/**
 * This class provides configuration's model for the OpenDJ3 setup.
 */
abstract class Model {
 
    /**
     * This enumeration is used to know what kind of server we want to set up.
     */
    public enum Type {
        /**
         * Stand alone server.
         */
        STANDALONE,
        /**
         * First server in topology.
         */
        FIRST_IN_TOPOLOGY,
        /**
         * Replicate the new suffix with existing server.
         */
        IN_EXISTING_TOPOLOGY
    }
 
    private Type type;
    private boolean startingServerAfterSetup;
    private boolean isService;
    private String instancePath;
    private String installationPath;
 
    private String license;
    private ListenerSettings settings;
    private RuntimeOptions serverRuntimeSettings;
    private RuntimeOptions importLdifRuntimeSettings;
    private DataConfiguration dataConfiguration;
 
    private ReplicationConfiguration replicationConfiguration = null;
 
    /**
     * Returns the listener settings.
     *
     * @return The listener settings.
     */
    public ListenerSettings getListenerSettings() {
        return settings;
    }
 
    /**
     * Sets the listener settings.
     *
     * @param lSettings
     *            The listener settings to set.
     */
    public void setListenerSettings(final ListenerSettings lSettings) {
        settings = lSettings;
    }
 
    /**
     * Returns {@code true} if this configuration has a non-empty license.
     *
     * @return {@code true} if this configuration has a license.
     */
    public boolean hasLicense() {
        return (this.license != null && !license.isEmpty());
    }
 
    /**
     * Returns {@code true} if this configuration is stand alone data store.
     *
     * @return {@code true} if this configuration is stand alone data store.
     */
    boolean isStandAlone() {
        return (type == Type.STANDALONE);
    }
 
    /**
     * Returns {@code true} if this configuration is a first server in a replication topology.
     *
     * @return {@code true} if this configuration is a first server in a replication topology.
     */
    boolean isFirstInTopology() {
        return (type == Type.FIRST_IN_TOPOLOGY);
    }
 
    /**
     * Returns {@code true} if this configuration is part of a replication topology.
     *
     * @return {@code true} if this configuration is part of a replication topology.
     */
    boolean isPartOfReplicationTopology() {
        return (type == Type.IN_EXISTING_TOPOLOGY);
    }
 
    /**
     * Returns {@code true} if this configuration has a certificate linked to it.
     * That generally means SSL and/or SSL are activated.
     *
     * @return {@code true} if this configuration has a certificate linked to it.
     */
    boolean isSecure() {
        return (this.getListenerSettings() != null
                && this.getListenerSettings().getCertificate() != null);
    }
 
    /**
     * Sets this configuration as a stand alone data store.
     */
    void setStandAloneDS() {
        setType(Type.STANDALONE);
    }
 
    /**
     * Sets the type of this server as : replication activated
     * and this is the first server in topology.
     */
    void setFirstInTopology() {
        this.setType(Type.FIRST_IN_TOPOLOGY);
    }
 
    /**
     * Sets the type of this server as : replication activated
     * and this is a server in an existing topology.
     */
    void setInExistingTopology() {
        this.setType(Type.IN_EXISTING_TOPOLOGY);
    }
 
    /**
     * Returns the type of this configuration.
     *
     * @return The type of this configuration.
     */
    public Type getType() {
        return type;
    }
 
    /**
     * Sets the type of this configuration.
     *
     * @param mtype
     *            The type of this configuration (standalone, etc...)
     */
    public void setType(Type mtype) {
        type = mtype;
    }
 
    /**
     * Returns {@code true} if the server must start after the installation.
     *
     * @return {@code true} if the server must start after the installation.
     */
    public boolean isStartingServerAfterSetup() {
        return startingServerAfterSetup;
    }
 
    /**
     * Sets if the server should start after its installation.
     *
     * @param startServerAfterSetup
     *            {@code true} if the server must start after the installation.
     */
    public void setStartingServerAfterSetup(boolean startServerAfterSetup) {
        startingServerAfterSetup = startServerAfterSetup;
    }
 
    public boolean isService() {
        return isService;
    }
 
    public void setService(boolean isAService) {
        isService = isAService;
    }
 
    public String getInstancePath() {
        return instancePath;
    }
 
    public void setInstancePath(String iPath) {
        instancePath = iPath;
    }
 
    public String getLicense() {
        return license;
    }
 
    public void setLicense(String theLicense) {
        license = theLicense;
    }
 
    public RuntimeOptions getServerRuntimeSettings() {
        return serverRuntimeSettings;
    }
 
    public void setServerRuntimeOptions(RuntimeOptions settings) {
        serverRuntimeSettings = settings;
    }
 
    public RuntimeOptions getImportLdifRuntimeOptions() {
        return importLdifRuntimeSettings;
    }
 
    public void setImportLdifRuntimeOptions(RuntimeOptions settings) {
        importLdifRuntimeSettings = settings;
    }
 
    public DataConfiguration getDataConfiguration() {
        return dataConfiguration;
    }
 
    public void setDataConfiguration(DataConfiguration dConfiguration) {
        dataConfiguration = dConfiguration;
    }
 
    public ReplicationConfiguration getReplicationConfiguration() {
        return replicationConfiguration;
    }
 
    public void setReplicationConfiguration(ReplicationConfiguration replicationConfiguration) {
        this.replicationConfiguration = replicationConfiguration;
    }
 
 
 
    public String getInstallationPath() {
        return installationPath;
    }
 
    public void setInstallationPath(String installationPath) {
        this.installationPath = installationPath;
    }
 
    /**
     * Creates a basic data store model configuration for setup.
     */
    static class DataStoreModel extends Model {
        DataStoreModel() {
            setStandAloneDS();
            setDataConfiguration(new DataConfiguration());
            setListenerSettings(new ListenerSettings());
            setServerRuntimeOptions(RuntimeOptions.getDefault());
            setImportLdifRuntimeOptions(RuntimeOptions.getDefault());
            setStartingServerAfterSetup(true);
        }
    }
 
    /**
     * Checks the validity of the current setup configuration.
     *
     * @throws ConfigException
     *             If this configuration is invalid.
     */
    void validate() throws ConfigException {
        if (isFirstInTopology() || isPartOfReplicationTopology()) {
            if (this.getReplicationConfiguration() == null) {
                throw new ConfigException(LocalizableMessage.raw("No replication configuration found"));
            }
            if (isPartOfReplicationTopology()) {
                Reject.ifNull(this.getReplicationConfiguration().getAdministrator(),
                        "Administrator name should not be null");
                Reject.ifNull(this.getReplicationConfiguration().getPassword(),
                        "Admin password should not be null");
                Reject.ifNull(this.getReplicationConfiguration().getGlobalAdministrator(),
                        "Global administrator should not be null");
                Reject.ifNull(this.getReplicationConfiguration().getGlobalAdministratorPassword(),
                        "Global administrator should not be null");
                if (getReplicationConfiguration().getSuffixes() == null
                        || getReplicationConfiguration().getSuffixes().size() == 0) {
                    throw new ConfigException(
                            LocalizableMessage.raw(
                                    "At least one base DN should be selected to replicate content with"));
                }
            }
        }
        if (getListenerSettings() == null) {
            throw new ConfigException(LocalizableMessage.raw("Invalid settings"));
        }
        if (getDataConfiguration() == null) {
            throw new ConfigException(LocalizableMessage.raw("Invalid data configuration"));
        }
        if (getDataConfiguration().isImportLDIF()) {
            if (getDataConfiguration().getLdifImportDataPath() == null) {
                throw new ConfigException(LocalizableMessage.raw("Invalid import ldif file."));
            }
        }
        if (getListenerSettings().getPasswordFile() == null && getListenerSettings().getPassword() == null) {
            throw new ConfigException(LocalizableMessage.raw("A password must be set for the root DN."));
        }
    }
 
}