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