17
17
import org .elasticsearch .common .settings .Settings ;
18
18
import org .elasticsearch .common .util .set .Sets ;
19
19
import org .elasticsearch .env .Environment ;
20
- import org .elasticsearch .xpack .core .XPackField ;
21
20
import org .elasticsearch .xpack .core .XPackSettings ;
22
21
import org .elasticsearch .xpack .core .security .authc .support .Hasher ;
23
- import org .elasticsearch .xpack .security .authz .store .FileRolesStore ;
24
22
import org .elasticsearch .xpack .core .security .authz .store .ReservedRolesStore ;
25
23
import org .elasticsearch .xpack .core .security .support .Validation ;
26
24
import org .elasticsearch .xpack .core .security .support .Validation .Users ;
27
25
import org .elasticsearch .xpack .security .authc .file .FileUserPasswdStore ;
28
26
import org .elasticsearch .xpack .security .authc .file .FileUserRolesStore ;
27
+ import org .elasticsearch .xpack .security .authz .store .FileRolesStore ;
29
28
import org .elasticsearch .xpack .security .support .FileAttributesChecker ;
30
29
31
30
import java .nio .file .Files ;
@@ -47,7 +46,7 @@ public static void main(String[] args) throws Exception {
47
46
}
48
47
49
48
UsersTool () {
50
- super ("Manages elasticsearch native users" );
49
+ super ("Manages elasticsearch file users" );
51
50
subcommands .put ("useradd" , newAddUserCommand ());
52
51
subcommands .put ("userdel" , newDeleteUserCommand ());
53
52
subcommands .put ("passwd" , newPasswordCommand ());
@@ -82,7 +81,7 @@ static class AddUserCommand extends EnvironmentAwareCommand {
82
81
private final OptionSpec <String > arguments ;
83
82
84
83
AddUserCommand () {
85
- super ("Adds a native user" );
84
+ super ("Adds a file user" );
86
85
87
86
this .passwordOption = parser .acceptsAll (Arrays .asList ("p" , "password" ),
88
87
"The user password" )
@@ -96,11 +95,8 @@ static class AddUserCommand extends EnvironmentAwareCommand {
96
95
@ Override
97
96
protected void printAdditionalHelp (Terminal terminal ) {
98
97
terminal .println ("Adds a file based user to elasticsearch (via internal realm). The user will" );
99
- terminal .println ("be added to the users file and its roles will be added to the" );
100
- terminal .println ("users_roles file. If non-default files are used (different file" );
101
- terminal .println ("locations are configured in elasticsearch.yml) the appropriate files" );
102
- terminal .println ("will be resolved from the settings and the user and its roles will be" );
103
- terminal .println ("added to them." );
98
+ terminal .println ("be added to the \" users\" file and its roles will be added to the" );
99
+ terminal .println ("\" users_roles\" file in the elasticsearch config directory." );
104
100
terminal .println ("" );
105
101
}
106
102
@@ -123,7 +119,7 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
123
119
124
120
Map <String , char []> users = FileUserPasswdStore .parseFile (passwordFile , null , env .settings ());
125
121
if (users == null ) {
126
- throw new UserException (ExitCodes .CONFIG , "Configuration file [users ] is missing" );
122
+ throw new UserException (ExitCodes .CONFIG , "Configuration file [" + passwordFile + " ] is missing" );
127
123
}
128
124
if (users .containsKey (username )) {
129
125
throw new UserException (ExitCodes .CODE_ERROR , "User [" + username + "] already exists" );
@@ -155,11 +151,8 @@ static class DeleteUserCommand extends EnvironmentAwareCommand {
155
151
@ Override
156
152
protected void printAdditionalHelp (Terminal terminal ) {
157
153
terminal .println ("Removes an existing file based user from elasticsearch. The user will be" );
158
- terminal .println ("removed from the users file and its roles will be removed from the" );
159
- terminal .println ("users_roles file. If non-default files are used (different file" );
160
- terminal .println ("locations are configured in elasticsearch.yml) the appropriate files" );
161
- terminal .println ("will be resolved from the settings and the user and its roles will be" );
162
- terminal .println ("removed from them." );
154
+ terminal .println ("removed from the \" users\" file and its roles will be removed from the" );
155
+ terminal .println ("\" users_roles\" file in the elasticsearch config directory." );
163
156
terminal .println ("" );
164
157
}
165
158
@@ -173,7 +166,7 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
173
166
174
167
Map <String , char []> users = FileUserPasswdStore .parseFile (passwordFile , null , env .settings ());
175
168
if (users == null ) {
176
- throw new UserException (ExitCodes .CONFIG , "Configuration file [users ] is missing" );
169
+ throw new UserException (ExitCodes .CONFIG , "Configuration file [" + passwordFile + " ] is missing" );
177
170
}
178
171
if (users .containsKey (username ) == false ) {
179
172
throw new UserException (ExitCodes .NO_USER , "User [" + username + "] doesn't exist" );
@@ -213,12 +206,10 @@ static class PasswordCommand extends EnvironmentAwareCommand {
213
206
214
207
@ Override
215
208
protected void printAdditionalHelp (Terminal terminal ) {
216
- terminal .println ("The passwd command changes passwords for files based users. The tool" );
209
+ terminal .println ("The passwd command changes passwords for file based users. The tool" );
217
210
terminal .println ("prompts twice for a replacement password. The second entry is compared" );
218
211
terminal .println ("against the first and both are required to match in order for the" );
219
- terminal .println ("password to be changed. If non-default users file is used (a different" );
220
- terminal .println ("file location is configured in elasticsearch.yml) the appropriate file" );
221
- terminal .println ("will be resolved from the settings." );
212
+ terminal .println ("password to be changed." );
222
213
terminal .println ("" );
223
214
}
224
215
@@ -232,7 +223,7 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
232
223
FileAttributesChecker attributesChecker = new FileAttributesChecker (file );
233
224
Map <String , char []> users = new HashMap <>(FileUserPasswdStore .parseFile (file , null , env .settings ()));
234
225
if (users == null ) {
235
- throw new UserException (ExitCodes .CONFIG , "Configuration file [users ] is missing" );
226
+ throw new UserException (ExitCodes .CONFIG , "Configuration file [" + file + " ] is missing" );
236
227
}
237
228
if (users .containsKey (username ) == false ) {
238
229
throw new UserException (ExitCodes .NO_USER , "User [" + username + "] doesn't exist" );
@@ -345,19 +336,19 @@ static void listUsersAndRoles(Terminal terminal, Environment env, String usernam
345
336
Path userRolesFilePath = FileUserRolesStore .resolveFile (env );
346
337
Map <String , String []> userRoles = FileUserRolesStore .parseFile (userRolesFilePath , null );
347
338
if (userRoles == null ) {
348
- throw new UserException (ExitCodes .CONFIG , "Configuration file [users_roles ] is missing" );
339
+ throw new UserException (ExitCodes .CONFIG , "Configuration file [" + userRolesFilePath + " ] is missing" );
349
340
}
350
341
351
342
Path userFilePath = FileUserPasswdStore .resolveFile (env );
352
343
Map <String , char []> users = FileUserPasswdStore .parseFile (userFilePath , null , env .settings ());
353
344
if (users == null ) {
354
- throw new UserException (ExitCodes .CONFIG , "Configuration file [users ] is missing" );
345
+ throw new UserException (ExitCodes .CONFIG , "Configuration file [" + userFilePath + " ] is missing" );
355
346
}
356
347
357
348
Path rolesFilePath = FileRolesStore .resolveFile (env );
358
349
Set <String > knownRoles = Sets .union (FileRolesStore .parseFileForRoleNames (rolesFilePath , null ), ReservedRolesStore .names ());
359
350
if (knownRoles == null ) {
360
- throw new UserException (ExitCodes .CONFIG , "Configuration file [roles.xml ] is missing" );
351
+ throw new UserException (ExitCodes .CONFIG , "Configuration file [" + rolesFilePath + " ] is missing" );
361
352
}
362
353
363
354
if (username != null ) {
0 commit comments