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