23
23
import com .fasterxml .jackson .databind .node .ObjectNode ;
24
24
import java .io .Console ;
25
25
import java .io .IOException ;
26
- import java .io .PrintStream ;
27
26
import java .net .URL ;
28
27
import java .nio .charset .StandardCharsets ;
29
28
import java .nio .file .Files ;
@@ -101,12 +100,8 @@ public class AuthTool extends ToolBase {
101
100
"This is where any authentication related configuration files, if any, would be placed. Defaults to $SOLR_HOME." )
102
101
.build ();
103
102
104
- public AuthTool () {
105
- this (CLIO .getOutStream ());
106
- }
107
-
108
- public AuthTool (PrintStream stdout ) {
109
- super (stdout );
103
+ public AuthTool (ToolRuntime runtime ) {
104
+ super (runtime );
110
105
}
111
106
112
107
@ Override
@@ -155,7 +150,7 @@ private void ensureArgumentIsValidBooleanIfPresent(CommandLine cli, Option optio
155
150
+ "] must be either true or false, but was ["
156
151
+ value
157
152
+ "]" );
158
- SolrCLI .exit (1 );
153
+ runtime .exit (1 );
159
154
}
160
155
}
161
156
}
@@ -169,12 +164,12 @@ private void handleBasicAuth(CommandLine cli) throws Exception {
169
164
case "enable" :
170
165
if (!prompt && !cli .hasOption (CommonCLIOptions .CREDENTIALS_OPTION )) {
171
166
CLIO .out ("Option --credentials or --prompt is required with enable." );
172
- SolrCLI .exit (1 );
167
+ runtime .exit (1 );
173
168
} else if (!prompt
174
169
&& (cli .getOptionValue (CommonCLIOptions .CREDENTIALS_OPTION ) == null
175
170
|| !cli .getOptionValue (CommonCLIOptions .CREDENTIALS_OPTION ).contains (":" ))) {
176
171
CLIO .out ("Option --credentials is not in correct format." );
177
- SolrCLI .exit (1 );
172
+ runtime .exit (1 );
178
173
}
179
174
180
175
String zkHost = null ;
@@ -190,7 +185,7 @@ private void handleBasicAuth(CommandLine cli) throws Exception {
190
185
CLIO .out (
191
186
"Couldn't get ZooKeeper host. Please make sure Solr is running in cloud mode, or a zk-host has been passed in." );
192
187
}
193
- SolrCLI .exit (1 );
188
+ runtime .exit (1 );
194
189
}
195
190
if (zkHost == null ) {
196
191
if (cli .hasOption (CommonCLIOptions .ZK_HOST_OPTION )) {
@@ -200,7 +195,7 @@ private void handleBasicAuth(CommandLine cli) throws Exception {
200
195
CLIO .out (
201
196
"Couldn't get ZooKeeper host. Please make sure Solr is running in cloud mode, or a zk-host has been passed in." );
202
197
}
203
- SolrCLI .exit (1 );
198
+ runtime .exit (1 );
204
199
}
205
200
206
201
// check if security is already enabled or not
@@ -264,15 +259,15 @@ private void handleBasicAuth(CommandLine cli) throws Exception {
264
259
CLIO .out (
265
260
"Solr include file " + solrIncludeFilename + " doesn't exist or is not writeable." );
266
261
printAuthEnablingInstructions (username , password );
267
- System .exit (0 );
262
+ runtime .exit (0 );
268
263
}
269
264
String authConfDir = cli .getOptionValue (AUTH_CONF_DIR_OPTION );
270
265
Path basicAuthConfFile = Path .of (authConfDir , "basicAuth.conf" );
271
266
272
267
if (!Files .isWritable (basicAuthConfFile .getParent ())) {
273
268
CLIO .out ("Cannot write to file: " + basicAuthConfFile .toAbsolutePath ());
274
269
printAuthEnablingInstructions (username , password );
275
- System .exit (0 );
270
+ runtime .exit (0 );
276
271
}
277
272
278
273
Files .writeString (
@@ -297,19 +292,19 @@ private void handleBasicAuth(CommandLine cli) throws Exception {
297
292
"Solr include file " + solrIncludeFilename + " doesn't exist or is not writeable." );
298
293
CLIO .out (
299
294
"Security has been disabled. Please remove any SOLR_AUTH_TYPE or SOLR_AUTHENTICATION_OPTS configuration from solr.in.sh/solr.in.cmd.\n " );
300
- System .exit (0 );
295
+ runtime .exit (0 );
301
296
}
302
297
303
298
// update the solr.in.sh file to comment out the necessary authentication lines
304
299
updateIncludeFileDisableAuth (includeFile );
305
300
return ;
306
301
default :
307
302
CLIO .out ("Valid auth commands are: enable, disable." );
308
- SolrCLI .exit (1 );
303
+ runtime .exit (1 );
309
304
}
310
305
311
306
CLIO .out ("Options not understood." );
312
- SolrCLI .exit (1 );
307
+ runtime .exit (1 );
313
308
}
314
309
315
310
private void checkSecurityJsonExists (SolrZkClient zkClient )
@@ -320,7 +315,7 @@ private void checkSecurityJsonExists(SolrZkClient zkClient)
320
315
CLIO .out (
321
316
"Security is already enabled. You can disable it with 'bin/solr auth disable'. Existing security.json: \n "
322
317
+ new String (oldSecurityBytes , StandardCharsets .UTF_8 ));
323
- SolrCLI .exit (1 );
318
+ runtime .exit (1 );
324
319
}
325
320
}
326
321
}
@@ -330,8 +325,8 @@ private void clearSecurityJson(CommandLine cli, boolean updateIncludeFileOnly) t
330
325
if (!updateIncludeFileOnly ) {
331
326
zkHost = CLIUtils .getZkHost (cli );
332
327
if (zkHost == null ) {
333
- stdout .print ("ZK Host not found. Solr should be running in cloud mode." );
334
- SolrCLI .exit (1 );
328
+ runtime .print ("ZK Host not found. Solr should be running in cloud mode." );
329
+ runtime .exit (1 );
335
330
}
336
331
337
332
echoIfVerbose ("Uploading following security.json: {}" );
0 commit comments