source: greenstone3/trunk/src/java/org/greenstone/gsdl3/service/Authentication.java@ 14349

Last change on this file since 14349 was 14349, checked in by qq6, 17 years ago

put some comments

File size: 24.1 KB
Line 
1package org.greenstone.gsdl3.service;
2
3import org.greenstone.gsdl3.util.GSXML;
4import org.greenstone.gsdl3.util.GSPath;
5import org.greenstone.gsdl3.util.DerbyWrapper;
6import org.greenstone.gsdl3.util.UserQueryResult;
7import org.greenstone.gsdl3.util.UserTermInfo;
8import org.greenstone.gsdl3.util.GlobalProperties;
9
10import org.w3c.dom.Element;
11import org.w3c.dom.NodeList;
12
13import java.util.ArrayList;
14import java.util.Map;
15import java.util.Iterator;
16import java.util.Set;
17import java.util.HashMap;
18import java.util.Vector;
19import java.sql.SQLException;
20import org.apache.log4j.*;
21
22import java.net.InetAddress;
23import java.net.URLEncoder;
24import java.util.Properties;
25import java.util.Date;
26import java.util.regex.Pattern;
27import java.io.File;
28import java.io.UnsupportedEncodingException;
29//import javax.mail.*;
30//import javax.mail.internet.*;
31
32import java.awt.event.ActionEvent;
33import java.awt.event.ActionListener;
34import javax.swing.Timer;
35
36import org.apache.log4j.*;
37
38public class Authentication
39 extends ServiceRack {
40 //the services on offer
41 protected static final String AUTHENTICATION_SERVICE="Authentication";
42
43 /** constructor */
44 public Authentication()
45 { }
46
47 public boolean configure(Element info, Element extra_info)
48 {
49 logger.info("Configuring Authentication...");
50 this.config_info = info;
51
52 // set up Authentication service info - for now just has name and type
53 Element authentication_service= this.doc.createElement(GSXML.SERVICE_ELEM);
54 authentication_service.setAttribute(GSXML.TYPE_ATT, "authen");
55 authentication_service.setAttribute(GSXML.NAME_ATT, AUTHENTICATION_SERVICE);
56 this.short_service_info.appendChild(authentication_service);
57
58 return true;
59 }
60
61 protected Element getServiceDescription(String service_id, String lang, String subset)
62 {
63
64 Element authen_service=this.doc.createElement(GSXML.SERVICE_ELEM);
65
66 if (service_id.equals(AUTHENTICATION_SERVICE)) {
67 authen_service.setAttribute(GSXML.TYPE_ATT,"authen");
68 authen_service.setAttribute(GSXML.NAME_ATT, AUTHENTICATION_SERVICE);
69 } else {
70 return null;
71 }
72
73 if (subset==null || subset.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
74 authen_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, getServiceName(service_id, lang) ));
75 authen_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getServiceDescription(service_id, lang)));
76 }
77 return authen_service;
78 }
79
80 protected String getServiceName(String service_id, String lang) {
81 return getTextString(service_id+".name", lang);
82 }
83
84 protected String getServiceSubmit(String service_id, String lang) {
85 return getTextString(service_id+".submit", lang);
86 }
87
88 protected String getServiceDescription(String service_id, String lang) {
89 return getTextString(service_id+".description", lang);
90 }
91
92 protected void addCustomParams(String service, Element param_list, String lang) {
93 }
94
95 protected void createParameter(String name, Element param_list, String lang) {
96 }
97
98 protected Element processAuthentication(Element request) throws SQLException, UnsupportedEncodingException{
99
100 // Create a new (empty) result message
101 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
102
103 result.setAttribute(GSXML.FROM_ATT, AUTHENTICATION_SERVICE);
104 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
105
106 String lang = request.getAttribute(GSXML.LANG_ATT);
107 // Get the parameters of the request
108 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
109
110 if (param_list == null) {
111 logger.error("AddUsers request had no paramList.");
112 return result; // Return the empty result
113 }
114
115 String aup=null; //Actions: ListUsers, AddUser, ModifyPassword, DeleteUser, Login
116 String un=""; //login user's name
117 String pw=""; //login user's password
118 String asn=""; //whether a user is authenticated
119 String uan=""; //whether a authentication for a particular action is needed
120 String cm=""; //whether the action is confirmed
121
122 String umun=""; //the new user name
123 String umpw=""; //user's new password
124 String umas=""; //user account status
125 String umgp=""; //user greoups
126 String umc=""; // comments for the user
127
128 String oumun=""; //the original user's name
129 String umpw1=""; //user's new password
130 String umpw2=""; //user's retyped new password
131
132 // get parameters from the request
133 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
134 for (int i=0; i<params.getLength();i++) {
135 Element param = (Element)params.item(i);
136 String p_name = param.getAttribute(GSXML.NAME_ATT);
137 String p_value = GSXML.getValue(param);
138
139 if (p_name.equals("aup")){
140 aup = p_value;
141 }else if (p_name.equals("un")) {
142 un = p_value;
143 }else if(p_name.equals("pw")) {
144 pw = p_value;
145 }else if(p_name.equals("umun")) {
146 umun = p_value;
147 }else if(p_name.equals("umpw")) {
148 umpw = p_value;
149 }else if (p_name.equals("umas")){
150 umas = p_value;
151 }else if (p_name.equals("umgp")){
152 umgp = p_value;
153 }else if (p_name.equals("umc")){
154 umc = p_value;
155 }else if (p_name.equals("asn")){
156 asn = p_value;
157 }else if (p_name.equals("uan")){
158 uan = p_value;
159 }else if (p_name.equals("cm")){
160 cm = p_value;
161 }else if(p_name.equals("umpw1")) {
162 umpw1 = p_value;
163 }else if(p_name.equals("umpw2")) {
164 umpw2 = p_value;
165 }else if(p_name.equals("oumun")) {
166 oumun = p_value;
167 }
168
169 }
170
171 // create a Authentication node put into the result
172 Element authen_node = this.doc.createElement(GSXML.AUTHEN_NODE_ELEM);
173 result.appendChild(authen_node);
174 // create a service node added into the Authentication node
175 Element service_node = this.doc.createElement(GSXML.SERVICE_ELEM);
176 authen_node.appendChild(service_node);
177 service_node.setAttribute("aup",aup);
178 // user's info
179 UserQueryResult userQueryResult=null;
180
181 // check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the user database and add a "admin" user
182 String usersDB_dir = this.site_home + File.separatorChar + "etc" + File.separatorChar + "usersDB";
183 DerbyWrapper derbyWrapper=new DerbyWrapper();
184 File usersDB_file =new File(usersDB_dir);
185 if (!usersDB_file.exists()){
186 String etc_dir = this.site_home + File.separatorChar + "etc";
187 File etc_file =new File(etc_dir);
188 if (!etc_file.exists()){
189 boolean success = etc_file.mkdir();
190 if (!success){
191 logger.error("Couldn't create the etc dir under "+this.site_home + ".");
192 return result;
193 }
194 }
195 derbyWrapper.connectDatabase(usersDB_dir,true);
196 derbyWrapper.createDatabase();
197 }else{
198 derbyWrapper.connectDatabase(usersDB_dir, false);
199 }
200
201 // Action: login
202 if (aup.equals("Login")){
203 if (uan.equals("")){ //return a login page, if the user's name is not given
204 service_node.setAttribute("info","Login");
205 derbyWrapper.closeDatabase();
206 return result;
207 }
208
209 // if the authentication(uan=1) is required,but the user hasn't been authenticated(asn=0),the user is asked to login first
210 if ((uan.equals("1") && asn.equals("0"))) {
211 if ((un.length()==0) && (pw.length()==0)){
212 service_node.setAttribute("asn","0");
213 service_node.setAttribute("info","Login");
214 derbyWrapper.closeDatabase();
215 return result;
216 }
217 if ((un.length()==0) || (pw.length()==0)){
218 service_node.setAttribute("asn","0");
219 service_node.setAttribute("info","Login");
220 service_node.setAttribute("err","un-pw-err");
221 derbyWrapper.closeDatabase();
222 return result;
223 }else{
224 userQueryResult=derbyWrapper.findUser(un,pw);//looking for the user from the users table
225 service_node.setAttribute(GSXML.NAME_ATT,"Authentication");
226 service_node.setAttribute("un",un);
227 if (userQueryResult==null){
228 //the user isn't a vaild user
229 service_node.setAttribute("asn","0");
230 service_node.setAttribute("err","un-pw-err");// either unsername or password is wrong
231 service_node.setAttribute("info","Login");
232 derbyWrapper.closeDatabase();
233 return result;
234 }else{
235 // asn="1"; //the user is a member of the "administrator" group
236 Vector userInfo=userQueryResult.users_;
237 String groups=((UserTermInfo)userInfo.get(0)).groups_;
238 String accountstatus=((UserTermInfo)userInfo.get(0)).accountstatus_;
239 if (accountstatus.trim().equals("false")){
240 service_node.setAttribute("asn","0");
241 service_node.setAttribute("err","as-false");//the account status is false
242 service_node.setAttribute("info","Login");
243 derbyWrapper.closeDatabase();
244 return result;
245 }
246 String[] groups_array=groups.split(",");
247 for (int i=0; i<groups_array.length;i++){
248 if ((groups_array[i].trim().toLowerCase()).equals("administrator")){// check whether the user is in the administrator group
249 asn="1";
250 service_node.setAttribute("asn","1");
251 break;
252 }
253 }
254 if (!asn.equals("1")){
255 asn="2";
256 service_node.setAttribute("asn","2");//the user is authenticated
257 }
258 }
259 }
260 }
261
262 //asn!=0 This is a valid user
263 if (!asn.equals("0")){
264 service_node.setAttribute("info","Login");
265 service_node.setAttribute("un",un);
266 service_node.setAttribute("asn",asn);
267 derbyWrapper.closeDatabase();
268 return result;
269 }
270 }
271
272 //Action: listuser
273 if (aup.equals("ListUsers")){
274 if (asn.equals("") && un.equals("")){
275 service_node.setAttribute("info","Login");
276 derbyWrapper.closeDatabase();
277 return result;
278 }
279
280 //valid users but not in the administrator group(asn=2), they cannot list all users
281 if (asn.equals("2")){
282 service_node.setAttribute("info","Login");
283 service_node.setAttribute("err","no-permission");
284 service_node.setAttribute("un",un);
285 service_node.setAttribute("asn",asn);
286 derbyWrapper.closeDatabase();
287 return result;
288 }
289 //valid users belong to the administrator group(asn=1), they can list all users
290 if (asn.equals("1")){
291 userQueryResult=derbyWrapper.findUser(null,null);
292 derbyWrapper.closeDatabase();
293 service_node.setAttribute(GSXML.NAME_ATT,"Authentication");
294 service_node.setAttribute("un",un);
295 service_node.setAttribute("asn",asn);
296
297 if (userQueryResult!=null && userQueryResult.getSize()>0){
298 service_node.setAttribute("info","all-un"); // got a user list
299 Element user_node=getUserNode(userQueryResult);
300 service_node.appendChild(user_node);
301 derbyWrapper.closeDatabase();
302 return result;
303 }else {
304 service_node.setAttribute("err","no-un"); // no user returned
305 derbyWrapper.closeDatabase();
306 return result;
307 }
308 }
309 }
310
311 //Action : adduder
312 if (aup.equals("AddUser")){
313 if (asn.equals("") && un.equals("")){
314 service_node.setAttribute("info","Login");
315 derbyWrapper.closeDatabase();
316 return result;
317 }
318 //valid users can't add a new user because they aren't in the administrator group(asn=2)
319 if (asn.equals("2")){
320 service_node.setAttribute("info","Login");
321 service_node.setAttribute("err","no-permission");
322 service_node.setAttribute("un",un);
323 service_node.setAttribute("asn",asn);
324 derbyWrapper.closeDatabase();
325 return result;
326 }
327 //valid users are in the administrator group, they can add a new user(asn=1)
328 if (asn.equals("1")){
329 service_node.setAttribute(GSXML.NAME_ATT,"Authentication");
330 service_node.setAttribute("un",un);
331 service_node.setAttribute("asn",asn);
332
333 if (umun.length()==0 && umpw.length()==0 && umgp.length()==0 && umas.length()==0 && umc.length()==0){
334 service_node.setAttribute("info","adduser_interface");
335 derbyWrapper.closeDatabase();
336 return result;
337 }
338
339 //check the strings of username and password
340 if ((umun==null) || (umun.length()<2) || (umun.length()>30) || (!(Pattern.matches("[a-zA-Z0-9//_//.]+",umun)))){
341 service_node.setAttribute("err","un-err"); //the input username string is illegal
342 service_node.setAttribute("info","adduser_interface");
343 derbyWrapper.closeDatabase();
344 return result;
345 }
346
347 if ((umpw==null) || (umpw.length()<3) || (umpw.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw)))){
348 service_node.setAttribute("err","pw-err"); //the input passwrod string is illegal
349 service_node.setAttribute("info","adduser_interface");
350 derbyWrapper.closeDatabase();
351 return result;
352 }
353
354 // add the new users into the users table
355 umgp=umgp.replaceAll(" ","");//get rid of the space of the groups string
356 userQueryResult=derbyWrapper.findUser(umun,null);// check whether the new user name has existed in the table.
357 if (userQueryResult!=null){
358 service_node.setAttribute("err","un-exist"); //the new username string is duplicated
359 service_node.setAttribute("info","adduser_interface");
360 derbyWrapper.closeDatabase();
361 return result;
362 }else{
363 String add_user=derbyWrapper.addUser(umun,umpw,umgp,umas,umc);
364 if (add_user.equals("succeed")){
365 userQueryResult=derbyWrapper.findUser(null,null);
366 derbyWrapper.closeDatabase();
367 service_node.setAttribute("info","all-un"); // return a list of all users if the user has been added
368 Element user_node=getUserNode(userQueryResult);
369 service_node.appendChild(user_node);
370 derbyWrapper.closeDatabase();
371 return result;
372 }else{
373 derbyWrapper.closeDatabase();
374 service_node.setAttribute("err",add_user);// return the error message if the user couldn't be added
375 derbyWrapper.closeDatabase();
376 return result;
377 }
378 }
379 }
380 }
381
382 //Action: edituser
383 if (aup.equals("EditUser")){
384 service_node.setAttribute(GSXML.NAME_ATT,"Authentication");
385 service_node.setAttribute("un",un);
386 service_node.setAttribute("asn",asn);
387
388 //Get the user's info from the database
389 if (cm.length()==0){
390 service_node.setAttribute("info","edituser-interface");
391 userQueryResult=derbyWrapper.findUser(umun,null);
392 derbyWrapper.closeDatabase();
393 Vector userInfo=userQueryResult.users_;
394 String username=((UserTermInfo)userInfo.get(0)).username_;
395 String password=((UserTermInfo)userInfo.get(0)).password_;
396 String groups=((UserTermInfo)userInfo.get(0)).groups_;
397 String accountstatus=((UserTermInfo)userInfo.get(0)).accountstatus_;
398 String comment=((UserTermInfo)userInfo.get(0)).comment_;
399
400 service_node.setAttribute("oumun",oumun);
401 service_node.setAttribute("umun",username);
402 service_node.setAttribute("umpw",password);
403 service_node.setAttribute("umgp",groups);
404 service_node.setAttribute("umas",accountstatus);
405 service_node.setAttribute("umc",comment);
406 derbyWrapper.closeDatabase();
407 return result;
408 }
409
410 //Commit the modified user's info to the database
411 if (cm.toLowerCase().equals("submit")){
412 if (oumun.equals(umun)){// the user's name hasn't been changed, update the user's info
413 if (umpw.length()==0){
414 derbyWrapper.modifyUserInfo(umun,null,umgp,umas,umc);
415 userQueryResult=derbyWrapper.findUser(null,null);
416 derbyWrapper.closeDatabase();
417 service_node.setAttribute("info","all-un"); // the user's info has been updated, return a list of all users
418 Element user_node=getUserNode(userQueryResult);
419 service_node.appendChild(user_node);
420 derbyWrapper.closeDatabase();
421 return result;
422 }else{
423 if ((umpw.length()==0) || (umpw.length()<3) || (umpw.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw)))){
424 service_node.setAttribute("err","umpw-err"); //the input passwrod string is illegal
425 service_node.setAttribute("info","edituser-interface");
426 service_node.setAttribute("umun",umun);
427 service_node.setAttribute("umpw",umpw);
428 service_node.setAttribute("umgp",umgp);
429 service_node.setAttribute("umas",umas);
430 service_node.setAttribute("umc",umc);
431 service_node.setAttribute("oumun",oumun);
432 derbyWrapper.closeDatabase();
433 return result;
434 }
435 umgp=umgp.replaceAll(" ","");// get rid of the space
436 derbyWrapper.modifyUserInfo(umun,umpw,umgp,umas,umc);
437 userQueryResult=derbyWrapper.listAllUser();
438 derbyWrapper.closeDatabase();
439 service_node.setAttribute("info","all-un"); // if the new user has been added successfully, return a list of all users
440 Element user_node=getUserNode(userQueryResult);
441 service_node.appendChild(user_node);
442 derbyWrapper.closeDatabase();
443 return result;
444 }
445 }
446 // The user's name has been changed, add a new user record to the database
447 else{
448 if ((umun.length()==0) || (umun.length()<2) || (umun.length()>30) || (!(Pattern.matches("[a-zA-Z0-9//_//.]+",umun)))){
449 service_node.setAttribute("err","umun-err"); //the input username string is illegal
450 service_node.setAttribute("umun",umun);
451 service_node.setAttribute("umpw",umpw);
452 service_node.setAttribute("umgp",umgp);
453 service_node.setAttribute("umas",umas);
454 service_node.setAttribute("umc",umc);
455 service_node.setAttribute("oumun",oumun);
456 service_node.setAttribute("info","edituser-interface");
457 derbyWrapper.closeDatabase();
458 return result;
459 }
460 if (umpw.length()==0){
461 service_node.setAttribute("err","ini-umpw-err"); //the input passwrod string is illegal
462 service_node.setAttribute("info","edituser-interface");
463 service_node.setAttribute("umun",umun);
464 service_node.setAttribute("umpw",umpw);
465 service_node.setAttribute("umgp",umgp);
466 service_node.setAttribute("umas",umas);
467 service_node.setAttribute("umc",umc);
468 service_node.setAttribute("oumun",oumun);
469 derbyWrapper.closeDatabase();
470 return result;
471 }
472 if ((umpw.length()<3) || (umpw.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw)))){
473 service_node.setAttribute("err","umpw-err"); //the input passwrod string is illegal
474 service_node.setAttribute("info","edituser-interface");
475 service_node.setAttribute("umun",umun);
476 service_node.setAttribute("umpw",umpw);
477 service_node.setAttribute("umgp",umgp);
478 service_node.setAttribute("umas",umas);
479 service_node.setAttribute("umc",umc);
480 service_node.setAttribute("oumun",oumun);
481 derbyWrapper.closeDatabase();
482 return result;
483 }
484 umgp=umgp.replaceAll(" ","");// get rid of the space
485 userQueryResult=derbyWrapper.findUser(umun,null);// check whether the new user name has existed in the table.
486 if (userQueryResult!=null){
487 service_node.setAttribute("err","un-exist"); //the new username string is duplicated
488 service_node.setAttribute("info","edituser-interface");
489 service_node.setAttribute("umun","");
490 service_node.setAttribute("umpw","");
491 service_node.setAttribute("umgp",umgp);
492 service_node.setAttribute("umas",umas);
493 service_node.setAttribute("umc",umc);
494 service_node.setAttribute("oumun",oumun);
495 derbyWrapper.closeDatabase();
496 return result;
497 }else{
498 derbyWrapper.addUser(umun,umpw,umgp,umas,umc);
499 userQueryResult=derbyWrapper.listAllUser();
500 derbyWrapper.closeDatabase();
501 service_node.setAttribute("info","all-un"); // if the new user has been added successfully, return a list of all users
502 Element user_node=getUserNode(userQueryResult);
503 service_node.appendChild(user_node);
504 derbyWrapper.closeDatabase();
505 return result;
506 }
507 }
508 }
509
510 if (cm.toLowerCase().equals("cancel")){
511 userQueryResult=derbyWrapper.listAllUser();
512 derbyWrapper.closeDatabase();
513 service_node.setAttribute("info","all-un"); // if the new user has been added successfully, return a list of all users
514 Element user_node=getUserNode(userQueryResult);
515 service_node.appendChild(user_node);
516 derbyWrapper.closeDatabase();
517 return result;
518 }
519 }
520
521 //Action: modifypassword
522 if (aup.equals("ModifyPassword")){
523 if (un.equals("")){
524 service_node.setAttribute("info","Login");
525 derbyWrapper.closeDatabase();
526 return result;
527 }
528
529 service_node.setAttribute(GSXML.NAME_ATT,"Authentication");
530 service_node.setAttribute("un",un);
531 service_node.setAttribute("asn",asn);
532
533 userQueryResult=derbyWrapper.findUser(un,null);
534 Vector userInfo=userQueryResult.users_;
535 pw=((UserTermInfo)userInfo.get(0)).password_;
536
537 if ((umpw1.length()==0) && (umpw2.length()==0) && (umpw.length()==0)){
538 service_node.setAttribute("info","modify_interface");// call the interface of the modifying password
539 derbyWrapper.closeDatabase();
540 return result;
541 }
542
543 if (!pw.equals(umpw) && umpw.length()>0){
544 service_node.setAttribute("info","modify_interface");
545 service_node.setAttribute("err","pw-umpw-nm-err");//if the original password is not match
546 derbyWrapper.closeDatabase();
547 return result;
548 }
549
550 if ((umpw1.length()==0) || (umpw2.length()==0)){
551 service_node.setAttribute("info","modify_interface");
552 service_node.setAttribute("err","umpw1-umpw2-null-err");//if one of the password strings is none,return the err info back
553 derbyWrapper.closeDatabase();
554 return result;
555 }
556
557 if(!umpw1.equals(umpw2)){
558 service_node.setAttribute("info","modify_interface");
559 service_node.setAttribute("err","umpw1-umpw2-nm-err");//if one of the password strings is none,return the err info back
560 derbyWrapper.closeDatabase();
561 return result;
562 }
563
564 if (umpw.length()==0){
565 service_node.setAttribute("info","modify_interface");
566 service_node.setAttribute("err","umpw-null-err");//if one of the password strings is none,return the err info back
567 derbyWrapper.closeDatabase();
568 return result;
569 }
570 //check the new password and the retyped password
571 if ((umpw1==null) || (umpw1.length()<3) || (umpw1.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw1)))){
572 service_node.setAttribute("info","modify_interface");
573 service_node.setAttribute("err","umpw1-err");// the new password is illegal
574 derbyWrapper.closeDatabase();
575 return result;
576 }
577
578 if ((umpw2==null) || (umpw2.length()<3) || (umpw2.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw2)))){
579 service_node.setAttribute("info","modify_interface");
580 service_node.setAttribute("err","umpw2-err"); // the retyped password is illegal
581 derbyWrapper.closeDatabase();
582 return result;
583 }
584 String modify_user_info=derbyWrapper.modifyUserInfo(un,umpw1,null,null,null);
585 if (modify_user_info.equals("succeed")){
586 service_node.setAttribute("err","");// the passsword has been changed successfully
587 derbyWrapper.closeDatabase();
588 return result;
589 }else{
590 service_node.setAttribute("err",modify_user_info);// return the error message of the pasword couldn't be modified
591 derbyWrapper.closeDatabase();
592 return result;
593 }
594 }
595
596 //Action: deleteuser
597 if (aup.equals("DeleteUser")){
598 service_node.setAttribute("un",un);
599 service_node.setAttribute("asn",asn);
600 service_node.setAttribute("umun",umun);
601 if (cm.equals("yes")){
602 String delete_user=derbyWrapper.deleteUser(umun);
603 if (delete_user.equals("succeed")){
604 service_node.setAttribute("err","");
605 userQueryResult=derbyWrapper.listAllUser();
606 service_node.setAttribute("info","all-un"); // return a list of all users
607 Element user_node=getUserNode(userQueryResult);
608 service_node.appendChild(user_node);
609 }else{
610 service_node.setAttribute("err",delete_user);//return the error message
611 derbyWrapper.closeDatabase();
612 return result;
613 }
614 }else if (cm.equals("no")){
615 service_node.setAttribute("err","");
616 userQueryResult=derbyWrapper.listAllUser();
617 service_node.setAttribute("info","all-un"); // return a list of all users
618 Element user_node=getUserNode(userQueryResult);
619 service_node.appendChild(user_node);
620 derbyWrapper.closeDatabase();
621 return result;
622 }else{
623 service_node.setAttribute("info","confirm");
624 derbyWrapper.closeDatabase();
625 return result;
626 }
627 }
628
629 return result;
630 }
631
632 private Element getUserNode(UserQueryResult userQueryResult){
633 Element user_list_node= this.doc.createElement(GSXML.USER_NODE_ELEM+"List");
634
635 Vector userInfo=userQueryResult.users_;
636
637 for (int i=0; i<userQueryResult.getSize(); i++){
638 Element user_node= this.doc.createElement(GSXML.USER_NODE_ELEM);
639 String username=((UserTermInfo)userInfo.get(i)).username_;
640 String password=((UserTermInfo)userInfo.get(i)).password_;
641 String groups=((UserTermInfo)userInfo.get(i)).groups_;
642 String accountstatus=((UserTermInfo)userInfo.get(i)).accountstatus_;
643 String comment=((UserTermInfo)userInfo.get(i)).comment_;
644 user_node.setAttribute("umun",username);
645 user_node.setAttribute("umpw",password);
646 user_node.setAttribute("umgp",groups);
647 user_node.setAttribute("umas",accountstatus);
648 user_node.setAttribute("umc",comment);
649
650 user_list_node.appendChild(user_node);
651 }
652 return user_list_node;
653 }
654
655}
656
Note: See TracBrowser for help on using the repository browser.