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