Revision 8488
Added by Jing Tao about 11 years ago
src/edu/ucsb/nceas/metacat/authentication/AuthFile.java | ||
---|---|---|
90 | 90 |
private static final String EMAIL = "email"; |
91 | 91 |
private static final String SURNAME = "surName"; |
92 | 92 |
private static final String GIVENNAME = "givenName"; |
93 |
private static final String MEMBEROF = "memberof"; |
|
93 | 94 |
private static final String INITCONTENT = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"+ |
94 | 95 |
"<"+SUBJECTS+">\n"+"<"+USERS+">\n"+"</"+USERS+">\n"+"<"+GROUPS+">\n"+"</"+GROUPS+">\n"+"</"+SUBJECTS+">\n"; |
95 | 96 |
|
... | ... | |
277 | 278 |
*/ |
278 | 279 |
public String[] getUsers(String user, String password, String group) |
279 | 280 |
throws ConnectException { |
280 |
List<Object> users = userpassword.getList(USERS+SLASH+USER+"["+GROUP+"='"+group+"']"+SLASH+AT+DN);
|
|
281 |
List<Object> users = userpassword.getList(USERS+SLASH+USER+"["+MEMBEROF+"='"+group+"']"+SLASH+AT+DN);
|
|
281 | 282 |
if(users != null && users.size() > 0) { |
282 | 283 |
String[] usersArray = new String[users.size()]; |
283 | 284 |
for(int i=0; i<users.size(); i++) { |
... | ... | |
320 | 321 |
*/ |
321 | 322 |
public String[][] getGroups(String user, String password, String foruser) |
322 | 323 |
throws ConnectException { |
323 |
List<Object> groups = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+foruser+"']"+SLASH+GROUP);
|
|
324 |
List<Object> groups = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+foruser+"']"+SLASH+MEMBEROF);
|
|
324 | 325 |
if(groups != null && groups.size() > 0) { |
325 | 326 |
String[][] groupsArray = new String[groups.size()][2]; |
326 | 327 |
for(int i=0; i<groups.size(); i++) { |
... | ... | |
618 | 619 |
*/ |
619 | 620 |
private static void handleGroupAdd(AuthFile authFile, String[]argus) throws AuthenticationException { |
620 | 621 |
HashMap<String, String> map = new <String, String>HashMap(); |
621 |
String DASHG = "-g"; |
|
622 |
String DASHD = "-d"; |
|
622 |
String G = "-g"; |
|
623 |
String D = "-d"; |
|
624 |
Vector<String> possibleOptions = new <String>Vector(); |
|
625 |
possibleOptions.add(G); |
|
626 |
possibleOptions.add(D); |
|
623 | 627 |
for(int i=2; i<argus.length; i++) { |
624 | 628 |
String arg = argus[i]; |
625 | 629 |
|
... | ... | |
628 | 632 |
System.exit(1); |
629 | 633 |
} |
630 | 634 |
|
631 |
if(arg.equals(DASHG) && i<argus.length-1) { |
|
632 |
map.put(arg, argus[i+1]); |
|
633 |
} else if (arg.equals(DASHD) && i<argus.length-1) { |
|
634 |
map.put(arg, argus[i+1]); |
|
635 |
} else if(!arg.equals(DASHG) && !arg.equals(DASHD)) { |
|
636 |
//check if the previous argument is -g or -d |
|
637 |
if(!argus[i-1].equals(DASHG) && !argus[i-1].equals(DASHD)) { |
|
635 |
|
|
636 |
if(possibleOptions.contains(arg) && i<argus.length-1) { |
|
637 |
if(possibleOptions.contains(argus[i+1])) { |
|
638 |
//scenario that -d follows -g |
|
639 |
System.out.println("Error: the \""+arg+"\" must be followed by a value rather than an option \""+argus[i+1]+"\""); |
|
640 |
System.exit(1); |
|
641 |
} else { |
|
642 |
map.put(arg, argus[i+1]); |
|
643 |
} |
|
644 |
} else if(!possibleOptions.contains(arg)) { |
|
645 |
//when the argu is not a switch check if the previous argument is a switch |
|
646 |
if(!possibleOptions.contains(argus[i-1])) { |
|
638 | 647 |
System.out.println("Error: an illegal argument "+arg+" in the groupadd command "); |
639 | 648 |
System.exit(1); |
640 | 649 |
} |
... | ... | |
643 | 652 |
String groupName = null; |
644 | 653 |
String description = null; |
645 | 654 |
if(map.keySet().size() == 0) { |
646 |
System.out.println("Error: the "+DASHG+" group-name is required in the groupadd command line.");
|
|
655 |
System.out.println("Error: the "+G+" group-name is required in the groupadd command line."); |
|
647 | 656 |
System.exit(1); |
648 | 657 |
} |
649 | 658 |
else if(map.keySet().size() ==1 || map.keySet().size() ==2) { |
650 |
groupName = map.get(DASHG);
|
|
659 |
groupName = map.get(G); |
|
651 | 660 |
if(groupName == null) { |
652 |
System.out.println("Error: the "+DASHG+" group-name is required in the groupadd command line.");
|
|
661 |
System.out.println("Error: the "+G+" group-name is required in the groupadd command line."); |
|
653 | 662 |
System.exit(1); |
654 | 663 |
} |
655 |
description = map.get(DASHD);
|
|
664 |
description = map.get(D); |
|
656 | 665 |
authFile.addGroup(groupName, description); |
657 | 666 |
System.out.println("Successfully added a group "+groupName+" to the file authentication system"); |
658 | 667 |
} else { |
... | ... | |
903 | 912 |
if(arg.equals(A) || arg.equals(R)) { |
904 | 913 |
//this is the scenario that "-a" or "-r" is NOT at the end of the arguments. |
905 | 914 |
if(!possibleOptions.contains(argus[i+1])) { |
906 |
System.out.println("Error: The option \"-i\" means the user will input a password in the usermod -group command. So it can't be followed by a value. It only can be followed by another option.");
|
|
915 |
System.out.println("Error: the option \"-a\" or \"-d\" shouldn't follow any value.");
|
|
907 | 916 |
System.exit(1); |
908 | 917 |
} |
909 | 918 |
map.put(arg, arg); |
... | ... | |
963 | 972 |
} |
964 | 973 |
|
965 | 974 |
while(true) { |
966 |
System.out.print("Enter your password(input 'q' to quite): "); |
|
975 |
System.out.print("Enter your new password(input 'q' to quite): ");
|
|
967 | 976 |
String password1 = new String(console.readPassword()); |
968 | 977 |
if(password1== null || password1.trim().equals("")) { |
969 | 978 |
System.out.println("Eorror: the password can't be blank or null. Please try again."); |
... | ... | |
971 | 980 |
} else if (password1.equals(quit)) { |
972 | 981 |
System.exit(0); |
973 | 982 |
} |
974 |
System.out.print("Confirm your password(input 'q' to quite): "); |
|
983 |
System.out.print("Confirm your new password(input 'q' to quite): ");
|
|
975 | 984 |
String password2 = new String(console.readPassword()); |
976 | 985 |
if(password2 == null || password2.trim().equals("")) { |
977 | 986 |
System.out.println("Eorror: the password can't be blank or null. Please try again."); |
... | ... | |
1217 | 1226 |
if(!groupExists(group)) { |
1218 | 1227 |
throw new AuthenticationException("AuthFile.User.addUserToGroup - the group "+group+ " doesn't exist."); |
1219 | 1228 |
} |
1220 |
List<Object> existingGroups = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+GROUP);
|
|
1229 |
List<Object> existingGroups = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+MEMBEROF);
|
|
1221 | 1230 |
if(existingGroups != null && existingGroups.contains(group)) { |
1222 | 1231 |
throw new AuthenticationException("AuthFile.User.addUserToGroup - the user "+dn+ " already is the memember of the group "+group); |
1223 | 1232 |
} |
1224 |
userpassword.addProperty(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+" "+GROUP, group);
|
|
1233 |
userpassword.addProperty(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+" "+MEMBEROF, group);
|
|
1225 | 1234 |
//add information to the memory |
1226 | 1235 |
if(groups == null) { |
1227 | 1236 |
if(existingGroups == null || existingGroups.isEmpty()) { |
... | ... | |
1258 | 1267 |
if(!groupExists(group)) { |
1259 | 1268 |
throw new AuthenticationException("AuthFile.User.removeUserFromGroup - the group "+group+ " doesn't exist."); |
1260 | 1269 |
} |
1261 |
String key = USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+GROUP;
|
|
1270 |
String key = USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+MEMBEROF;
|
|
1262 | 1271 |
List<Object> existingGroups = userpassword.getList(key); |
1263 | 1272 |
if(!existingGroups.contains(group)) { |
1264 | 1273 |
throw new AuthenticationException("AuthFile.User.removeUserFromGroup - the user "+dn+ " isn't the memember of the group "+group); |
... | ... | |
1370 | 1379 |
String group = groups[i]; |
1371 | 1380 |
if(group != null && !group.trim().equals("")) { |
1372 | 1381 |
if(groupExists(group)) { |
1373 |
userpassword.addProperty(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+" "+GROUP, group);
|
|
1382 |
userpassword.addProperty(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+" "+MEMBEROF, group);
|
|
1374 | 1383 |
} |
1375 | 1384 |
} |
1376 | 1385 |
} |
Also available in: Unified diff
Change the element name in the user from "group" to "memberof".
Fixed a bug that in groupadd.