m2u-upass-core / src / my / com / upass / UPassController.java @ 2:dcd717e1bcae
History | View | Annotate | Download (47.5 KB)
1 |
package my.com.upass; |
---|---|
2 |
|
3 |
import java.text.ParseException; |
4 |
import java.text.SimpleDateFormat; |
5 |
import java.util.Calendar; |
6 |
import java.util.Date; |
7 |
import java.util.HashMap; |
8 |
import java.util.Properties; |
9 |
|
10 |
import my.com.upass.db.DBOperations; |
11 |
import my.com.upass.factory.UPassFactory; |
12 |
import my.com.upass.pojo.TacBean; |
13 |
import my.com.upass.pojo.UserBean; |
14 |
import my.com.upass.spassword.PasswordController; |
15 |
import my.com.upass.vasco.LoadTokenDPX; |
16 |
import my.com.upass.vasco.TokenController; |
17 |
|
18 |
import org.apache.log4j.Logger; |
19 |
|
20 |
//import com.vasco.utils.DigipassInfo;
|
21 |
|
22 |
/**
|
23 |
* @author LeeTK dking
|
24 |
* UPassController Class Release 20090703
|
25 |
*
|
26 |
*/
|
27 |
public class UPassController { |
28 |
|
29 |
// private UserBean userBean = null;
|
30 |
// private TacBean tacBean = null;
|
31 |
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 |
|
38 |
/**
|
39 |
* Constructs an empty object
|
40 |
*/
|
41 |
public UPassController() {
|
42 |
getSystemProperties(); |
43 |
logger.info("Constructor::UPassController()");
|
44 |
} |
45 |
|
46 |
/**
|
47 |
* Constructs an object contains the initial userAlias value
|
48 |
*
|
49 |
* @param userAlias
|
50 |
*/
|
51 |
public UPassController(String userAlias) { |
52 |
getSystemProperties(); |
53 |
logger.info("Constructor::UPassController(" + userAlias + ")"); |
54 |
setUserAlias(userAlias); |
55 |
} |
56 |
|
57 |
/**
|
58 |
* Sets the userAlias with this binding.
|
59 |
*
|
60 |
* @param userAlias
|
61 |
*/
|
62 |
public void setUserAlias(String userAlias) { |
63 |
this.userAlias = userAlias;
|
64 |
} |
65 |
|
66 |
private void getSystemProperties() { |
67 |
Config cfg = Config.getInstance(); |
68 |
Properties cfgData = cfg.getConfig();
|
69 |
try {
|
70 |
SUPERVISOR_ID_SUSPEND = Integer.parseInt(cfgData.get("SUPERVISOR_ID_SUSPEND").toString()); |
71 |
_MAX_ERROR = Integer.parseInt(cfgData.get("PASSWORD_MAX_ERROR").toString()); |
72 |
} catch (Exception e) { |
73 |
logger.error("ERR: Property entry not found..");
|
74 |
} |
75 |
} |
76 |
|
77 |
// /////////////////////////////////////////////////////////////////////////////////////////
|
78 |
// Static Password Methods
|
79 |
// /////////////////////////////////////////////////////////////////////////////////////////
|
80 |
/**
|
81 |
* This method verify static password generated using SP_ChangeStaticPassword().
|
82 |
*
|
83 |
* @param userAlias
|
84 |
* @param password
|
85 |
* @return ERR_code defined in the Constants.<br/>
|
86 |
* ERR_SUCCESS<br/>
|
87 |
* ERR_SYSTEM_NOT_READY<br/>
|
88 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
89 |
* ERR_INVALID_STATE - user not active or temporary suspended.<br/>
|
90 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
91 |
* ERR_EXCEED_MAX_TRIES - used ModifyUser to reset password.<br/>
|
92 |
* ERR_INVALID_CREDENTIAL<br/>
|
93 |
* ERR_PASSWD_EXPIRED - password is valid but expired, suggest to change new password.<br/>
|
94 |
*/
|
95 |
public int SP_VerifyStaticPassword(String userAlias, String password) { |
96 |
int rc = verifyStaticPassword(userAlias, password, false, 0); |
97 |
logger.info(userAlias + " Return=" + rc);
|
98 |
return rc;
|
99 |
} |
100 |
|
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 |
/**
|
175 |
* This method generate static password and to be using SP_VerifyStaticPassword().
|
176 |
*
|
177 |
* @param userAlias
|
178 |
* @param newPassword
|
179 |
* @param oldPassword
|
180 |
* @return ERR_code defined in the Constants<br/>
|
181 |
* ERR_SUCCESS<br/>
|
182 |
* ERR_SYSTEM_NOT_READY<br/>
|
183 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
184 |
* ERR_INVALID_STATE - user not active or temporary suspended.<br/>
|
185 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
186 |
* ERR_EXCEED_MAX_TRIES - used ModifyUser to reset password.<br/>
|
187 |
* ERR_INVALID_CREDENTIAL<br/>
|
188 |
* ERR_REUSED_PASSWD - reuse previous generated password.<br/>
|
189 |
*/
|
190 |
public int SP_ChangeStaticPassword(String userAlias, String newPassword, String oldPassword) { |
191 |
int rc = changeStaticPassword(userAlias, newPassword, oldPassword);
|
192 |
logger.info(userAlias + " Return=" + rc);
|
193 |
return rc;
|
194 |
} |
195 |
|
196 |
private int changeStaticPassword(String userAlias, String newPassword, String oldPassword) { |
197 |
DBOperations dbo = new DBOperations();
|
198 |
UserBean userBean = new UserBean();
|
199 |
userBean = dbo.getUserFromStore(userAlias); |
200 |
if (userBean == null) { |
201 |
dbo.close(); |
202 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
203 |
} |
204 |
|
205 |
// verify user
|
206 |
PasswordController pc = new PasswordController(userBean);
|
207 |
int rc = pc.VerifyPassword(oldPassword);
|
208 |
|
209 |
if (rc == Constants.ERR_SUCCESS ||
|
210 |
rc == Constants.ERR_PASSWD_EXPIRED) { |
211 |
rc = pc.GeneratePassword(newPassword, true);
|
212 |
} |
213 |
|
214 |
userBean = pc.getUpdatedObject(); |
215 |
|
216 |
// Debug info:
|
217 |
logger.debug("RC........." + rc +
|
218 |
"\n.use......." + userBean.getPuseCount() +
|
219 |
"\n.err......." + userBean.getPerrorCount() +
|
220 |
"\n.hist......" + userBean.getPhistoryList() +
|
221 |
"\n.last......" +
|
222 |
new String(Constants.defaultDateFormat.format(userBean.getPdateLastUsed()))); |
223 |
// debug info:
|
224 |
|
225 |
// update database
|
226 |
boolean lrc = dbo.updateUserToStore(userBean);
|
227 |
dbo.close(); |
228 |
if (!lrc) {
|
229 |
rc = Constants.ERR_SYSTEM_NOT_READY; |
230 |
} |
231 |
|
232 |
return rc;
|
233 |
} |
234 |
|
235 |
// /////////////////////////////////////////////////////////////////////////////////////////
|
236 |
// User Administration methods.
|
237 |
// /////////////////////////////////////////////////////////////////////////////////////////
|
238 |
|
239 |
/**
|
240 |
* This method to add online users to the system
|
241 |
*
|
242 |
* @param adminUserAlias
|
243 |
* @param adminUserPassword
|
244 |
* @param userAlias
|
245 |
* @param userDesc
|
246 |
* @param userPassword
|
247 |
* @return ERR_code defined in the Constants<br/>
|
248 |
* ERR_SUCCESS<br/>
|
249 |
* ERR_SYSTEM_NOT_READY<br/>
|
250 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
251 |
* ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
|
252 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
253 |
* ERR_EXCEED_MAX_TRIES<br/>
|
254 |
* ERR_INVALID_CREDENTIAL<br/>
|
255 |
* ERR_INVALID_INPUT - internal error.<br/>
|
256 |
* ERR_ALREADY_EXIST<br/>
|
257 |
*/
|
258 |
|
259 |
public int UA_AddUser(String adminUserAlias, String adminUserPassword, |
260 |
String userAlias, String userDesc, String userPassword) { |
261 |
int rc = ua_AddUser(adminUserAlias, adminUserPassword, userAlias, userDesc, userPassword);
|
262 |
logger.info(adminUserAlias + " " + userAlias + " Return=" + rc); |
263 |
return rc;
|
264 |
} |
265 |
|
266 |
private int ua_AddUser(String adminUserAlias, String adminUserPassword, |
267 |
String userAlias, String userDesc, String userPassword) { |
268 |
|
269 |
// verify supervisor password
|
270 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
271 |
if (rc != Constants.ERR_SUCCESS) {
|
272 |
return rc;
|
273 |
} |
274 |
return addUser(userAlias, Constants.UTYPE_STATE_USER, userDesc, userPassword, Constants.UID_STATE_ACTIVE);
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* This method to Modify online users to the system
|
279 |
*
|
280 |
* @param adminUserAlias
|
281 |
* @param adminUserPassword
|
282 |
* @param userAlias
|
283 |
* @param userDesc
|
284 |
* - can be null - Null denotes no description will be modified.
|
285 |
* @param userPassword
|
286 |
* - can be null - Null denotes no password will be modified.
|
287 |
* @return ERR_code defined in the Constants<br/>
|
288 |
* ERR_SUCCESS<br/>
|
289 |
* ERR_SYSTEM_NOT_READY<br/>
|
290 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
291 |
* ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
|
292 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
293 |
* ERR_EXCEED_MAX_TRIES<br/>
|
294 |
* ERR_INVALID_CREDENTIAL<br/>
|
295 |
* ERR_INVALID_INPUT - internal error.<br/>
|
296 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
297 |
* ERR_REUSED_PASSWD - the password entered was used previously.<br/>
|
298 |
*/
|
299 |
public int UA_ModifyUser(String adminUserAlias, String adminUserPassword, |
300 |
String userAlias, String userDesc, String userPassword) { |
301 |
int rc = ua_ModifyUser(adminUserAlias, adminUserPassword, userAlias, userDesc, userPassword);
|
302 |
logger.info(adminUserAlias + " " + userAlias + " Return=" + rc); |
303 |
return rc;
|
304 |
} |
305 |
|
306 |
private int ua_ModifyUser(String adminUserAlias, String adminUserPassword, |
307 |
String userAlias, String userDesc, String userPassword) { |
308 |
|
309 |
// verify supervisor password
|
310 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
311 |
if (rc != Constants.ERR_SUCCESS) {
|
312 |
return rc;
|
313 |
} |
314 |
return modifyUser(userAlias, Constants.UTYPE_STATE_USER, userDesc, userPassword, Constants.UID_STATE_ACTIVE);
|
315 |
} |
316 |
|
317 |
/**
|
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 |
* This method to modify admin users to the system
|
359 |
*
|
360 |
* @param rootAlias
|
361 |
* @param rootPassword
|
362 |
* @param adminUserAlias
|
363 |
* @param adminDesc
|
364 |
* - can be null - Null denotes no description will be modified.
|
365 |
* @param adminUserPassword
|
366 |
* - can be null - Null denotes no password will be modified.
|
367 |
* @return ERR_code defined in the Constants.<br/>
|
368 |
* ERR_SUCCESS<br/>
|
369 |
* ERR_SYSTEM_NOT_READY<br/>
|
370 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
371 |
* ERR_INVALID_STATE - root not active or temporary suspended.<br/>
|
372 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
373 |
* ERR_EXCEED_MAX_TRIES<br/>
|
374 |
* ERR_INVALID_CREDENTIAL<br/>
|
375 |
* ERR_INVALID_INPUT - internal error.<br/>
|
376 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
377 |
* ERR_REUSED_PASSWD - the password entered was used previously.<br/>
|
378 |
* ERR_PASSWD_WEAK - the password entered is too weak.<br/>
|
379 |
*/
|
380 |
public int AD_ModifyUser(String rootAlias, String rootPassword, |
381 |
String adminUserAlias, String adminDesc, String adminUserPassword) { |
382 |
int rc = ad_ModifyUser(rootAlias, rootPassword, adminUserAlias, adminDesc, adminUserPassword);
|
383 |
logger.info(rootAlias + " " + adminUserAlias + " Return=" + rc); |
384 |
return rc;
|
385 |
} |
386 |
|
387 |
private int ad_ModifyUser(String rootAlias, String rootPassword, |
388 |
String adminUserAlias, String adminDesc, String adminUserPassword) { |
389 |
|
390 |
// verify supervisor password
|
391 |
int rc = verifyStaticPassword(rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT); |
392 |
if (rc != Constants.ERR_SUCCESS) {
|
393 |
return rc;
|
394 |
} |
395 |
return modifyUser(adminUserAlias, Constants.UTYPE_STATE_ADMIN, adminDesc, adminUserPassword,
|
396 |
Constants.UID_STATE_ACTIVE); |
397 |
} |
398 |
|
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 |
// TODO: chg to public for testing purpose only
|
439 |
private int modifyUser(String userAlias, int userType, String userDesc, String userPassword, int userState) { |
440 |
int rc;
|
441 |
|
442 |
if (userAlias == null) |
443 |
return Constants.ERR_INVALID_INPUT;
|
444 |
|
445 |
// insert into DB
|
446 |
DBOperations dbo = new DBOperations();
|
447 |
UserBean ub = new UserBean();
|
448 |
ub = dbo.getUserFromStore(userAlias); |
449 |
if (ub == null) { |
450 |
dbo.close(); |
451 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
452 |
} |
453 |
|
454 |
if (userPassword != null) { |
455 |
// Generate new paswword
|
456 |
PasswordController pc = new PasswordController(ub);
|
457 |
// rc = pc.GeneratePassword(userPassword, false); //disable password hist check 20081220
|
458 |
rc = pc.GeneratePassword(userPassword, true);
|
459 |
if (rc != Constants.ERR_SUCCESS) {
|
460 |
dbo.close(); |
461 |
return rc;
|
462 |
} |
463 |
ub = pc.getUpdatedObject(); |
464 |
} |
465 |
|
466 |
if (userDesc != null) { |
467 |
ub.setDescription(userDesc); |
468 |
} |
469 |
|
470 |
ub.setUserType(userType); |
471 |
ub.setUstate(userState); |
472 |
|
473 |
if (dbo.updateUserToStore(ub)) {
|
474 |
rc = Constants.ERR_SUCCESS; |
475 |
} |
476 |
else {
|
477 |
rc = Constants.ERR_UNKNOWN; |
478 |
} |
479 |
|
480 |
dbo.close(); |
481 |
return rc;
|
482 |
|
483 |
} |
484 |
|
485 |
/**
|
486 |
* This method to change online users state to ACTIVE status.
|
487 |
*
|
488 |
* @param adminUserAlias
|
489 |
* @param adminUserPassword
|
490 |
* @param userAlias
|
491 |
* @return ERR_code defined in the Constants.<br/>
|
492 |
* ERR_SUCCESS<br/>
|
493 |
* ERR_SYSTEM_NOT_READY<br/>
|
494 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
495 |
* ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
|
496 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
497 |
* ERR_EXCEED_MAX_TRIES<br/>
|
498 |
* ERR_INVALID_CREDENTIAL<br/>
|
499 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
500 |
* ERR_UNKNOWN <br/>
|
501 |
*/
|
502 |
public int UA_ActivateUser(String adminUserAlias, String adminUserPassword, String userAlias) { |
503 |
int rc = ua_ActivateUser(adminUserAlias, adminUserPassword, userAlias);
|
504 |
logger.info(adminUserAlias + " " + userAlias + " Return=" + rc); |
505 |
return rc;
|
506 |
} |
507 |
|
508 |
private int ua_ActivateUser(String adminUserAlias, String adminUserPassword, String userAlias) { |
509 |
|
510 |
// verify supervisor password
|
511 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
512 |
if (rc != Constants.ERR_SUCCESS) {
|
513 |
return rc;
|
514 |
} |
515 |
return activateUser(userAlias);
|
516 |
} |
517 |
|
518 |
/**
|
519 |
* This method to change admin users state to ACTIVE status.
|
520 |
*
|
521 |
* @param rootAlias
|
522 |
* @param rootPassword
|
523 |
* @param adminUserAlias
|
524 |
* @return ERR_code defined in the Constants.<br/>
|
525 |
* ERR_SUCCESS<br/>
|
526 |
* ERR_SYSTEM_NOT_READY<br/>
|
527 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
528 |
* ERR_INVALID_STATE - root not active or temporary suspended.<br/>
|
529 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
530 |
* ERR_EXCEED_MAX_TRIES<br/>
|
531 |
* ERR_INVALID_CREDENTIAL<br/>
|
532 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
533 |
* ERR_UNKNOWN<br/>
|
534 |
*/
|
535 |
public int AD_ActivateUser(String rootAlias, String rootPassword, String adminUserAlias) { |
536 |
int rc = ad_ActivateUser(rootAlias, rootPassword, adminUserAlias);
|
537 |
logger.info(rootAlias + " " + adminUserAlias + " Return=" + rc); |
538 |
return rc;
|
539 |
} |
540 |
|
541 |
private int ad_ActivateUser(String rootAlias, String rootPassword, String adminUserAlias) { |
542 |
|
543 |
// verify supervisor password
|
544 |
int rc = verifyStaticPassword(rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT); |
545 |
if (rc != Constants.ERR_SUCCESS) {
|
546 |
return rc;
|
547 |
} |
548 |
return activateUser(adminUserAlias);
|
549 |
} |
550 |
|
551 |
// TODO: chg to public for testing purpose only
|
552 |
private int activateUser(String userAlias) { |
553 |
int rc;
|
554 |
|
555 |
if (userAlias == null) |
556 |
return Constants.ERR_INVALID_INPUT;
|
557 |
|
558 |
DBOperations dbo = new DBOperations();
|
559 |
UserBean ub = new UserBean();
|
560 |
ub = dbo.getUserFromStore(userAlias); |
561 |
if (ub == null) { |
562 |
dbo.close(); |
563 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
564 |
} |
565 |
|
566 |
ub.setUstate(Constants.UID_STATE_ACTIVE); |
567 |
ub.setUdateLastActivated(new Date()); |
568 |
|
569 |
if (dbo.updateUserToStore(ub)) {
|
570 |
rc = Constants.ERR_SUCCESS; |
571 |
} |
572 |
else {
|
573 |
rc = Constants.ERR_UNKNOWN; |
574 |
} |
575 |
dbo.close(); |
576 |
return rc;
|
577 |
} |
578 |
|
579 |
/**
|
580 |
* This method is to check whether the user alias exist in the system.
|
581 |
*
|
582 |
* @param userAlias
|
583 |
* @return ERR_code defined in the Constants.<br/>
|
584 |
* ERR_SUCCESS 0 - found<br/>
|
585 |
* ERR_USERALIAS_NOT_FOUND 6<br/>
|
586 |
* ERR_SYSTEM_NOT_READY 98<br/>
|
587 |
*/
|
588 |
public int UA_IsUserExist(String userAlias) { |
589 |
DBOperations dbo = new DBOperations();
|
590 |
UserBean ub = new UserBean();
|
591 |
ub = dbo.getUserFromStore(userAlias); |
592 |
dbo.close(); |
593 |
if (ub == null) { |
594 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
595 |
} |
596 |
|
597 |
return Constants.ERR_SUCCESS;
|
598 |
} |
599 |
|
600 |
/**
|
601 |
* This method is to get user type. Valid return is [0-root user | 1-admin user | 2-Ordinary User]
|
602 |
*
|
603 |
* @param userAlias
|
604 |
* @return <br/>
|
605 |
* UTYPE_STATE_ROOT = 0<br/>
|
606 |
* UTYPE_STATE_ADMIN = 1<br/>
|
607 |
* UTYPE_STATE_USER = 2<br/>
|
608 |
* ERR_USERALIAS_NOT_FOUND = 6<br/>
|
609 |
* ERR_SYSTEM_NOT_READY = 98<br/>
|
610 |
*/
|
611 |
|
612 |
public int UA_GetUserType(String userAlias) { |
613 |
DBOperations dbo = new DBOperations();
|
614 |
UserBean ub = new UserBean();
|
615 |
ub = dbo.getUserFromStore(userAlias); |
616 |
dbo.close(); |
617 |
if (ub == null) { |
618 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
619 |
} |
620 |
|
621 |
return ub.getUserType();
|
622 |
} |
623 |
|
624 |
/**
|
625 |
* This method is to get user ID associated to user alias
|
626 |
*
|
627 |
* @param userAlias
|
628 |
* @return userID or Zero if failed.
|
629 |
*/
|
630 |
public long UA_GetUserIDByAlias(String userAlias) { |
631 |
DBOperations dbo = new DBOperations();
|
632 |
UserBean ub = new UserBean();
|
633 |
ub = dbo.getUserFromStore(userAlias); |
634 |
dbo.close(); |
635 |
return (ub == null) ? 0 : ub.getUserID(); |
636 |
} |
637 |
|
638 |
/**
|
639 |
* This method is to get attributes associated to user. Return type is HashMap<String,String>
|
640 |
* The object keys is as below:<br/>
|
641 |
* RC - Return Code [always present]<br/>
|
642 |
* RT - Return Code in Text [always present]<br/>
|
643 |
* <br/>
|
644 |
* The following data present only with the return is ERR_SUCCESS<br/>
|
645 |
* Type - User Type [0-Root User] [1-Admin User] [2-Ordinary User][9-SysControl]<br/>
|
646 |
* State - User State [0-Active] [1-Temporary Locked] [2-Locked] [3-Inactive] [4-Deleted]<br/>
|
647 |
* Description - User Description<br/>
|
648 |
* UseCount - Number of time the record being access<br/>
|
649 |
* DateCreated - Created date<br/>
|
650 |
* DateLastUsed - Last access of the record<br/>
|
651 |
* DateLastActivated - Last activation of the record<br/>
|
652 |
* DateLastLocked - Last date the user being locked<br/>
|
653 |
* DateLockedFrom - last date the user being locked from<br/>
|
654 |
* DateLockedTo - last date the user being locked to<br/>
|
655 |
*
|
656 |
* @param userAlias
|
657 |
* @return HashMap
|
658 |
*/
|
659 |
public HashMap<String, String> UA_GetUserData(String userAlias) { |
660 |
HashMap<String, String> map = new HashMap<String, String>(); |
661 |
|
662 |
DBOperations dbo = new DBOperations();
|
663 |
UserBean ub = new UserBean();
|
664 |
ub = dbo.getUserFromStore(userAlias); |
665 |
dbo.close(); |
666 |
if (ub == null) { |
667 |
map.put("RC", new Integer(Constants.ERR_USERALIAS_NOT_FOUND).toString()); |
668 |
map.put("RT", "ERR_USERALIAS_NOT_FOUND"); |
669 |
return map;
|
670 |
} |
671 |
|
672 |
// return Constants.ERR_SUCCESS;
|
673 |
map.put("RC", new Integer(Constants.ERR_SUCCESS).toString()); |
674 |
map.put("RT", "ERR_SUCCESS"); |
675 |
map.put("Type", new Integer(ub.getUserType()).toString()); |
676 |
map.put("State", new Integer(ub.getUstate()).toString()); |
677 |
map.put("Description", ub.getDescription());
|
678 |
map.put("UseCount", new Integer(ub.getUuseCount()).toString()); |
679 |
map.put("DateCreated", (ub.getUdateCreated() == null) ? "NULL" : ub.getUdateCreated().toString()); |
680 |
map.put("DateLastUsed", (ub.getUdateLastUsed() == null) ? "NULL" : ub.getUdateLastUsed().toString()); |
681 |
map.put("DateLastActivated", (ub.getUdateLastActivated() == null) ? "NULL" : ub.getUdateLastActivated() |
682 |
.toString()); |
683 |
map.put("DateLastLocked", (ub.getUdateLastLocked() == null) ? "NULL" : ub.getUdateLastLocked().toString()); |
684 |
map.put("DateLockedFrom", (ub.getUdateLockedFrom() == null) ? "NULL" : ub.getUdateLockedFrom().toString()); |
685 |
map.put("DateLockedTo", (ub.getUdateLockedTo() == null) ? "NULL" : ub.getUdateLockedTo().toString()); |
686 |
return map;
|
687 |
|
688 |
} |
689 |
|
690 |
/**
|
691 |
* This method is to get attributes associated to password. Return type is HashMap<String,String>
|
692 |
* The object keys is as below:<br/>
|
693 |
* RC - Return Code [always present]<br/>
|
694 |
* RT - Return Code in Text [always present]<br/>
|
695 |
* <br/>
|
696 |
* The following data present only with the return is ERR_SUCCESS<br/>
|
697 |
* State - Password State [0-Enable] [1-Disable] [2-OneTime Use]<br/>
|
698 |
* ExpiryStatus - Expiry Status [0-Will Expired][1-Never Expired]
|
699 |
* UseCount - Number of time the record being access<br/>
|
700 |
* ErrorCount - Number of time the password verified error<br/>
|
701 |
* DateCreated - Created date<br/>
|
702 |
* DateFirstUsed - First access of the password<br/>
|
703 |
* DateLastUsed - Last access of the password<br/>
|
704 |
* DatePasswdExpired - Expiry date of the password<br/>
|
705 |
*
|
706 |
* @param userAlias
|
707 |
* @return HashMap
|
708 |
*/
|
709 |
public HashMap<String, String> QueryPassword(String userAlias) { |
710 |
HashMap<String, String> map = new HashMap<String, String>(); |
711 |
|
712 |
DBOperations dbo = new DBOperations();
|
713 |
UserBean ub = new UserBean();
|
714 |
ub = dbo.getUserFromStore(userAlias); |
715 |
dbo.close(); |
716 |
if (ub == null) { |
717 |
map.put("RC", new Integer(Constants.ERR_USERALIAS_NOT_FOUND).toString()); |
718 |
map.put("RT", "ERR_USERALIAS_NOT_FOUND"); |
719 |
return map;
|
720 |
} |
721 |
|
722 |
// return Constants.ERR_SUCCESS;
|
723 |
map.put("RC", new Integer(Constants.ERR_SUCCESS).toString()); |
724 |
map.put("RT", "ERR_SUCCESS"); |
725 |
map.put("State", new Integer(ub.getPstate()).toString()); |
726 |
map.put("ExpiryStatus", new Integer(ub.getPexpiredStatus()).toString()); |
727 |
map.put("UseCount", new Integer(ub.getPuseCount()).toString()); |
728 |
map.put("ErrorCount", new Integer(ub.getPerrorCount()).toString()); |
729 |
map.put("DateCreated", (ub.getPdateCreated() == null) ? "NULL" : ub.getPdateCreated().toString()); |
730 |
map.put("DateFirstUsed", (ub.getPdateFirstUsed() == null) ? "NULL" : ub.getPdateFirstUsed().toString()); |
731 |
map.put("DateLastUsed", (ub.getPdateLastUsed() == null) ? "NULL" : ub.getPdateLastUsed().toString()); |
732 |
map.put("DatePasswdExpired", (ub.getPdateExpired() == null) ? "NULL" : ub.getPdateExpired().toString()); |
733 |
return map;
|
734 |
|
735 |
} |
736 |
|
737 |
/**
|
738 |
* This method is to get attributes associated to TAC. Return type is HashMap<String,String>
|
739 |
* The object keys is as below:<br/>
|
740 |
* RC - Return Code [always present]<br/>
|
741 |
* RT - Return Code in Text [always present]<br/>
|
742 |
* <br/>
|
743 |
* The following data present only with the return is ERR_SUCCESS<br/>
|
744 |
* State - User State [0-Enable] [1-Disable]<br/>
|
745 |
* UseCount - Number of time the record being access<br/>
|
746 |
* ErrorCount - Number of time the TAC verified error<br/>
|
747 |
* DateCreated - TAC Created date<br/>
|
748 |
* DateFirstUsed - First access of the TAC<br/>
|
749 |
* DateLastUsed - Last access of the TAC<br/>
|
750 |
*
|
751 |
* @param userAlias
|
752 |
* @return HashMap
|
753 |
*/
|
754 |
public HashMap<String, String> QueryTAC(String userAlias) { |
755 |
HashMap<String, String> map = new HashMap<String, String>(); |
756 |
|
757 |
DBOperations dbo = new DBOperations();
|
758 |
TacBean tacBean = new TacBean();
|
759 |
tacBean = dbo.getTacFromStore(userAlias); |
760 |
dbo.close(); |
761 |
if (tacBean == null) { |
762 |
map.put("RC", new Integer(Constants.ERR_USERALIAS_NOT_FOUND).toString()); |
763 |
map.put("RT", "ERR_USERALIAS_NOT_FOUND"); |
764 |
return map;
|
765 |
} |
766 |
|
767 |
// return Constants.ERR_SUCCESS;
|
768 |
map.put("RC", new Integer(Constants.ERR_SUCCESS).toString()); |
769 |
map.put("RT", "ERR_SUCCESS"); |
770 |
|
771 |
map.put("State", new Integer(tacBean.getState()).toString()); |
772 |
map.put("UseCount", new Integer(tacBean.getUseCount()).toString()); |
773 |
map.put("ErrorCount", new Integer(tacBean.getErrorCount()).toString()); |
774 |
map.put("DateCreated", (tacBean.getDateCreated() == null) ? "NULL" : tacBean.getDateCreated().toString()); |
775 |
map.put("DateFirstUsed", (tacBean.getDateFirstUsed() == null) ? "NULL" : tacBean.getDateFirstUsed().toString()); |
776 |
map.put("DateLastUsed", (tacBean.getDateLastUsed() == null) ? "NULL" : tacBean.getDateLastUsed().toString()); |
777 |
map.put("SessionID", (tacBean.getSessionId() == null) ? "NULL" : tacBean.getSessionId()); |
778 |
return map;
|
779 |
|
780 |
} |
781 |
|
782 |
/**
|
783 |
* This method is to change online user state to LOCKED status.
|
784 |
*
|
785 |
* @param adminUserAlias
|
786 |
* @param adminUserPassword
|
787 |
* @param userAlias
|
788 |
* @return ERR_code defined in the Constants.<br/>
|
789 |
* ERR_SUCCESS<br/>
|
790 |
* ERR_SYSTEM_NOT_READY<br/>
|
791 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
792 |
* ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
|
793 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
794 |
* ERR_EXCEED_MAX_TRIES<br/>
|
795 |
* ERR_INVALID_CREDENTIAL<br/>
|
796 |
* ERR_UNKNOWN<br/>
|
797 |
*/
|
798 |
public int UA_LockUser(String adminUserAlias, String adminUserPassword, String userAlias) { |
799 |
int rc = ua_LockUser(adminUserAlias, adminUserPassword, userAlias);
|
800 |
logger.info(adminUserAlias + " " + userAlias + " Return=" + rc); |
801 |
return rc;
|
802 |
} |
803 |
|
804 |
private int ua_LockUser(String adminUserAlias, String adminUserPassword, String userAlias) { |
805 |
// verify supervisor password
|
806 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
807 |
if (rc != Constants.ERR_SUCCESS) {
|
808 |
return rc;
|
809 |
} |
810 |
return lockUser(userAlias);
|
811 |
|
812 |
} |
813 |
|
814 |
/**
|
815 |
* This method is to change admin user state to LOCKED status.
|
816 |
*
|
817 |
* @param rootAlias
|
818 |
* @param rootPassword
|
819 |
* @param adminUserAlias
|
820 |
* @return ERR_code defined in the Constants.<br/>
|
821 |
* ERR_SUCCESS<br/>
|
822 |
* ERR_SYSTEM_NOT_READY<br/>
|
823 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
824 |
* ERR_INVALID_STATE - root not active or temporary suspended.<br/>
|
825 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
826 |
* ERR_EXCEED_MAX_TRIES<br/>
|
827 |
* ERR_INVALID_CREDENTIAL<br/>
|
828 |
* ERR_UNKNOWN<br/>
|
829 |
*/
|
830 |
public int AD_LockUser(String rootAlias, String rootPassword, String adminUserAlias) { |
831 |
int rc = ad_LockUser(rootAlias, rootPassword, adminUserAlias);
|
832 |
logger.info(rootAlias + " " + adminUserAlias + " Return=" + rc); |
833 |
return rc;
|
834 |
} |
835 |
|
836 |
private int ad_LockUser(String rootAlias, String rootPassword, String adminUserAlias) { |
837 |
|
838 |
// verify supervisor password
|
839 |
int rc = verifyStaticPassword(rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT); |
840 |
if (rc != Constants.ERR_SUCCESS) {
|
841 |
return rc;
|
842 |
} |
843 |
return lockUser(adminUserAlias);
|
844 |
} |
845 |
|
846 |
/**
|
847 |
* This method is to suspend online user from when for how many Minutes
|
848 |
*
|
849 |
* @param adminUserAlias
|
850 |
* @param adminUserPassword
|
851 |
* @param userAlias
|
852 |
* @param fromDate
|
853 |
* - from when
|
854 |
* @param nMinutes
|
855 |
* - Suspend for how many minutes
|
856 |
* @return ERR_code defined in the Constants.<br/>
|
857 |
* ERR_SUCCESS<br/>
|
858 |
* ERR_SYSTEM_NOT_READY<br/>
|
859 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
860 |
* ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
|
861 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
862 |
* ERR_EXCEED_MAX_TRIES<br/>
|
863 |
* ERR_INVALID_CREDENTIAL<br/>
|
864 |
* ERR_UNKNOWN<br/>
|
865 |
*/
|
866 |
public int UA_SuspendUser(String adminUserAlias, String adminUserPassword, String userAlias, String strFromDate, |
867 |
int nMinutes) {
|
868 |
Date fromDate = StringToDate(strFromDate);
|
869 |
int rc = ua_SuspendUser(adminUserAlias, adminUserPassword, userAlias, fromDate, nMinutes);
|
870 |
logger.info(adminUserAlias + " " + userAlias + " From:" + fromDate + " for " + nMinutes + "min Return=" + rc); |
871 |
return rc;
|
872 |
} |
873 |
|
874 |
private int ua_SuspendUser(String adminUserAlias, String adminUserPassword, String userAlias, Date fromDate, |
875 |
int nMinutes) {
|
876 |
// verify supervisor password
|
877 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
878 |
if (rc != Constants.ERR_SUCCESS) {
|
879 |
return rc;
|
880 |
} |
881 |
return lockUser(userAlias, Constants.UID_STATE_TMP_LOCKED, fromDate, nMinutes);
|
882 |
} |
883 |
|
884 |
/**
|
885 |
* This method is to suspend admin user from when for how many Minutes
|
886 |
*
|
887 |
* @param rootAlias
|
888 |
* @param rootPassword
|
889 |
* @param adminUserAlias
|
890 |
* @param fromDate
|
891 |
* - from when
|
892 |
* @param nMinutes
|
893 |
* - Suspend for how many Minutes
|
894 |
* @return ERR_code defined in the Constants.<br/>
|
895 |
* ERR_SUCCESS<br/>
|
896 |
* ERR_SYSTEM_NOT_READY<br/>
|
897 |
* ERR_USERALIAS_NOT_FOUND <br/>
|
898 |
* ERR_INVALID_STATE - root not active or temporary suspended.<br/>
|
899 |
* ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
|
900 |
* ERR_EXCEED_MAX_TRIES<br/>
|
901 |
* ERR_INVALID_CREDENTIAL<br/>
|
902 |
* ERR_UNKNOWN<br/>
|
903 |
*/
|
904 |
public int AD_SuspendUser(String rootAlias, String rootPassword, String adminUserAlias, String strFromDate, |
905 |
int nMinutes) {
|
906 |
Date fromDate = StringToDate(strFromDate);
|
907 |
int rc = ad_SuspendUser(rootAlias, rootPassword, adminUserAlias, fromDate, nMinutes);
|
908 |
logger.info(userAlias + " Return=" + rc);
|
909 |
return rc;
|
910 |
} |
911 |
|
912 |
private int ad_SuspendUser(String rootAlias, String rootPassword, String adminUserAlias, Date fromDate, int nMinutes) { |
913 |
|
914 |
// verify supervisor password
|
915 |
int rc = verifyStaticPassword(rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT); |
916 |
if (rc != Constants.ERR_SUCCESS) {
|
917 |
return rc;
|
918 |
} |
919 |
return lockUser(adminUserAlias, Constants.UID_STATE_TMP_LOCKED, fromDate, nMinutes);
|
920 |
} |
921 |
|
922 |
private int lockUser(String userAlias) { |
923 |
return lockUser(userAlias, Constants.UID_STATE_LOCKED, null, 0); |
924 |
} |
925 |
|
926 |
private int lockUser(String userAlias, int mode, Date fromDate, int nMinutes) { |
927 |
int rc;
|
928 |
|
929 |
if (userAlias == null) |
930 |
return Constants.ERR_INVALID_INPUT;
|
931 |
|
932 |
DBOperations dbo = new DBOperations();
|
933 |
UserBean ub = new UserBean();
|
934 |
ub = dbo.getUserFromStore(userAlias); |
935 |
if (ub == null) { |
936 |
dbo.close(); |
937 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
938 |
} |
939 |
|
940 |
Date now = new Date(); |
941 |
if (mode == Constants.UID_STATE_LOCKED) {
|
942 |
ub.setUstate(Constants.UID_STATE_LOCKED); |
943 |
} else {
|
944 |
ub.setUstate(Constants.UID_STATE_TMP_LOCKED); |
945 |
ub.setUdateLockedFrom(fromDate); |
946 |
|
947 |
Calendar expiryDate = Calendar.getInstance(); |
948 |
expiryDate.setTime(fromDate); // set expiry date to fromDate
|
949 |
expiryDate.add(Calendar.MINUTE, +nMinutes);
|
950 |
ub.setUdateLockedTo(expiryDate.getTime()); |
951 |
} |
952 |
|
953 |
ub.setUdateLastLocked(now); |
954 |
|
955 |
if (dbo.updateUserToStore(ub)) {
|
956 |
rc = Constants.ERR_SUCCESS; |
957 |
} |
958 |
else {
|
959 |
rc = Constants.ERR_UNKNOWN; |
960 |
} |
961 |
|
962 |
dbo.close(); |
963 |
return rc;
|
964 |
} |
965 |
|
966 |
// ///////////////////////////////////////////////////////////////////////////////
|
967 |
// token area
|
968 |
// ///////////////////////////////////////////////////////////////////////////////
|
969 |
|
970 |
/**
|
971 |
* This method is to verify token password
|
972 |
*
|
973 |
* @param userAlias
|
974 |
* @param inPassword
|
975 |
* @return ERR_code defined in the Constants<br/>
|
976 |
* ERR_SUCCESS<br/>
|
977 |
* ERR_SYSTEM_NOT_READY<br/>
|
978 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
979 |
* ERR_INVALID_STATE<br/>
|
980 |
* ERR_EXCEED_MAX_TRIES<br/>
|
981 |
* ERR_INVALID_CREDENTIAL<br/>
|
982 |
* ERR_PASSWD_EXPIRED<br/>
|
983 |
* ERR_REUSED_PASSWD<br/>
|
984 |
*/
|
985 |
public int VerifyToken(String userAlias, String inPassword) { |
986 |
int rc = verifyToken(userAlias, inPassword);
|
987 |
logger.info(userAlias + " Return=" + rc);
|
988 |
return rc;
|
989 |
} |
990 |
|
991 |
private int verifyToken(String userAlias, String inPassword) { |
992 |
DBOperations dbo = new DBOperations();
|
993 |
TokenBean tb = new TokenBean();
|
994 |
int rc = Constants.ERR_SYSTEM_NOT_READY;
|
995 |
try {
|
996 |
tb = dbo.getTokenFromStoreByUserAlias(userAlias); |
997 |
if (tb == null) { |
998 |
dbo.close(); |
999 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
1000 |
} |
1001 |
|
1002 |
if (tb.getVstate() != Constants.TKN_STATE_ASSIGNED) {
|
1003 |
dbo.close(); |
1004 |
return Constants.ERR_INVALID_STATE;
|
1005 |
} |
1006 |
|
1007 |
TokenController tc = UPassFactory.getTokenController(tb); |
1008 |
rc = tc.verifyToken(inPassword, "", ""); |
1009 |
|
1010 |
tb = tc.getUpdatedObject(); |
1011 |
|
1012 |
// update first time used
|
1013 |
if (tb.getVdateFirstUsed() == null) { |
1014 |
tb.setVdateFirstUsed(new Date()); |
1015 |
} |
1016 |
// update last time used
|
1017 |
tb.setVdateLastUsed(new Date()); |
1018 |
|
1019 |
// update database
|
1020 |
boolean lrc = dbo.updateTokenToStore(tb);
|
1021 |
dbo.close(); |
1022 |
if (!lrc) {
|
1023 |
return Constants.ERR_UNKNOWN;
|
1024 |
} |
1025 |
} catch (Exception e) |
1026 |
{ |
1027 |
e.printStackTrace(); |
1028 |
} |
1029 |
|
1030 |
return rc;
|
1031 |
} |
1032 |
|
1033 |
/**
|
1034 |
* This method is to reset user token <br/>
|
1035 |
*
|
1036 |
* @param adminUserAlias
|
1037 |
* @param adminUserPassword
|
1038 |
* @param userAlias
|
1039 |
* @return ERR_code defined in the Constants<br/>
|
1040 |
* ERR_SUCCESS<br/>
|
1041 |
* ERR_SYSTEM_NOT_READY<br/>
|
1042 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
1043 |
* ERR_INVALID_STATE<br/>
|
1044 |
* ERR_EXCEED_MAX_TRIES<br/>
|
1045 |
* ERR_INVALID_CREDENTIAL<br/>
|
1046 |
*/
|
1047 |
public int ResetToken(String adminUserAlias, String adminUserPassword, String userAlias) { |
1048 |
int rc = resetToken(adminUserAlias, adminUserPassword, userAlias);
|
1049 |
logger.info(adminUserAlias + " " + userAlias + " Return=" + rc); |
1050 |
return rc;
|
1051 |
} |
1052 |
|
1053 |
private int resetToken(String adminUserAlias, String adminUserPassword, String userAlias) { |
1054 |
|
1055 |
// verify supervisor password
|
1056 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
1057 |
if (rc != Constants.ERR_SUCCESS) {
|
1058 |
return rc;
|
1059 |
} |
1060 |
|
1061 |
DBOperations dbo = new DBOperations();
|
1062 |
TokenBean tb = new TokenBean();
|
1063 |
tb = dbo.getTokenFromStoreByUserAlias(userAlias); |
1064 |
if (tb == null) { |
1065 |
dbo.close(); |
1066 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
1067 |
} |
1068 |
|
1069 |
TokenController tc = UPassFactory.getTokenController(tb); |
1070 |
rc = tc.resetToken(); |
1071 |
tb = tc.getUpdatedObject(); |
1072 |
|
1073 |
// update database
|
1074 |
boolean lrc = dbo.updateTokenToStore(tb);
|
1075 |
dbo.close(); |
1076 |
if (!lrc) {
|
1077 |
return Constants.ERR_UNKNOWN;
|
1078 |
} |
1079 |
|
1080 |
return rc;
|
1081 |
} |
1082 |
|
1083 |
/**
|
1084 |
* This method is to query token information, Return type is HashMap<String,String>
|
1085 |
* RC - Return Code [always present]<br/>
|
1086 |
* RT - Return Code in Text [always present]<br/>
|
1087 |
* <br/>
|
1088 |
* The following data present only with the return is ERR_SUCCESS<br/>
|
1089 |
* SerailNo - The serial number of token<br/>
|
1090 |
* State - Token State, [0-UNASSIGNED], [1-ASSIGNED], [2-DISABLE], [3-LOCKED], [4-DELETED]<br/>
|
1091 |
* UseCount - number of time of password authentication <br/>
|
1092 |
* ErrorCount - number of time error encountered of password authentication<br/>
|
1093 |
* DateAssigned - date of assignment to user<br/>
|
1094 |
* DateFirstUsed - date of 1st time use<br/>
|
1095 |
* DateLastUsed - date of last time used<br/>
|
1096 |
* BatchID - the ID used for loading the token into data store<br/>
|
1097 |
* <br/>
|
1098 |
*
|
1099 |
* Data retrieved from token BLOB<br/>
|
1100 |
* TOKEN_MODEL<br/>
|
1101 |
* USE_COUNT<br/>
|
1102 |
* ERROR_COUNT<br/>
|
1103 |
* LAST_TIME_USED<br/>
|
1104 |
* CODE_WORD<br/>
|
1105 |
* TRIPLE_DES<br/>
|
1106 |
* MAX_INPUT_FIELDS<br/>
|
1107 |
* RESPONSE_LENGTH<br/>
|
1108 |
* RESPONSE_TYPE<br/>
|
1109 |
* RESPONSE_CHECKSUM<br/>
|
1110 |
* TIME_STEP_USED<br/>
|
1111 |
*
|
1112 |
* @param userAlias
|
1113 |
* @return HashMap
|
1114 |
*/
|
1115 |
public HashMap<String, String> QueryToken(String userAlias) { |
1116 |
HashMap<String, String> map = new HashMap<String, String>(); |
1117 |
|
1118 |
DBOperations dbo = new DBOperations();
|
1119 |
TokenBean tb = new TokenBean();
|
1120 |
tb = dbo.getTokenFromStoreByUserAlias(userAlias); |
1121 |
dbo.close(); |
1122 |
|
1123 |
if (tb == null) { |
1124 |
map.put("RC", new Integer(Constants.ERR_USERALIAS_NOT_FOUND).toString()); |
1125 |
map.put("RT", "ERR_USERALIAS_NOT_FOUND"); |
1126 |
return map;
|
1127 |
} |
1128 |
|
1129 |
map.put("RC", new Integer(Constants.ERR_SUCCESS).toString()); |
1130 |
map.put("RT", "ERR_SUCCESS"); |
1131 |
|
1132 |
map.put("SerailNo", tb.getVserialNumber());
|
1133 |
map.put("State", new Integer(tb.getVstate()).toString()); |
1134 |
map.put("UseCount", new Integer(tb.getVuseCount()).toString()); |
1135 |
map.put("ErrorCount", new Integer(tb.getVerrorCount()).toString()); |
1136 |
map.put("DateAssigned", (tb.getVdateAssigned() == null) ? "NULL" : tb.getVdateAssigned().toString()); |
1137 |
map.put("DateFirstUsed", (tb.getVdateFirstUsed() == null) ? "NULL" : tb.getVdateFirstUsed().toString()); |
1138 |
map.put("DateLastUsed", (tb.getVdateLastUsed() == null) ? "NULL" : tb.getVdateLastUsed().toString()); |
1139 |
map.put("BatchID", new Long(tb.getVbatchNo()).toString()); |
1140 |
|
1141 |
HashMap<String, String> hmBLOB = new HashMap<String, String>(); |
1142 |
TokenController tc = UPassFactory.getTokenController(tb); |
1143 |
hmBLOB = tc.getTokenBlobInfo(); |
1144 |
|
1145 |
map.put("TOKEN_MODEL", hmBLOB.get("TOKEN_MODEL")); |
1146 |
map.put("USE_COUNT", hmBLOB.get("USE_COUNT")); |
1147 |
map.put("ERROR_COUNT", hmBLOB.get("ERROR_COUNT")); |
1148 |
map.put("LAST_TIME_USED", hmBLOB.get("LAST_TIME_USED")); |
1149 |
map.put("CODE_WORD", hmBLOB.get("CODE_WORD")); |
1150 |
map.put("TRIPLE_DES", hmBLOB.get("TRIPLE_DES")); |
1151 |
map.put("MAX_INPUT_FIELDS", hmBLOB.get("MAX_INPUT_FIELDS")); |
1152 |
map.put("RESPONSE_LENGTH", hmBLOB.get("RESPONSE_LENGTH")); |
1153 |
map.put("RESPONSE_TYPE", hmBLOB.get("RESPONSE_TYPE")); |
1154 |
map.put("RESPONSE_CHECKSUM", hmBLOB.get("RESPONSE_CHECKSUM")); |
1155 |
map.put("TIME_STEP_USED", hmBLOB.get("TIME_STEP_USED")); |
1156 |
|
1157 |
return map;
|
1158 |
} |
1159 |
|
1160 |
public int DeleteTokenFromStore(String adminUserAlias, String adminUserPassword, String serialNumber) { |
1161 |
int rc = deleteTokenFromStore(adminUserAlias, adminUserPassword, serialNumber);
|
1162 |
logger.info(serialNumber + " Return=" + rc);
|
1163 |
return rc;
|
1164 |
} |
1165 |
|
1166 |
private int deleteTokenFromStore(String adminUserAlias, String adminUserPassword, String serialNumber) { |
1167 |
// verify supervisor password
|
1168 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
1169 |
if (rc != Constants.ERR_SUCCESS) {
|
1170 |
return rc;
|
1171 |
} |
1172 |
|
1173 |
DBOperations dbo = new DBOperations();
|
1174 |
boolean lrc = dbo.deleteTokenFromStoreBySerialNumber(serialNumber);
|
1175 |
dbo.close(); |
1176 |
|
1177 |
if (lrc)
|
1178 |
return Constants.ERR_SUCCESS;
|
1179 |
else
|
1180 |
return Constants.ERR_TOKEN_NOT_EXIST;
|
1181 |
|
1182 |
} |
1183 |
|
1184 |
/**
|
1185 |
* This method is to assign token to user<br/>
|
1186 |
*
|
1187 |
* @param serialNumber
|
1188 |
* @param userAlias
|
1189 |
* @return ERR_code defined in the Constants<br/>
|
1190 |
* ERR_SUCCESS<br/>
|
1191 |
* ERR_SYSTEM_NOT_READY<br/>
|
1192 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
1193 |
* ERR_INVALID_STATE<br/>
|
1194 |
*/
|
1195 |
public int AssignTokenToUser(String adminUserAlias, String adminUserPassword, String serialNumber, String userAlias) { |
1196 |
int rc = assignToken(adminUserAlias, adminUserPassword, serialNumber, userAlias, Constants.TKN_STATE_ASSIGNED);
|
1197 |
logger.info(serialNumber + " " + userAlias + " Return=" + rc); |
1198 |
return rc;
|
1199 |
} |
1200 |
|
1201 |
/**
|
1202 |
* This method is to return Token to store; Reset the Token.<br/>
|
1203 |
* The token is ready to re-assign to other user.<br/>
|
1204 |
*
|
1205 |
* @param adminUserAlias
|
1206 |
* @param adminUserPassword
|
1207 |
* @param userAlias
|
1208 |
* @return ERR_code defined in the Constants<br/>
|
1209 |
* ERR_SUCCESS<br/>
|
1210 |
* ERR_SYSTEM_NOT_READY<br/>
|
1211 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
1212 |
* ERR_INVALID_STATE<br/>
|
1213 |
*/
|
1214 |
public int UnassignTokenFromUser(String adminUserAlias, String adminUserPassword, String userAlias) { |
1215 |
int rc = assignToken(adminUserAlias, adminUserPassword, null, userAlias, Constants.TKN_STATE_UNASSIGNED); |
1216 |
logger.info(userAlias + " Return=" + rc);
|
1217 |
return rc;
|
1218 |
} |
1219 |
|
1220 |
/**
|
1221 |
* This method is to disable the token<br/>
|
1222 |
*
|
1223 |
* @param adminUserAlias
|
1224 |
* @param adminUserPassword
|
1225 |
* @param userAlias
|
1226 |
* @return ERR_code defined in the Constants<br/>
|
1227 |
* ERR_SUCCESS<br/>
|
1228 |
* ERR_SYSTEM_NOT_READY<br/>
|
1229 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
1230 |
* ERR_INVALID_STATE<br/>
|
1231 |
*/
|
1232 |
public int DisableToken(String adminUserAlias, String adminUserPassword, String userAlias) { |
1233 |
int rc = disableToken(adminUserAlias, adminUserPassword, userAlias, true); |
1234 |
logger.info(userAlias + " Return=" + rc);
|
1235 |
return rc;
|
1236 |
} |
1237 |
|
1238 |
/**
|
1239 |
* This method is to enable to token<br/>
|
1240 |
*
|
1241 |
* @param adminUserAlias
|
1242 |
* @param adminUserPassword
|
1243 |
* @param userAlias
|
1244 |
* @return ERR_code defined in the Constants<br/>
|
1245 |
* ERR_SUCCESS<br/>
|
1246 |
* ERR_SYSTEM_NOT_READY<br/>
|
1247 |
* ERR_USERALIAS_NOT_FOUND<br/>
|
1248 |
* ERR_INVALID_STATE<br/>
|
1249 |
*/
|
1250 |
public int EnableToken(String adminUserAlias, String adminUserPassword, String userAlias) { |
1251 |
int rc = disableToken(adminUserAlias, adminUserPassword, userAlias, false); |
1252 |
logger.info(userAlias + " Return=" + rc);
|
1253 |
return rc;
|
1254 |
} |
1255 |
|
1256 |
private int disableToken(String adminUserAlias, String adminUserPassword, String userAlias, boolean ldisable) { |
1257 |
// verify supervisor password
|
1258 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
1259 |
if (rc != Constants.ERR_SUCCESS) {
|
1260 |
return rc;
|
1261 |
} |
1262 |
|
1263 |
DBOperations dbo = new DBOperations();
|
1264 |
TokenBean tb = new TokenBean();
|
1265 |
tb = dbo.getTokenFromStoreByUserAlias(userAlias); |
1266 |
|
1267 |
// check state vs operations
|
1268 |
boolean validState = true; |
1269 |
if (ldisable & tb.getVstate() != Constants.TKN_STATE_ASSIGNED) {
|
1270 |
validState = false;
|
1271 |
} |
1272 |
|
1273 |
if (!ldisable & tb.getVstate() != Constants.TKN_STATE_DISABLE) {
|
1274 |
validState = false;
|
1275 |
} |
1276 |
|
1277 |
if (!validState) {
|
1278 |
dbo.close(); |
1279 |
return Constants.ERR_INVALID_STATE;
|
1280 |
} |
1281 |
|
1282 |
// assign state according to Enable|Disable
|
1283 |
int TargetTokenAssignmentState = (ldisable) ? Constants.TKN_STATE_DISABLE : Constants.TKN_STATE_ASSIGNED;
|
1284 |
tb.setVstate(TargetTokenAssignmentState); |
1285 |
tb.setVdateLastUsed(null);
|
1286 |
|
1287 |
// update database
|
1288 |
boolean lrc = dbo.updateTokenToStore(tb);
|
1289 |
dbo.close(); |
1290 |
if (!lrc) {
|
1291 |
return Constants.ERR_UNKNOWN;
|
1292 |
} |
1293 |
|
1294 |
return Constants.ERR_SUCCESS;
|
1295 |
} |
1296 |
|
1297 |
private int assignToken(String adminUserAlias, String adminUserPassword, String serialNumber, String userAlias, |
1298 |
int TargetTokenAssignmentState) {
|
1299 |
|
1300 |
// verify supervisor password
|
1301 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
1302 |
if (rc != Constants.ERR_SUCCESS) {
|
1303 |
return rc;
|
1304 |
} |
1305 |
|
1306 |
DBOperations dbo = new DBOperations();
|
1307 |
TokenBean tb = new TokenBean();
|
1308 |
String targetUserAlias = null; |
1309 |
|
1310 |
if (TargetTokenAssignmentState == Constants.TKN_STATE_ASSIGNED) {
|
1311 |
// if the operation is to assign token to user, query by token serial number
|
1312 |
// then assign token to user
|
1313 |
tb = dbo.getTokenFromStoreBySerialNumber(serialNumber); |
1314 |
targetUserAlias = userAlias; |
1315 |
} else {
|
1316 |
// query by user ID, since it already assigned
|
1317 |
// then return token back to TokenOwner
|
1318 |
tb = dbo.getTokenFromStoreByUserAlias(userAlias); |
1319 |
targetUserAlias = "TokenOwner";
|
1320 |
} |
1321 |
|
1322 |
if (tb == null) { |
1323 |
dbo.close(); |
1324 |
return Constants.ERR_TOKEN_NOT_EXIST;
|
1325 |
} |
1326 |
|
1327 |
// check if the token already assigned and the target state is assignToken
|
1328 |
if (TargetTokenAssignmentState == Constants.TKN_STATE_ASSIGNED &
|
1329 |
tb.getVstate() == Constants.TKN_STATE_ASSIGNED) { |
1330 |
return Constants.ERR_TOKEN_ALREADY_ASSIGNED;
|
1331 |
} |
1332 |
|
1333 |
// check user exist for the token
|
1334 |
UserBean ub = new UserBean();
|
1335 |
ub = dbo.getUserFromStore(targetUserAlias); |
1336 |
if (ub == null) { |
1337 |
dbo.close(); |
1338 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
1339 |
} |
1340 |
|
1341 |
// reset and assign token to user
|
1342 |
TokenController tc = UPassFactory.getTokenController(tb); |
1343 |
rc = tc.resetToken(); |
1344 |
|
1345 |
tb = tc.getUpdatedObject(); |
1346 |
tb.setVstate(TargetTokenAssignmentState); |
1347 |
tb.setVdateAssigned(new Date()); |
1348 |
tb.setVuserID(ub.getUserID()); |
1349 |
tb.setVdateFirstUsed(null);
|
1350 |
tb.setVdateLastUsed(null);
|
1351 |
|
1352 |
// update database
|
1353 |
boolean lrc = dbo.updateTokenToStore(tb);
|
1354 |
dbo.close(); |
1355 |
if (!lrc) {
|
1356 |
return Constants.ERR_UNKNOWN;
|
1357 |
} |
1358 |
|
1359 |
return Constants.ERR_SUCCESS;
|
1360 |
|
1361 |
} |
1362 |
|
1363 |
/**
|
1364 |
* This method is to load token from DPX file to UPass data store
|
1365 |
* Refer to System Console for additional information.
|
1366 |
*
|
1367 |
* @param adminUserAlias
|
1368 |
* @param adminUserPassword
|
1369 |
* @param filename
|
1370 |
* @param importKey
|
1371 |
* @param BatchID
|
1372 |
* @return ERR_code defined in the Constants<br/>
|
1373 |
* ERR_SUCCESS<br/>
|
1374 |
* ERR_SYSTEM_NOT_READY<br/>
|
1375 |
*/
|
1376 |
public int LoadToken(String adminUserAlias, String adminUserPassword, String filename, String importKey, |
1377 |
String BatchID) {
|
1378 |
int rc = loadToken(adminUserAlias, adminUserPassword, filename, importKey, BatchID);
|
1379 |
logger.info(userAlias + " Return=" + rc);
|
1380 |
return rc;
|
1381 |
} |
1382 |
|
1383 |
private int loadToken(String adminUserAlias, String adminUserPassword, String filename, String importKey, |
1384 |
String BatchID) {
|
1385 |
|
1386 |
// verify supervisor password
|
1387 |
int rc = verifyStaticPassword(adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN); |
1388 |
if (rc != Constants.ERR_SUCCESS) {
|
1389 |
return rc;
|
1390 |
} |
1391 |
|
1392 |
LoadTokenDPX ldpx = new LoadTokenDPX(filename, importKey, BatchID);
|
1393 |
rc = ldpx.importToken(); |
1394 |
|
1395 |
return rc;
|
1396 |
} |
1397 |
|
1398 |
// ///////////////////////////////////////////////////////////////////////////////
|
1399 |
// token area end
|
1400 |
// ///////////////////////////////////////////////////////////////////////////////
|
1401 |
|
1402 |
private Date StringToDate(String dateString) { |
1403 |
|
1404 |
String DATE_FORMAT = "yyyyMMddHHmmss"; |
1405 |
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); |
1406 |
Date parsedDate = new Date(); |
1407 |
try {
|
1408 |
parsedDate = format.parse(dateString); |
1409 |
} catch (ParseException pe) { |
1410 |
logger.info("ERROR: Cannot parse date in String " + dateString);
|
1411 |
} |
1412 |
|
1413 |
logger.info("Date=" + parsedDate.toString());
|
1414 |
|
1415 |
return parsedDate;
|
1416 |
} |
1417 |
}// end class
|