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

Valery Kharseko
20 hours ago 37b9647aa845308648fa1450cc1a763f9bb52c94
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
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2024-2026 3A Systems LLC.
 */
 
package org.openidentityplatform.opendj.embedded;
 
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
 
public class Config {
 
    private final String CONFIG_PREFIX = Config.class.getPackage().getName();
    private int port = intProperty(CONFIG_PREFIX + ".port", "1389");
 
    private int adminPort = intProperty(CONFIG_PREFIX + ".admin_port", "4444");
 
    private String adminPassword = System.getProperty(CONFIG_PREFIX + ".password", "passw0rd");
 
    private String baseDN = System.getProperty(CONFIG_PREFIX + ".root", "dc=openidentityplatform,dc=org");
 
    private String backendType = System.getProperty(CONFIG_PREFIX + ".backend", "je");
 
    private int jmxPort = intProperty(CONFIG_PREFIX + ".jmx_port", "1689");
 
    private String ldifSchema = System.getProperty(CONFIG_PREFIX + ".ldif.schema");
 
    private String file = System.getProperty(CONFIG_PREFIX + ".ldif.data", "/test.ldif");
 
    private Set<String> skipSet = new HashSet<>(Arrays.asList(System.getProperty(CONFIG_PREFIX + ".skip", ",ou=sample-skip-group,").toLowerCase().split(";")));
 
    private long deleteTimeout = timeoutProperty(CONFIG_PREFIX + ".delete_timeout", "10000");
 
    /**
     * Returns the value of a system property holding a number.
     * <p>
     * These fields are initialized when the instance is created, so an unhandled
     * {@link NumberFormatException} would surface from the constructor of
     * {@link EmbeddedOpenDJ} saying only which string was rejected, without naming the
     * property that carried it.
     *
     * @param name
     *            the name of the system property
     * @param defaultValue
     *            the value used when the property is not set
     * @return the value of the property, or {@code defaultValue} when it is not set
     * @throws IllegalArgumentException
     *             If the value of the property is not a number.
     */
    private static int intProperty(String name, String defaultValue) {
        final String value = System.getProperty(name, defaultValue);
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            throw invalidProperty(name, value, e);
        }
    }
 
    /**
     * Returns the value of a system property holding a duration in milliseconds.
     *
     * @param name
     *            the name of the system property
     * @param defaultValue
     *            the value used when the property is not set
     * @return the value of the property, or {@code defaultValue} when it is not set
     * @throws IllegalArgumentException
     *             If the value of the property is not a number, or is negative.
     */
    private static long timeoutProperty(String name, String defaultValue) {
        final String value = System.getProperty(name, defaultValue);
        final long timeout;
        try {
            timeout = Long.parseLong(value);
        } catch (NumberFormatException e) {
            throw invalidProperty(name, value, e);
        }
        if (timeout < 0) {
            throw new IllegalArgumentException("Invalid value \"" + value + "\" for the system property "
                    + name + ": a timeout in milliseconds cannot be negative");
        }
        return timeout;
    }
 
    private static IllegalArgumentException invalidProperty(String name, String value, NumberFormatException cause) {
        return new IllegalArgumentException("Invalid value \"" + value + "\" for the system property "
                + name + ": expected a number", cause);
    }
 
    public int getPort() {
        return port;
    }
 
    public void setPort(int port) {
        this.port = port;
    }
 
    public int getAdminPort() {
        return adminPort;
    }
 
    public void setAdminPort(int adminPort) {
        this.adminPort = adminPort;
    }
 
 
    public String getAdminPassword() {
        return adminPassword;
    }
 
    public void setAdminPassword(String adminPassword) {
        this.adminPassword = adminPassword;
    }
 
    public String getBaseDN() {
        return baseDN;
    }
 
    public void setBaseDN(String baseDN) {
        this.baseDN = baseDN;
    }
 
    public String getBackendType() {
        return backendType;
    }
 
    public void setBackendType(String backendType) {
        this.backendType = backendType;
    }
 
    public int getJmxPort() {
        return jmxPort;
    }
 
    public void setJmxPort(int jmxPort) {
        this.jmxPort = jmxPort;
    }
 
    public String getLdifSchema() {
        return ldifSchema;
    }
 
    public void setLdifSchema(String ldifSchema) {
        this.ldifSchema = ldifSchema;
    }
 
    public String getFile() {
        return file;
    }
 
    public void setFile(String file) {
        this.file = file;
    }
 
 
    public Set<String> getSkipSet() {
        return skipSet;
    }
 
    public void setSkipSet(Set<String> skipSet) {
        this.skipSet = skipSet;
    }
 
    /**
     * Returns how long {@link EmbeddedOpenDJ#close()} retries the deletion of the temporary
     * directory of the instance, in milliseconds.
     * <p>
     * The deletion has to be retried because a file cannot be deleted on Windows while a
     * handle to it is still open, and the server threads release their handles shortly after
     * the server has been stopped. Whatever is still locked when this expires is scheduled for
     * deletion on JVM exit. Set it to {@code 0} to delete once and never wait.
     *
     * @return the deletion timeout in milliseconds
     */
    public long getDeleteTimeout() {
        return deleteTimeout;
    }
 
    /**
     * Sets how long {@link EmbeddedOpenDJ#close()} retries the deletion of the temporary
     * directory of the instance.
     *
     * @param deleteTimeout
     *            the deletion timeout in milliseconds, {@code 0} to delete once and never wait
     * @throws IllegalArgumentException
     *             If the timeout is negative.
     */
    public void setDeleteTimeout(long deleteTimeout) {
        if (deleteTimeout < 0) {
            throw new IllegalArgumentException("The delete timeout cannot be negative, but was " + deleteTimeout);
        }
        this.deleteTimeout = deleteTimeout;
    }
 
    @Override
    public String toString() {
        return "Config {" +
                "port=" + port +
                ", adminPort=" + adminPort +
                ", adminPassword='" + adminPassword + '\'' +
                ", baseDN='" + baseDN + '\'' +
                ", backendType='" + backendType + '\'' +
                ", jmxPort=" + jmxPort +
                ", ldifSchema='" + ldifSchema + '\'' +
                ", file='" + file + '\'' +
                ", skipSet=" + skipSet +
                ", deleteTimeout=" + deleteTimeout +
                '}';
    }
}