Revision 9:16125cca68e4 src/my/com/upass/UPassController.java
src/my/com/upass/UPassController.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
import my.com.upass.db.DBOperations; |
11 | 11 |
import my.com.upass.factory.UPassFactory; |
12 |
import my.com.upass.pojo.MinimalUserBean; |
|
12 | 13 |
import my.com.upass.pojo.TacBean; |
13 | 14 |
import my.com.upass.pojo.UserBean; |
14 | 15 |
import my.com.upass.spassword.PasswordController; |
15 | 16 |
import my.com.upass.vasco.LoadTokenDPX; |
16 | 17 |
import my.com.upass.vasco.TokenController; |
17 | 18 |
|
18 |
import org.apache.log4j.Logger; |
|
19 |
|
|
20 | 19 |
//import com.vasco.utils.DigipassInfo; |
21 | 20 |
|
22 | 21 |
/** |
... | ... | |
24 | 23 |
* UPassController Class Release 20090703 |
25 | 24 |
* |
26 | 25 |
*/ |
27 |
public class UPassController { |
|
26 |
public class UPassController extends MinimalUPassController {
|
|
28 | 27 |
|
29 | 28 |
// private UserBean userBean = null; |
30 | 29 |
// private TacBean tacBean = null; |
31 | 30 |
long userID; |
32 |
String userAlias; |
|
33 |
int SUPERVISOR_ID_SUSPEND = 0; |
|
34 |
int _MAX_ERROR = 0; |
|
35 |
|
|
36 |
Logger logger = Logger.getLogger(UPassController.class.getName()); |
|
37 | 31 |
|
38 | 32 |
/** |
39 | 33 |
* Constructs an empty object |
... | ... | |
98 | 92 |
return rc; |
99 | 93 |
} |
100 | 94 |
|
101 |
int verifyStaticPassword(String userAlias, String password, boolean chkUserType, int userType) { |
|
102 |
|
|
103 |
if (userAlias == null || password == null) { |
|
104 |
return Constants.ERR_INVALID_INPUT; |
|
105 |
} |
|
106 |
|
|
107 |
DBOperations dbo = new DBOperations(); |
|
108 |
UserBean userBean = new UserBean(); |
|
109 |
userBean = dbo.getUserFromStore(userAlias); |
|
110 |
if (userBean == null) { |
|
111 |
dbo.close(); |
|
112 |
return Constants.ERR_USERALIAS_NOT_FOUND; |
|
113 |
} |
|
114 |
|
|
115 |
// verify user state, must be active (not inactive|locked|deleted) |
|
116 |
switch (userBean.getUstate()) { |
|
117 |
case (Constants.UID_STATE_ACTIVE): |
|
118 |
break; |
|
119 |
case (Constants.UID_STATE_TMP_LOCKED): |
|
120 |
Date now = new Date(); |
|
121 |
if (userBean.getUdateLockedTo().after(now)) { |
|
122 |
dbo.close(); |
|
123 |
return Constants.ERR_INVALID_STATE; |
|
124 |
} |
|
125 |
break; |
|
126 |
default: |
|
127 |
dbo.close(); |
|
128 |
return Constants.ERR_INVALID_STATE; |
|
129 |
} |
|
130 |
|
|
131 |
// verify user type |
|
132 |
if (chkUserType && userBean.getUserType() != userType) { |
|
133 |
dbo.close(); |
|
134 |
return Constants.ERR_APP_SERV_NOT_PERMITTED; |
|
135 |
} |
|
136 |
|
|
137 |
// verify user password |
|
138 |
PasswordController pc = new PasswordController(userBean); |
|
139 |
int rc = pc.VerifyPassword(password); |
|
140 |
userBean = pc.getUpdatedObject(); |
|
141 |
|
|
142 |
// suspend if exceeded max retries |
|
143 |
if (rc == Constants.ERR_EXCEED_MAX_TRIES && |
|
144 |
(userBean.getUserType() != Constants.UTYPE_STATE_USER)) { |
|
145 |
|
|
146 |
Calendar expiryDate = Calendar.getInstance(); |
|
147 |
expiryDate.add(Calendar.MINUTE, +SUPERVISOR_ID_SUSPEND); |
|
148 |
|
|
149 |
userBean.setUstate(Constants.UID_STATE_TMP_LOCKED); |
|
150 |
userBean.setPerrorCount(_MAX_ERROR - 1); |
|
151 |
userBean.setUdateLockedFrom((new Date())); |
|
152 |
userBean.setUdateLockedTo(expiryDate.getTime()); |
|
153 |
userBean.setUdateLastLocked((new Date())); |
|
154 |
} |
|
155 |
|
|
156 |
// Debug info: |
|
157 |
logger.debug("RC........." + rc + "\n" + |
|
158 |
".use......." + userBean.getPuseCount() + "\n" + |
|
159 |
".err......." + userBean.getPerrorCount() + "\n" + |
|
160 |
".hist......" + userBean.getPhistoryList() + "\n" + |
|
161 |
".last......" + |
|
162 |
new String(Constants.defaultDateFormat.format(userBean.getPdateLastUsed()))); |
|
163 |
// debug info: |
|
164 |
|
|
165 |
// update database |
|
166 |
boolean lrc = dbo.updateUserToStore(userBean); |
|
167 |
dbo.close(); |
|
168 |
if (!lrc) { |
|
169 |
rc = Constants.ERR_SYSTEM_NOT_READY; |
|
170 |
} |
|
171 |
return rc; |
|
172 |
} |
|
173 |
|
|
174 | 95 |
/** |
175 | 96 |
* This method generate static password and to be using SP_VerifyStaticPassword(). |
176 | 97 |
* |
... | ... | |
195 | 116 |
|
196 | 117 |
private int changeStaticPassword(String userAlias, String newPassword, String oldPassword) { |
197 | 118 |
DBOperations dbo = new DBOperations(); |
198 |
UserBean userBean = new UserBean(); |
|
119 |
MinimalUserBean userBean = new UserBean();
|
|
199 | 120 |
userBean = dbo.getUserFromStore(userAlias); |
200 | 121 |
if (userBean == null) { |
201 | 122 |
dbo.close(); |
... | ... | |
315 | 236 |
} |
316 | 237 |
|
317 | 238 |
/** |
318 |
* This method to add admin users to the system |
|
319 |
* |
|
320 |
* @param rootAlias |
|
321 |
* @param rootPassword |
|
322 |
* @param adminUserAlias |
|
323 |
* @param adminDesc |
|
324 |
* @param adminUserPassword |
|
325 |
* @return ERR_code defined in the Constants<br/> |
|
326 |
* ERR_SUCCESS<br/> |
|
327 |
* ERR_SYSTEM_NOT_READY<br/> |
|
328 |
* ERR_USERALIAS_NOT_FOUND <br/> |
|
329 |
* ERR_INVALID_STATE - root not active or temporary suspended.<br/> |
|
330 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/> |
|
331 |
* ERR_EXCEED_MAX_TRIES<br/> |
|
332 |
* ERR_INVALID_CREDENTIAL<br/> |
|
333 |
* ERR_INVALID_INPUT - internal error.<br/> |
|
334 |
* ERR_ALREADY_EXIST<br/> |
|
335 |
*/ |
|
336 |
public int AD_AddUser(String rootAlias, String rootPassword, |
|
337 |
String adminUserAlias, String adminDesc, String adminUserPassword) { |
|
338 |
int rc = ad_AddUser(rootAlias, rootPassword, adminUserAlias, adminDesc, adminUserPassword); |
|
339 |
logger.info(userAlias + " Return=" + rc); |
|
340 |
return rc; |
|
341 |
} |
|
342 |
|
|
343 |
private int ad_AddUser(String rootAlias, String rootPassword, |
|
344 |
String adminUserAlias, String adminDesc, String adminUserPassword) { |
|
345 |
|
|
346 |
// verify supervisor password |
|
347 |
int rc = verifyStaticPassword(rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT); |
|
348 |
if (rc != Constants.ERR_SUCCESS) { |
|
349 |
return rc; |
|
350 |
} |
|
351 |
|
|
352 |
rc = addUser(adminUserAlias, Constants.UTYPE_STATE_ADMIN, adminDesc, adminUserPassword, |
|
353 |
Constants.UID_STATE_ACTIVE); |
|
354 |
return rc; |
|
355 |
} |
|
356 |
|
|
357 |
/** |
|
358 | 239 |
* This method to modify admin users to the system |
359 | 240 |
* |
360 | 241 |
* @param rootAlias |
... | ... | |
396 | 277 |
Constants.UID_STATE_ACTIVE); |
397 | 278 |
} |
398 | 279 |
|
399 |
private int addUser(String userAlias, int userType, String userDesc, String userPassword, int userState) { |
|
400 |
int rc; |
|
401 |
|
|
402 |
if (userAlias == null || userPassword == null) |
|
403 |
return Constants.ERR_INVALID_INPUT; |
|
404 |
|
|
405 |
// insert into DB |
|
406 |
DBOperations dbo = new DBOperations(); |
|
407 |
UserBean ub = new UserBean(); |
|
408 |
ub.setUserAlias(userAlias); |
|
409 |
ub.setDescription(userDesc); |
|
410 |
ub.setUserType(userType); |
|
411 |
ub.setUstate(userState); |
|
412 |
|
|
413 |
PasswordController pc = new PasswordController(ub); |
|
414 |
rc = pc.VerifyUserAlias(userAlias); |
|
415 |
// if useralias is valid then continue else return error |
|
416 |
if (rc == Constants.ERR_SUCCESS) { |
|
417 |
rc = pc.GeneratePassword(userPassword, false); |
|
418 |
ub = pc.getUpdatedObject(); |
|
419 |
|
|
420 |
// Debug info: |
|
421 |
// logger.info( "RC........." + rc); |
|
422 |
// logger.info( ".hist......" + ub.getPhistoryList() + "/" + ub.getUserID()); |
|
423 |
|
|
424 |
// debug info: |
|
425 |
if (dbo.insertUserToStore(ub)) { |
|
426 |
rc = Constants.ERR_SUCCESS; |
|
427 |
} |
|
428 |
else { |
|
429 |
rc = Constants.ERR_ALREADY_EXIST; |
|
430 |
} |
|
431 |
dbo.close(); |
|
432 |
} |
|
433 |
|
|
434 |
return rc; |
|
435 |
|
|
436 |
} |
|
437 |
|
|
438 | 280 |
// TODO: chg to public for testing purpose only |
439 | 281 |
private int modifyUser(String userAlias, int userType, String userDesc, String userPassword, int userState) { |
440 | 282 |
int rc; |
... | ... | |
444 | 286 |
|
445 | 287 |
// insert into DB |
446 | 288 |
DBOperations dbo = new DBOperations(); |
447 |
UserBean ub = new UserBean(); |
|
289 |
MinimalUserBean ub = new UserBean();
|
|
448 | 290 |
ub = dbo.getUserFromStore(userAlias); |
449 | 291 |
if (ub == null) { |
450 | 292 |
dbo.close(); |
... | ... | |
556 | 398 |
return Constants.ERR_INVALID_INPUT; |
557 | 399 |
|
558 | 400 |
DBOperations dbo = new DBOperations(); |
559 |
UserBean ub = new UserBean(); |
|
401 |
MinimalUserBean ub = new UserBean();
|
|
560 | 402 |
ub = dbo.getUserFromStore(userAlias); |
561 | 403 |
if (ub == null) { |
562 | 404 |
dbo.close(); |
... | ... | |
587 | 429 |
*/ |
588 | 430 |
public int UA_IsUserExist(String userAlias) { |
589 | 431 |
DBOperations dbo = new DBOperations(); |
590 |
UserBean ub = new UserBean(); |
|
432 |
MinimalUserBean ub = new UserBean();
|
|
591 | 433 |
ub = dbo.getUserFromStore(userAlias); |
592 | 434 |
dbo.close(); |
593 | 435 |
if (ub == null) { |
... | ... | |
611 | 453 |
|
612 | 454 |
public int UA_GetUserType(String userAlias) { |
613 | 455 |
DBOperations dbo = new DBOperations(); |
614 |
UserBean ub = new UserBean(); |
|
456 |
MinimalUserBean ub = new UserBean();
|
|
615 | 457 |
ub = dbo.getUserFromStore(userAlias); |
616 | 458 |
dbo.close(); |
617 | 459 |
if (ub == null) { |
... | ... | |
629 | 471 |
*/ |
630 | 472 |
public long UA_GetUserIDByAlias(String userAlias) { |
631 | 473 |
DBOperations dbo = new DBOperations(); |
632 |
UserBean ub = new UserBean(); |
|
474 |
MinimalUserBean ub = new UserBean();
|
|
633 | 475 |
ub = dbo.getUserFromStore(userAlias); |
634 | 476 |
dbo.close(); |
635 | 477 |
return (ub == null) ? 0 : ub.getUserID(); |
... | ... | |
660 | 502 |
HashMap<String, String> map = new HashMap<String, String>(); |
661 | 503 |
|
662 | 504 |
DBOperations dbo = new DBOperations(); |
663 |
UserBean ub = new UserBean(); |
|
505 |
MinimalUserBean ub = new UserBean();
|
|
664 | 506 |
ub = dbo.getUserFromStore(userAlias); |
665 | 507 |
dbo.close(); |
666 | 508 |
if (ub == null) { |
... | ... | |
710 | 552 |
HashMap<String, String> map = new HashMap<String, String>(); |
711 | 553 |
|
712 | 554 |
DBOperations dbo = new DBOperations(); |
713 |
UserBean ub = new UserBean(); |
|
555 |
MinimalUserBean ub = new UserBean();
|
|
714 | 556 |
ub = dbo.getUserFromStore(userAlias); |
715 | 557 |
dbo.close(); |
716 | 558 |
if (ub == null) { |
... | ... | |
930 | 772 |
return Constants.ERR_INVALID_INPUT; |
931 | 773 |
|
932 | 774 |
DBOperations dbo = new DBOperations(); |
933 |
UserBean ub = new UserBean(); |
|
775 |
MinimalUserBean ub = new UserBean();
|
|
934 | 776 |
ub = dbo.getUserFromStore(userAlias); |
935 | 777 |
if (ub == null) { |
936 | 778 |
dbo.close(); |
... | ... | |
1331 | 1173 |
} |
1332 | 1174 |
|
1333 | 1175 |
// check user exist for the token |
1334 |
UserBean ub = new UserBean(); |
|
1176 |
MinimalUserBean ub = new UserBean();
|
|
1335 | 1177 |
ub = dbo.getUserFromStore(targetUserAlias); |
1336 | 1178 |
if (ub == null) { |
1337 | 1179 |
dbo.close(); |
Also available in: Unified diff