|
9 | 9 | import org.apache.logging.log4j.Logger;
|
10 | 10 | import org.elasticsearch.ExceptionsHelper;
|
11 | 11 | import org.elasticsearch.common.Randomness;
|
12 |
| -import org.elasticsearch.common.Strings; |
13 | 12 | import org.elasticsearch.common.logging.Loggers;
|
14 | 13 | import org.elasticsearch.common.settings.Settings;
|
15 | 14 | import org.elasticsearch.test.ESTestCase;
|
16 |
| -import org.elasticsearch.xpack.core.security.authc.kerberos.KerberosRealmSettings; |
17 | 15 | import org.junit.After;
|
18 | 16 | import org.junit.AfterClass;
|
19 | 17 | import org.junit.Before;
|
20 | 18 | import org.junit.BeforeClass;
|
21 | 19 |
|
22 |
| -import java.io.BufferedWriter; |
23 | 20 | import java.io.IOException;
|
24 |
| -import java.nio.charset.StandardCharsets; |
25 |
| -import java.nio.file.Files; |
26 | 21 | import java.nio.file.Path;
|
27 | 22 | import java.security.AccessController;
|
28 | 23 | import java.security.PrivilegedActionException;
|
@@ -130,12 +125,14 @@ public void startSimpleKdcLdapServer() throws Exception {
|
130 | 125 | throw ExceptionsHelper.convertToRuntime(e);
|
131 | 126 | }
|
132 | 127 | });
|
133 |
| - settings = buildKerberosRealmSettings(ktabPathForService.toString()); |
| 128 | + settings = KerberosRealmTestCase.buildKerberosRealmSettings(ktabPathForService.toString()); |
134 | 129 | }
|
135 | 130 |
|
136 | 131 | @After
|
137 | 132 | public void tearDownMiniKdc() throws IOException, PrivilegedActionException {
|
138 |
| - simpleKdcLdapServer.stop(); |
| 133 | + if (simpleKdcLdapServer != null) { |
| 134 | + simpleKdcLdapServer.stop(); |
| 135 | + } |
139 | 136 | }
|
140 | 137 |
|
141 | 138 | /**
|
@@ -186,49 +183,4 @@ static <T> T doAsWrapper(final Subject subject, final PrivilegedExceptionAction<
|
186 | 183 | return AccessController.doPrivileged((PrivilegedExceptionAction<T>) () -> Subject.doAs(subject, action));
|
187 | 184 | }
|
188 | 185 |
|
189 |
| - /** |
190 |
| - * Write content to provided keytab file. |
191 |
| - * |
192 |
| - * @param keytabPath {@link Path} to keytab file. |
193 |
| - * @param content Content for keytab |
194 |
| - * @return key tab path |
195 |
| - * @throws IOException if I/O error occurs while writing keytab file |
196 |
| - */ |
197 |
| - public static Path writeKeyTab(final Path keytabPath, final String content) throws IOException { |
198 |
| - try (BufferedWriter bufferedWriter = Files.newBufferedWriter(keytabPath, StandardCharsets.US_ASCII)) { |
199 |
| - bufferedWriter.write(Strings.isNullOrEmpty(content) ? "test-content" : content); |
200 |
| - } |
201 |
| - return keytabPath; |
202 |
| - } |
203 |
| - |
204 |
| - /** |
205 |
| - * Build kerberos realm settings with default config and given keytab |
206 |
| - * |
207 |
| - * @param keytabPath key tab file path |
208 |
| - * @return {@link Settings} for kerberos realm |
209 |
| - */ |
210 |
| - public static Settings buildKerberosRealmSettings(final String keytabPath) { |
211 |
| - return buildKerberosRealmSettings(keytabPath, 100, "10m", true, false); |
212 |
| - } |
213 |
| - |
214 |
| - /** |
215 |
| - * Build kerberos realm settings |
216 |
| - * |
217 |
| - * @param keytabPath key tab file path |
218 |
| - * @param maxUsersInCache max users to be maintained in cache |
219 |
| - * @param cacheTTL time to live for cached entries |
220 |
| - * @param enableDebugging for krb5 logs |
221 |
| - * @param removeRealmName {@code true} if we want to remove realm name from the username of form 'user@REALM' |
222 |
| - * @return {@link Settings} for kerberos realm |
223 |
| - */ |
224 |
| - public static Settings buildKerberosRealmSettings(final String keytabPath, final int maxUsersInCache, final String cacheTTL, |
225 |
| - final boolean enableDebugging, final boolean removeRealmName) { |
226 |
| - final Settings.Builder builder = Settings.builder().put(KerberosRealmSettings.HTTP_SERVICE_KEYTAB_PATH.getKey(), keytabPath) |
227 |
| - .put(KerberosRealmSettings.CACHE_MAX_USERS_SETTING.getKey(), maxUsersInCache) |
228 |
| - .put(KerberosRealmSettings.CACHE_TTL_SETTING.getKey(), cacheTTL) |
229 |
| - .put(KerberosRealmSettings.SETTING_KRB_DEBUG_ENABLE.getKey(), enableDebugging) |
230 |
| - .put(KerberosRealmSettings.SETTING_REMOVE_REALM_NAME.getKey(), removeRealmName); |
231 |
| - return builder.build(); |
232 |
| - } |
233 |
| - |
234 | 186 | }
|
0 commit comments