Statistics
| Branch: | Revision:

m2u-upass-core / src / my / com / upass / UPassControllerV2.java @ 44:7a7fb8fcfd6e

History | View | Annotate | Download (41.6 KB)

1
/**
2
 * Copyright (M) 2010 Penril Datability (M) Sdn Bhd All rights reserved.
3
 *
4
 * This software is copyrighted. Under the copyright laws, this software
5
 * may not be copied, in whole or in part, without prior written consent
6
 * of Penril Datability (M) Sdn Bhd or its assignees. This software is
7
 * provided under the terms of a license between Penril Datability (M)
8
 * Sdn Bhd and the recipient, and its use is subject to the terms of that
9
 * license.
10
 */
11
package my.com.upass;
12

    
13
import java.text.ParseException;
14
import java.text.SimpleDateFormat;
15
import java.util.Date;
16
import java.util.HashMap;
17

    
18
import my.com.upass.MinimalUPassControllerV2.AccessCheckResult;
19
import my.com.upass.factory.UPassFactory;
20
import my.com.upass.pojo.ClientApp;
21
import my.com.upass.services.ActivateUserService;
22
import my.com.upass.services.AppAccessMgtService.MultipleAppAccessesFound;
23
import my.com.upass.services.AssignTokenService;
24
import my.com.upass.services.CheckPasswordReusedService;
25
import my.com.upass.services.DeleteTokenService;
26
import my.com.upass.services.DeleteUserService;
27
import my.com.upass.services.DisableTacService;
28
import my.com.upass.services.DisableTokenService;
29
import my.com.upass.services.GenerateSecurityCodeService;
30
import my.com.upass.services.GenerateTacService;
31
import my.com.upass.services.LoadTokenService;
32
import my.com.upass.services.LockUserService;
33
import my.com.upass.services.QueryInfoService;
34
import my.com.upass.services.ResetTacService;
35
import my.com.upass.services.ResetTokenService;
36
import my.com.upass.services.SynchronizeTokenService;
37
import my.com.upass.services.VerifyPasswordComplexityService;
38
import my.com.upass.services.VerifySecurityCodeService;
39
import my.com.upass.services.VerifyTacService;
40
import my.com.upass.services.VerifyTokenService;
41

    
42
import org.apache.commons.lang.NotImplementedException;
43
import org.hibernate.Session;
44

    
45
/**
46
 * PROGRAMMER: Danniell
47
 * CHANGE-NO:
48
 * TASK-NO:
49
 * DATE CREATED: Oct 8, 2011
50
 * TAG AS:
51
 * REASON(S):
52
 * MODIFICATION:
53
 */
54

    
55
/**
56
 * Data Access Object version of UPASS Controller
57
 */
58
/**
59
 * @author Enson
60
 * 
61
 */
62
public class UPassControllerV2 extends MinimalUPassControllerV2
63
{
64
        private CheckPasswordReusedService checkPasswordReusedService = new CheckPasswordReusedService(this);
65
        private GenerateTacService generateTacService = new GenerateTacService(this);
66
        private VerifyTacService verifyTacService = new VerifyTacService(this);
67
        private ResetTacService resetTacService = new ResetTacService(this);
68
        private GenerateSecurityCodeService generateSecurityCodeService = new GenerateSecurityCodeService(this);
69
        private VerifySecurityCodeService verifySecurityCodeService = new VerifySecurityCodeService(this);
70
        private DisableTacService disableTacService = new DisableTacService(this);
71
        private ActivateUserService activateUserService = new ActivateUserService();
72
        private QueryInfoService queryInfoService = new QueryInfoService();
73
        private LockUserService lockUserService = new LockUserService();
74
        private VerifyTokenService verifyTokenService = new VerifyTokenService();
75
        private LoadTokenService loadTokenService = new LoadTokenService();
76
        private ResetTokenService resetTokenService = new ResetTokenService();
77
        private DeleteTokenService deleteTokenService = new DeleteTokenService();
78
        private AssignTokenService assignTokenService = new AssignTokenService();
79
        private DisableTokenService disableTokenService = new DisableTokenService();
80
        private SynchronizeTokenService synchronizeTokenService = new SynchronizeTokenService();
81
        private VerifyPasswordComplexityService verifyPasswordComplexityService = new VerifyPasswordComplexityService(this);
82
        private DeleteUserService deleteUserService = new DeleteUserService();
83

    
84
        // ////////////////////////////////////////////////////////////////////////////////////////
85
        // Static Password Methods
86
        // /////////////////////////////////////////////////////////////////////////////////////////
87
        /**
88
         * This method verify static password generated using SP_ChangeStaticPassword()
89
         * and also check for user dormant status
90
         * 
91
         * @param userAlias
92
         * @param password
93
         * @return ERR_code defined in the Constants.<br/>
94
         *         ERR_SUCCESS<br/>
95
         *         ERR_SYSTEM_NOT_READY<br/>
96
         *         ERR_USERALIAS_NOT_FOUND <br/>
97
         *         ERR_INVALID_STATE - user not active or temporary suspended.<br/>
98
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
99
         *         ERR_EXCEED_MAX_TRIES - used ModifyUser to reset password.<br/>
100
         *         ERR_INVALID_CREDENTIAL<br/>
101
         *         ERR_PASSWD_EXPIRED - password is valid but expired, suggest to change new password.<br/>
102
         */
103
        public int SP_Login(String userAlias, String password)
104
        {
105
                int rc = verifyStaticPasswordService.login(userAlias, password, false, 0);
106
                logger.info("SP_Login - user alias: [" + userAlias + "] Return: " + rc);
107
                return rc;
108
        }
109

    
110
        public int SP_ForceChangeStaticPassword(String userAlias, String newPassword, String oldPassword)
111
        {
112
                int rc = changeStaticPasswordService.changeStaticPassword(userAlias, newPassword, oldPassword, false);
113
                logger.info("SP_ChangeStaticPassword - user alias: [" + userAlias + "] Return: " + rc);
114
                return rc;
115
        }
116

    
117
        public int UA_CheckPasswordReused(String userAlias, String password)
118
        {
119
                int rc = checkPasswordReusedService.CheckPasswordReused(userAlias, password);
120
                logger.info("UA_CheckPasswordReused - user alias: [" + userAlias + "] Return: " + rc);
121
                return rc;
122
        }
123

    
124
        // /////////////////////////////////////////////////////////////////////////////////////////
125
        // TAC Methods ...
126
        // /////////////////////////////////////////////////////////////////////////////////////////
127

    
128
        /**
129
         * This method to Generate 6-digit TAC.
130
         * 
131
         * @param userAlias
132
         * @param appId
133
         *            TODO
134
         * @return 6-digit TAC or Error code with prefix *** <br/>
135
         *         ***98 ERR_SYSTEM_NOT_READY<br/>
136
         *         ***6 ERR_USERALIAS_NOT_FOUND<br/>
137
         *         ***12 ERR_TAC_ALREADY_EXIST - Repeated request within allowed period<br/>
138
         */
139
        public String GenerateTAC(String userAlias, int appId) {
140

    
141
                String tac = generateTacService.generateTAC(userAlias, null, null, appId);
142
                logger.info(userAlias + " Return=" + tac.substring(2));
143
                return tac;
144
        }
145

    
146
        /**
147
         * This method to Generate 6-digit TAC with SessionID verification.
148
         * 
149
         * @param userAlias
150
         * @param sessionID
151
         *            16-Characters SessionID
152
         * @param appId
153
         *            TODO
154
         * @return 6-digit TAC or Error code with prefix *** <br/>
155
         *         ***98 ERR_SYSTEM_NOT_READY<br/>
156
         *         ***6 ERR_USERALIAS_NOT_FOUND<br/>
157
         *         ***12 ERR_TAC_ALREADY_EXIST - Repeated request within allowed period<br/>
158
         */
159
        public String GenerateTAC(String userAlias, String sessionID, int appId) {
160

    
161
                String tac = generateTacService.generateTAC(userAlias, sessionID, null, appId);
162
                logger.info(userAlias + " SessionID=" + sessionID + " Return=" + tac.substring(2));
163
                return tac;
164
        }
165

    
166
        /**
167
         * This method to Generate 6-digit TAC with SessionID verification.
168
         * 
169
         * @param userAlias
170
         * @param sessionID
171
         *            16-Characters SessionID
172
         * @param nonce
173
         *            Additional nonce value
174
         * @param appId
175
         *            TODO
176
         * @return 6-digit TAC or Error code with prefix *** <br/>
177
         *         ***98 ERR_SYSTEM_NOT_READY<br/>
178
         *         ***6 ERR_USERALIAS_NOT_FOUND<br/>
179
         *         ***12 ERR_TAC_ALREADY_EXIST - Repeated request within allowed period<br/>
180
         */
181
        public String GenerateTAC(String userAlias, String sessionID, String nonce, int appId) {
182

    
183
                String tac = generateTacService.generateTAC(userAlias, sessionID, nonce, appId);
184
                logger.info(userAlias + " SessionID=" + sessionID + " Return=" + tac.substring(2));
185
                return tac;
186
        }
187

    
188
        /**
189
         * This method to verify 6-digit TAC generated by GenerateTAC()
190
         * 
191
         * @param userAlias
192
         * @param inTac
193
         *            User inputs TAC
194
         * @param appId
195
         *            TODO
196
         * @return ERR_code defined in the Constants<br/>
197
         *         ERR_SUCCESS<br/>
198
         *         ERR_SYSTEM_NOT_READY<br/>
199
         *         ERR_USERALIAS_NOT_FOUND<br/>
200
         *         ERR_INVALID_STATE - Verify method call before generation; TAC disabled.<br/>
201
         *         ERR_EXCEED_MAX_TRIES<br/>
202
         *         ERR_INVALID_CREDENTIAL<br/>
203
         *         ERR_PASSWD_EXPIRED - TAC expired.<br/>
204
         */
205
        public int VerifyTAC(String userAlias, String inTac, int appId) {
206

    
207
                int rc = verifyTacService.verifyTAC(userAlias, inTac, null, appId);
208
                logger.info("VerifyTAC - user alias: [" + userAlias + "] Return: " + rc);
209
                return rc;
210
        }
211

    
212
        /**
213
         * This method to verify 6-digit TAC generated by GenerateTAC() with SessionID verification
214
         * 
215
         * @param userAlias
216
         * @param inTac
217
         *            User inputs TAC
218
         * @param sessionID
219
         *            16-Characters SessionID
220
         * @param appId
221
         *            TODO
222
         * @return ERR_code defined in the Constants<br/>
223
         *         ERR_SUCCESS<br/>
224
         *         ERR_SYSTEM_NOT_READY<br/>
225
         *         ERR_USERALIAS_NOT_FOUND<br/>
226
         *         ERR_INVALID_STATE - Verify method call before generation; TAC disabled.<br/>
227
         *         ERR_EXCEED_MAX_TRIES<br/>
228
         *         ERR_INVALID_CREDENTIAL<br/>
229
         *         ERR_PASSWD_EXPIRED - TAC expired.<br/>
230
         *         ERR_INVALID_SESSION<br/>
231
         */
232
        public int VerifyTAC(String userAlias, String inTac, String sessionID, int appId) {
233

    
234
                return VerifyTAC(userAlias, inTac, sessionID, null, appId);
235
        }
236

    
237
        /**
238
         * This method to verify 6-digit TAC generated by GenerateTAC() with SessionID verification
239
         * 
240
         * @param userAlias
241
         * @param inTac
242
         *            User inputs TAC
243
         * @param sessionID
244
         *            16-Characters SessionID
245
         * @param nonce
246
         *            Additional nonce value
247
         * @param appId
248
         *            TODO
249
         * @return ERR_code defined in the Constants<br/>
250
         *         ERR_SUCCESS<br/>
251
         *         ERR_SYSTEM_NOT_READY<br/>
252
         *         ERR_USERALIAS_NOT_FOUND<br/>
253
         *         ERR_INVALID_STATE - Verify method call before generation; TAC disabled.<br/>
254
         *         ERR_EXCEED_MAX_TRIES<br/>
255
         *         ERR_INVALID_CREDENTIAL<br/>
256
         *         ERR_PASSWD_EXPIRED - TAC expired.<br/>
257
         *         ERR_INVALID_SESSION<br/>
258
         */
259
        public int VerifyTAC(String userAlias, String inTac, String sessionID, String nonce, int appId) {
260

    
261
                int rc = verifyTacService.verifyTAC(userAlias, inTac, sessionID, nonce, appId);
262
                logger.info("VerifyTAC - user alias: [" + userAlias + "] SessID: [" + sessionID + "] Return: " + rc);
263
                return rc;
264
        }
265

    
266
        /**
267
         * This method is to reset Error Count to Zero and set state to PASSWD_STATUS_ENABLE
268
         * 
269
         * @param adminUserAlias
270
         * @param adminUserPassword
271
         * @param userAlias
272
         * @return ERR_code defined in the Constants<br/>
273
         *         ERR_SUCCESS<br/>
274
         *         ERR_SYSTEM_NOT_READY<br/>
275
         *         ERR_USERALIAS_NOT_FOUND <br/>
276
         *         ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
277
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
278
         *         ERR_EXCEED_MAX_TRIES<br/>
279
         *         ERR_INVALID_CREDENTIAL<br/>
280
         *         ERR_UNKNOWN<br/>
281
         */
282
        public int ResetTAC(String adminUserAlias, String adminUserPassword, String userAlias) {
283

    
284
                int rc = verifyStaticPasswordService.verifyStaticPassword(
285
                                adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN);
286

    
287
                if (rc != Constants.ERR_SUCCESS) {
288
                        return rc;
289
                }
290
                rc = resetTacService.resetTAC(userAlias);
291
                logger.info("ResetTAC - user alias: [" + userAlias + "] Return: " + rc);
292
                return rc;
293
        }
294

    
295
        /**
296
         * This method is to set state to PASSWD_STATUS_DISABLE
297
         * 
298
         * @param adminUserAlias
299
         * @param adminUserPassword
300
         * @param userAlias
301
         * @return ERR_code defined in the Constants<br/>
302
         *         ERR_SUCCESS<br/>
303
         *         ERR_SYSTEM_NOT_READY<br/>
304
         *         ERR_USERALIAS_NOT_FOUND <br/>
305
         *         ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
306
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
307
         *         ERR_EXCEED_MAX_TRIES<br/>
308
         *         ERR_INVALID_CREDENTIAL<br/>
309
         *         ERR_UNKNOWN<br/>
310
         */
311
        public int DisableTAC(String adminUserAlias, String adminUserPassword, String userAlias) {
312

    
313
                int rc = verifyStaticPasswordService.verifyStaticPassword(
314
                                adminUserAlias, adminUserPassword, true, Constants.UTYPE_STATE_ADMIN);
315

    
316
                if (rc != Constants.ERR_SUCCESS) {
317
                        return rc;
318
                }
319
                rc = disableTacService.disableTAC(userAlias);
320
                logger.info("DisableTAC - user alias: [" + userAlias + "] Return: " + rc);
321
                return rc;
322
        }
323

    
324
        // /////////////////////////////////////////////////////////////////////////////////////////
325
        // User Administration methods.
326
        // /////////////////////////////////////////////////////////////////////////////////////////
327

    
328
        /**
329
         * This method to modify admin users to the system
330
         * 
331
         * @param rootAlias
332
         * @param rootPassword
333
         * @param adminUserAlias
334
         * @param adminDesc
335
         *            - can be null - Null denotes no description will be modified.
336
         * @param adminUserPassword
337
         *            - can be null - Null denotes no password will be modified.
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 - root 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_INVALID_INPUT - internal error.<br/>
347
         *         ERR_USERALIAS_NOT_FOUND<br/>
348
         *         ERR_REUSED_PASSWD - the password entered was used previously.<br/>
349
         *         ERR_PASSWD_WEAK - the password entered is too weak.<br/>
350
         *         ERR_INVALID_USERALIAS - User alias does not match with defined pattern <br/>
351
         *         ERR_PASSWORD_SAMEAS_USERALIAS - password is same is user name error <br/>
352
         */
353
        public int AD_ModifyUser(String rootAlias, String rootPassword,
354
                        String adminUserAlias, String adminDesc, String adminUserPassword)
355
        {
356
                // check if password is similar to user alias
357
                if (rootAlias.equalsIgnoreCase(rootPassword)) {
358
                        return Constants.ERR_PASSWORD_SAMEAS_USERALIAS;
359
                }
360

    
361
                int rc = verifyStaticPasswordService.verifyStaticPassword(
362
                                rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT);
363

    
364
                if (rc != Constants.ERR_SUCCESS)
365
                {
366
                        return rc;
367
                }
368

    
369
                rc = modifyUserService.modifyUser(adminUserAlias,
370
                                Constants.UTYPE_STATE_ADMIN, adminDesc, adminUserPassword,
371
                                Constants.UID_STATE_ACTIVE);
372

    
373
                logger.info("AD_ModifyUser - admin user alias: [" + adminUserAlias
374
                                + "] Return: " + rc);
375

    
376
                return rc;
377
        }
378

    
379
        /**
380
         * This method to change online users state to ACTIVE status.
381
         * 
382
         * @param adminUserAlias
383
         * @param adminUserPassword
384
         * @param userAlias
385
         * @return ERR_code defined in the Constants.<br/>
386
         *         ERR_SUCCESS<br/>
387
         *         ERR_SYSTEM_NOT_READY<br/>
388
         *         ERR_USERALIAS_NOT_FOUND <br/>
389
         *         ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
390
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
391
         *         ERR_EXCEED_MAX_TRIES<br/>
392
         *         ERR_INVALID_CREDENTIAL<br/>
393
         *         ERR_USERALIAS_NOT_FOUND<br/>
394
         *         ERR_UNKNOWN <br/>
395
         */
396
        public int UA_ActivateUser(String adminUserAlias, String adminUserPassword, String userAlias)
397
        {
398
                int rc = verifyStaticPasswordService.verifyStaticPassword(
399
                                adminUserAlias, adminUserPassword, true,
400
                                Constants.UTYPE_STATE_ADMIN);
401

    
402
                if (rc != Constants.ERR_SUCCESS)
403
                {
404
                        return rc;
405
                }
406

    
407
                rc = activateUserService.activateUser(userAlias);
408

    
409
                logger.info("UA_ActivateUser - user alias: [" + userAlias
410
                                + "] Return: " + rc);
411

    
412
                return rc;
413
        }
414

    
415
        /**
416
         * This method to change admin users state to ACTIVE status.
417
         * 
418
         * @param rootAlias
419
         * @param rootPassword
420
         * @param adminUserAlias
421
         * @return ERR_code defined in the Constants.<br/>
422
         *         ERR_SUCCESS<br/>
423
         *         ERR_SYSTEM_NOT_READY<br/>
424
         *         ERR_USERALIAS_NOT_FOUND <br/>
425
         *         ERR_INVALID_STATE - root not active or temporary suspended.<br/>
426
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
427
         *         ERR_EXCEED_MAX_TRIES<br/>
428
         *         ERR_INVALID_CREDENTIAL<br/>
429
         *         ERR_USERALIAS_NOT_FOUND<br/>
430
         *         ERR_UNKNOWN<br/>
431
         */
432
        public int AD_ActivateUser(String rootAlias, String rootPassword,
433
                        String adminUserAlias)
434
        {
435
                int rc = verifyStaticPasswordService.verifyStaticPassword(
436
                                rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT);
437

    
438
                if (rc != Constants.ERR_SUCCESS)
439
                {
440
                        return rc;
441
                }
442

    
443
                rc = activateUserService.activateUser(adminUserAlias);
444

    
445
                logger.info("AD_ActivateUser - admin user alias: [" + adminUserAlias
446
                                + "] Return: " + rc);
447

    
448
                return rc;
449
        }
450

    
451
        /**
452
         * This method is to check whether the user alias exist in the system.
453
         * 
454
         * @param userAlias
455
         * @return ERR_code defined in the Constants.<br/>
456
         *         ERR_SUCCESS 0 - found<br/>
457
         *         ERR_USERALIAS_NOT_FOUND 6<br/>
458
         *         ERR_SYSTEM_NOT_READY 98<br/>
459
         */
460
        public int UA_IsUserExist(String userAlias)
461
        {
462
                return queryInfoService.checkUserExistence(userAlias);
463
        }
464

    
465
        /**
466
         * This method is to get user type. Valid return is [0-root user | 1-admin user | 2-Ordinary User]
467
         * 
468
         * @param userAlias
469
         * @return <br/>
470
         *         UTYPE_STATE_ROOT = 0<br/>
471
         *         UTYPE_STATE_ADMIN = 1<br/>
472
         *         UTYPE_STATE_USER = 2<br/>
473
         *         ERR_USERALIAS_NOT_FOUND = 6<br/>
474
         *         ERR_SYSTEM_NOT_READY = 98<br/>
475
         */
476

    
477
        public int UA_GetUserType(String userAlias)
478
        {
479
                return queryInfoService.getUserType(userAlias);
480
        }
481

    
482
        /**
483
         * This method is to get attributes associated to user. Return type is HashMap<String,String>
484
         * The object keys is as below:<br/>
485
         * RC - Return Code [always present]<br/>
486
         * RT - Return Code in Text [always present]<br/>
487
         * <br/>
488
         * The following data present only with the return is ERR_SUCCESS<br/>
489
         * Type - User Type [0-Root User] [1-Admin User] [2-Ordinary User][9-SysControl]<br/>
490
         * State - User State [0-Active] [1-Temporary Locked] [2-Locked] [3-Inactive] [4-Deleted]<br/>
491
         * Description - User Description<br/>
492
         * UseCount - Number of time the record being access<br/>
493
         * DateCreated - Created date<br/>
494
         * DateLastUsed - Last access of the record<br/>
495
         * DateLastActivated - Last activation of the record<br/>
496
         * DateLastLocked - Last date the user being locked<br/>
497
         * DateLockedFrom - last date the user being locked from<br/>
498
         * DateLockedTo - last date the user being locked to<br/>
499
         * 
500
         * @param userAlias
501
         * @return HashMap
502
         */
503
        public HashMap<String, String> UA_GetUserData(String userAlias)
504
        {
505
                return queryInfoService.getUserData(userAlias);
506
        }
507

    
508
        /**
509
         * This method is to get attributes associated to password. Return type is HashMap<String,String>
510
         * The object keys is as below:<br/>
511
         * RC - Return Code [always present]<br/>
512
         * RT - Return Code in Text [always present]<br/>
513
         * <br/>
514
         * The following data present only with the return is ERR_SUCCESS<br/>
515
         * State - Password State [0-Enable] [1-Disable] [2-OneTime Use]<br/>
516
         * ExpiryStatus - Expiry Status [0-Will Expired][1-Never Expired]
517
         * UseCount - Number of time the record being access<br/>
518
         * ErrorCount - Number of time the password verified error<br/>
519
         * DateCreated - Created date<br/>
520
         * DateFirstUsed - First access of the password<br/>
521
         * DateLastUsed - Last access of the password<br/>
522
         * DatePasswdExpired - Expiry date of the password<br/>
523
         * 
524
         * @param userAlias
525
         * @return HashMap
526
         */
527
        public HashMap<String, String> QueryPassword(String userAlias)
528
        {
529
                return queryInfoService.queryPassword(userAlias);
530
        }
531

    
532
        /**
533
         * This method is to get attributes associated to TAC. 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 - User State [0-Enable] [1-Disable]<br/>
540
         * UseCount - Number of time the record being access<br/>
541
         * ErrorCount - Number of time the TAC verified error<br/>
542
         * DateCreated - TAC Created date<br/>
543
         * DateFirstUsed - First access of the TAC<br/>
544
         * DateLastUsed - Last access of the TAC<br/>
545
         * 
546
         * @param userAlias
547
         * @param appId
548
         *            TODO
549
         * @return HashMap
550
         */
551
        public HashMap<String, String> QueryTAC(String userAlias, int appId)
552
        {
553
                return queryInfoService.queryTAC(userAlias, appId);
554
        }
555

    
556
        /**
557
         * This method is to change online user state to LOCKED status.
558
         * 
559
         * @param adminUserAlias
560
         * @param adminUserPassword
561
         * @param userAlias
562
         * @return ERR_code defined in the Constants.<br/>
563
         *         ERR_SUCCESS<br/>
564
         *         ERR_SYSTEM_NOT_READY<br/>
565
         *         ERR_USERALIAS_NOT_FOUND <br/>
566
         *         ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
567
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
568
         *         ERR_EXCEED_MAX_TRIES<br/>
569
         *         ERR_INVALID_CREDENTIAL<br/>
570
         *         ERR_UNKNOWN<br/>
571
         */
572
        public int UA_LockUser(String adminUserAlias, String adminUserPassword,
573
                        String userAlias)
574
        {
575
                int rc = verifyStaticPasswordService.verifyStaticPassword(
576
                                adminUserAlias, adminUserPassword, true,
577
                                Constants.UTYPE_STATE_ADMIN);
578

    
579
                if (rc != Constants.ERR_SUCCESS)
580
                {
581
                        return rc;
582
                }
583

    
584
                rc = lockUserService.lockUser(userAlias);
585

    
586
                logger.info("UA_LockUser - user alias: [" + userAlias + "] Return:"
587
                                + rc);
588

    
589
                return rc;
590
        }
591

    
592
        /**
593
         * This method is to change admin user state to LOCKED status.
594
         * 
595
         * @param rootAlias
596
         * @param rootPassword
597
         * @param adminUserAlias
598
         * @return ERR_code defined in the Constants.<br/>
599
         *         ERR_SUCCESS<br/>
600
         *         ERR_SYSTEM_NOT_READY<br/>
601
         *         ERR_USERALIAS_NOT_FOUND <br/>
602
         *         ERR_INVALID_STATE - root not active or temporary suspended.<br/>
603
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
604
         *         ERR_EXCEED_MAX_TRIES<br/>
605
         *         ERR_INVALID_CREDENTIAL<br/>
606
         *         ERR_UNKNOWN<br/>
607
         */
608
        public int AD_LockUser(String rootAlias, String rootPassword,
609
                        String adminUserAlias)
610
        {
611
                int rc = verifyStaticPasswordService.verifyStaticPassword(
612
                                rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT);
613

    
614
                if (rc != Constants.ERR_SUCCESS)
615
                {
616
                        return rc;
617
                }
618

    
619
                rc = lockUserService.lockUser(adminUserAlias);
620

    
621
                logger.info("AD_LockUser - admin user alias: [" + adminUserAlias
622
                                + "] Return: " + rc);
623

    
624
                return rc;
625
        }
626

    
627
        /**
628
         * This method is to suspend online user from when for how many Minutes
629
         * 
630
         * @param adminUserAlias
631
         * @param adminUserPassword
632
         * @param userAlias
633
         * @param fromDate
634
         *            - from when
635
         * @param nMinutes
636
         *            - Suspend for how many minutes
637
         * @return ERR_code defined in the Constants.<br/>
638
         *         ERR_SUCCESS<br/>
639
         *         ERR_SYSTEM_NOT_READY<br/>
640
         *         ERR_USERALIAS_NOT_FOUND <br/>
641
         *         ERR_INVALID_STATE - admin not active or temporary suspended.<br/>
642
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
643
         *         ERR_EXCEED_MAX_TRIES<br/>
644
         *         ERR_INVALID_CREDENTIAL<br/>
645
         *         ERR_UNKNOWN<br/>
646
         */
647
        public int UA_SuspendUser(String adminUserAlias, String adminUserPassword,
648
                        String userAlias, String strFromDate, int nMinutes)
649
        {
650
                Date fromDate = StringToDate(strFromDate);
651
                int rc = verifyStaticPasswordService.verifyStaticPassword(
652
                                adminUserAlias, adminUserPassword, true,
653
                                Constants.UTYPE_STATE_ADMIN);
654

    
655
                if (rc != Constants.ERR_SUCCESS)
656
                {
657
                        return rc;
658
                }
659

    
660
                rc = lockUserService.lockUser(userAlias,
661
                                Constants.UID_STATE_TMP_LOCKED, fromDate, nMinutes);
662

    
663
                logger.info("UA_SuspendUser - admin user alias: [" + adminUserAlias
664
                                + "] user alias: [" + userAlias + "] From: [" + fromDate
665
                                + " for " + nMinutes + "min] Return: " + rc);
666

    
667
                return rc;
668
        }
669

    
670
        /**
671
         * This method is to suspend admin user from when for how many Minutes
672
         * 
673
         * @param rootAlias
674
         * @param rootPassword
675
         * @param adminUserAlias
676
         * @param fromDate
677
         *            - from when
678
         * @param nMinutes
679
         *            - Suspend for how many Minutes
680
         * @return ERR_code defined in the Constants.<br/>
681
         *         ERR_SUCCESS<br/>
682
         *         ERR_SYSTEM_NOT_READY<br/>
683
         *         ERR_USERALIAS_NOT_FOUND <br/>
684
         *         ERR_INVALID_STATE - root not active or temporary suspended.<br/>
685
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
686
         *         ERR_EXCEED_MAX_TRIES<br/>
687
         *         ERR_INVALID_CREDENTIAL<br/>
688
         *         ERR_UNKNOWN<br/>
689
         */
690
        public int AD_SuspendUser(String rootAlias, String rootPassword,
691
                        String adminUserAlias, String strFromDate, int nMinutes)
692
        {
693
                Date fromDate = StringToDate(strFromDate);
694
                int rc = verifyStaticPasswordService.verifyStaticPassword(
695
                                rootAlias, rootPassword, true, Constants.UTYPE_STATE_ROOT);
696

    
697
                if (rc != Constants.ERR_SUCCESS)
698
                {
699
                        return rc;
700
                }
701

    
702
                rc = lockUserService.lockUser(adminUserAlias,
703
                                Constants.UID_STATE_TMP_LOCKED, fromDate, nMinutes);
704

    
705
                logger.info("AD_SuspendUser - admin user alias: [" + adminUserAlias
706
                                + "] Return: " + rc);
707

    
708
                return rc;
709
        }
710

    
711
        /**
712
         * This method is to concate existing user alias to allow re use user after deleted.
713
         * 
714
         * @param rootAlias
715
         * @param rootPassword
716
         * @param adminUserAlias
717
         * @param fromDate
718
         *            - from when
719
         * @param nMinutes
720
         *            - Suspend for how many Minutes
721
         * @return ERR_code defined in the Constants.<br/>
722
         *         ERR_SUCCESS<br/>
723
         *         ERR_SYSTEM_NOT_READY<br/>
724
         *         ERR_USERALIAS_NOT_FOUND <br/>
725
         *         ERR_INVALID_STATE - root not active or temporary suspended.<br/>
726
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
727
         *         ERR_EXCEED_MAX_TRIES<br/>
728
         *         ERR_INVALID_CREDENTIAL<br/>
729
         *         ERR_UNKNOWN<br/>
730
         */
731
        public int UA_DeleteUser(String adminUserAlias, String adminUserPassword, String userAlias) {
732

    
733
                int rc = verifyStaticPasswordService.verifyStaticPassword(
734
                                adminUserAlias, adminUserPassword, true,
735
                                Constants.UTYPE_STATE_ADMIN);
736

    
737
                if (rc != Constants.ERR_SUCCESS) {
738
                        return rc;
739
                }
740
                rc = deleteUserService.deleteUser(userAlias, null);
741
                logger.info("UA_DeleteUser - admin user alias: [" + userAlias + "] Return: " + rc);
742
                return rc;
743
        }
744

    
745
        /**
746
         * Because of the ability to choose the target app,
747
         * this method is meant for USS only.
748
         * 
749
         * @see #deleteUserWithTheProfile(String, String, String, Session)
750
         */
751
        public int deleteUserWithTheProfile(
752
                        String adminUsername, String adminPassword,
753
                        String username, int targetAppId, Session txSession)
754
                        throws UPassException {
755

    
756
                int rc;
757
                try {
758
                        AccessCheckResult checkResult = checkAppAccess(adminUsername, adminPassword, txSession);
759

    
760
                        if (!checkResult.hasUPassAdminAccess())
761
                                rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
762

    
763
                        else {
764
                                boolean revoked = appAccessMgtService.revokeAppAccessForUser(username, targetAppId, txSession);
765
                                rc = revoked ?
766
                                                deleteUserService.deleteUser(username, targetAppId, txSession)
767
                                                : MinimalConstants.ERR_SYSTEM_NOT_READY;
768
                        }
769
                } catch (MultipleAppAccessesFound e) {
770
                        rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
771
                        e.printStackTrace();
772
                }
773
                logger.info("deleteUser - user alias: [" + username + "] Return: " + rc);
774
                return rc;
775
        }
776

    
777
        /**
778
         * This methods identifies the target app using <code>appAccessId</code>,
779
         * hence meant for {@link ClientApp}s
780
         * 
781
         * @see #deleteUserWithTheProfile(String, String, String, int, Session)
782
         */
783
        public int deleteUserWithTheProfile(
784
                        String appAccessId, String hashedSecretKey,
785
                        String username, Session txSession)
786
                        throws UPassException {
787

    
788
                int rc;
789
                try {
790
                        AccessCheckResult checkResult = checkAppAccess(appAccessId, hashedSecretKey, txSession);
791

    
792
                        final Integer targetAppId = checkResult.invokerAppId;
793
                        if (targetAppId == null) {
794
                                rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
795

    
796
                        } else {
797
                                boolean revoked = appAccessMgtService.revokeAppAccessForUser(username, targetAppId, txSession);
798
                                rc = revoked ?
799
                                                deleteUserService.deleteUser(username, targetAppId, txSession)
800
                                                : MinimalConstants.ERR_SYSTEM_NOT_READY;
801
                        }
802
                } catch (MultipleAppAccessesFound e) {
803
                        rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
804
                        e.printStackTrace();
805
                }
806
                logger.info("deleteUser - user alias: [" + username + "] Return: " + rc);
807
                return rc;
808
        }
809

    
810
        // ///////////////////////////////////////////////////////////////////////////////
811
        // token area
812
        // ///////////////////////////////////////////////////////////////////////////////
813

    
814
        /**
815
         * This method is to verify token password
816
         * 
817
         * @param userAlias
818
         * @param inPassword
819
         * @return ERR_code defined in the Constants<br/>
820
         *         ERR_SUCCESS<br/>
821
         *         ERR_SYSTEM_NOT_READY<br/>
822
         *         ERR_USERALIAS_NOT_FOUND<br/>
823
         *         ERR_INVALID_STATE<br/>
824
         *         ERR_EXCEED_MAX_TRIES<br/>
825
         *         ERR_INVALID_CREDENTIAL<br/>
826
         *         ERR_PASSWD_EXPIRED<br/>
827
         *         ERR_REUSED_PASSWD<br/>
828
         */
829
        public int VerifyToken(String userAlias, String inPassword)
830
        {
831
                int rc = verifyTokenService.verifyToken(userAlias, inPassword);
832

    
833
                logger.info("VerifyToken - user alias: [" + userAlias + "] Return: "
834
                                + rc);
835

    
836
                return rc;
837
        }
838

    
839
        /**
840
         * This method is to reset user token <br/>
841
         * 
842
         * @param adminUserAlias
843
         * @param adminUserPassword
844
         * @param userAlias
845
         * @return ERR_code defined in the Constants<br/>
846
         *         ERR_SUCCESS<br/>
847
         *         ERR_SYSTEM_NOT_READY<br/>
848
         *         ERR_USERALIAS_NOT_FOUND<br/>
849
         *         ERR_INVALID_STATE<br/>
850
         *         ERR_EXCEED_MAX_TRIES<br/>
851
         *         ERR_INVALID_CREDENTIAL<br/>
852
         */
853
        public int ResetToken(String adminUserAlias, String adminUserPassword,
854
                        String userAlias)
855
        {
856
                int rc = verifyStaticPasswordService.verifyStaticPassword(
857
                                adminUserAlias, adminUserPassword, true,
858
                                Constants.UTYPE_STATE_ADMIN);
859

    
860
                if (rc != Constants.ERR_SUCCESS)
861
                {
862
                        return rc;
863
                }
864

    
865
                rc = resetTokenService.resetToken(userAlias);
866
                logger.info("ResetToken - user alias: [" + userAlias + "] Return: "
867
                                + rc);
868
                return rc;
869
        }
870

    
871
        /**
872
         * This method is to query token information, Return type is HashMap<String,String>
873
         * RC - Return Code [always present]<br/>
874
         * RT - Return Code in Text [always present]<br/>
875
         * <br/>
876
         * The following data present only with the return is ERR_SUCCESS<br/>
877
         * SerailNo - The serial number of token<br/>
878
         * State - Token State, [0-UNASSIGNED], [1-ASSIGNED], [2-DISABLE], [3-LOCKED], [4-DELETED]<br/>
879
         * UseCount - number of time of password authentication <br/>
880
         * ErrorCount - number of time error encountered of password authentication<br/>
881
         * DateAssigned - date of assignment to user<br/>
882
         * DateFirstUsed - date of 1st time use<br/>
883
         * DateLastUsed - date of last time used<br/>
884
         * BatchID - the ID used for loading the token into data store<br/>
885
         * <br/>
886
         * 
887
         * Data retrieved from token BLOB<br/>
888
         * TOKEN_MODEL<br/>
889
         * USE_COUNT<br/>
890
         * ERROR_COUNT<br/>
891
         * LAST_TIME_USED<br/>
892
         * CODE_WORD<br/>
893
         * TRIPLE_DES<br/>
894
         * MAX_INPUT_FIELDS<br/>
895
         * RESPONSE_LENGTH<br/>
896
         * RESPONSE_TYPE<br/>
897
         * RESPONSE_CHECKSUM<br/>
898
         * TIME_STEP_USED<br/>
899
         * 
900
         * @param userAlias
901
         * @return HashMap
902
         */
903
        public HashMap<String, String> QueryToken(String userAlias)
904
        {
905
                return queryInfoService.queryToken(userAlias);
906
        }
907

    
908
        public int DeleteTokenFromStore(String adminUserAlias,
909
                        String adminUserPassword, String serialNumber)
910
        {
911
                int rc = verifyStaticPasswordService.verifyStaticPassword(
912
                                adminUserAlias, adminUserPassword, true,
913
                                Constants.UTYPE_STATE_ADMIN);
914

    
915
                if (rc != Constants.ERR_SUCCESS)
916
                {
917
                        return rc;
918
                }
919

    
920
                rc = deleteTokenService.deleteTokenFromStore(serialNumber);
921
                logger.info("DeleteTokenFromStore - serial number: [" + serialNumber
922
                                + "] Return: " + rc);
923
                return rc;
924
        }
925

    
926
        /**
927
         * This method is to assign token to user<br/>
928
         * 
929
         * @param serialNumber
930
         * @param userAlias
931
         * @return ERR_code defined in the Constants<br/>
932
         *         ERR_SUCCESS<br/>
933
         *         ERR_SYSTEM_NOT_READY<br/>
934
         *         ERR_USERALIAS_NOT_FOUND<br/>
935
         *         ERR_INVALID_STATE<br/>
936
         */
937
        public int AssignTokenToUser(String adminUserAlias,
938
                        String adminUserPassword, String serialNumber, String userAlias)
939
        {
940
                int rc = verifyStaticPasswordService.verifyStaticPassword(
941
                                adminUserAlias, adminUserPassword, true,
942
                                Constants.UTYPE_STATE_ADMIN);
943

    
944
                if (rc != Constants.ERR_SUCCESS)
945
                {
946
                        return rc;
947
                }
948

    
949
                rc = assignTokenService.assignToken(serialNumber, userAlias,
950
                                Constants.TKN_STATE_ASSIGNED);
951

    
952
                logger.info("AssignTokenToUser - serial number: [" + serialNumber
953
                                + "] user alias: [" + userAlias + "] Return: " + rc);
954

    
955
                return rc;
956
        }
957

    
958
        /**
959
         * This method is to return Token to store; Reset the Token.<br/>
960
         * The token is ready to re-assign to other user.<br/>
961
         * 
962
         * @param adminUserAlias
963
         * @param adminUserPassword
964
         * @param userAlias
965
         * @return ERR_code defined in the Constants<br/>
966
         *         ERR_SUCCESS<br/>
967
         *         ERR_SYSTEM_NOT_READY<br/>
968
         *         ERR_USERALIAS_NOT_FOUND<br/>
969
         *         ERR_INVALID_STATE<br/>
970
         */
971
        public int UnassignTokenFromUser(String adminUserAlias,
972
                        String adminUserPassword, String userAlias)
973
        {
974
                int rc = verifyStaticPasswordService.verifyStaticPassword(
975
                                adminUserAlias, adminUserPassword, true,
976
                                Constants.UTYPE_STATE_ADMIN);
977

    
978
                if (rc != Constants.ERR_SUCCESS)
979
                {
980
                        return rc;
981
                }
982

    
983
                rc = assignTokenService.assignToken(null, userAlias,
984
                                Constants.TKN_STATE_UNASSIGNED);
985

    
986
                logger.info("UnassignTokenFromUser - user alias: [" + userAlias
987
                                + "] Return: " + rc);
988

    
989
                return rc;
990
        }
991

    
992
        /**
993
         * This method is to disable the token<br/>
994
         * 
995
         * @param adminUserAlias
996
         * @param adminUserPassword
997
         * @param userAlias
998
         * @return ERR_code defined in the Constants<br/>
999
         *         ERR_SUCCESS<br/>
1000
         *         ERR_SYSTEM_NOT_READY<br/>
1001
         *         ERR_USERALIAS_NOT_FOUND<br/>
1002
         *         ERR_INVALID_STATE<br/>
1003
         */
1004
        public int DisableToken(String adminUserAlias, String adminUserPassword,
1005
                        String userAlias)
1006
        {
1007
                int rc = verifyStaticPasswordService.verifyStaticPassword(
1008
                                adminUserAlias, adminUserPassword, true,
1009
                                Constants.UTYPE_STATE_ADMIN);
1010

    
1011
                if (rc != Constants.ERR_SUCCESS)
1012
                {
1013
                        return rc;
1014
                }
1015

    
1016
                rc = disableTokenService.disableToken(userAlias, true);
1017

    
1018
                logger.info("DisableToken - user alias: [" + userAlias + "] Return: "
1019
                                + rc);
1020

    
1021
                return rc;
1022
        }
1023

    
1024
        /**
1025
         * This method is to enable to token<br/>
1026
         * 
1027
         * @param adminUserAlias
1028
         * @param adminUserPassword
1029
         * @param userAlias
1030
         * @return ERR_code defined in the Constants<br/>
1031
         *         ERR_SUCCESS<br/>
1032
         *         ERR_SYSTEM_NOT_READY<br/>
1033
         *         ERR_USERALIAS_NOT_FOUND<br/>
1034
         *         ERR_INVALID_STATE<br/>
1035
         */
1036
        public int EnableToken(String adminUserAlias, String adminUserPassword,
1037
                        String userAlias)
1038
        {
1039
                int rc = verifyStaticPasswordService.verifyStaticPassword(
1040
                                adminUserAlias, adminUserPassword, true,
1041
                                Constants.UTYPE_STATE_ADMIN);
1042

    
1043
                if (rc != Constants.ERR_SUCCESS)
1044
                {
1045
                        return rc;
1046
                }
1047

    
1048
                rc = disableTokenService.disableToken(userAlias, false);
1049

    
1050
                logger.info("EnableToken - user alias: [" + userAlias + "] Return: "
1051
                                + rc);
1052

    
1053
                return rc;
1054
        }
1055

    
1056
        /**
1057
         * This method is to load token from DPX or PSKC file to UPass data store
1058
         * Refer to System Console for additional information.
1059
         * 
1060
         * @param adminUserAlias
1061
         * @param adminUserPassword
1062
         * @param requiredField1
1063
         *            = fileName
1064
         * @param requiredField2
1065
         *            = importKey/ passsphrase / fileName
1066
         * @param requiredField3
1067
         *            = batchId/ null
1068
         * @return rc (response code)
1069
         * @throws Exception
1070
         */
1071
        public int LoadToken(String adminUserAlias, String adminUserPassword,
1072
                        String requiredField1, String requiredField2, String requiredField3) throws Exception
1073
        {
1074
                int rc = Constants.ERR_SYSTEM_NOT_READY;
1075

    
1076
                rc = LoadTokenWithStats(adminUserAlias, adminUserPassword,
1077
                                requiredField1, requiredField2, requiredField3).getResponseCode();
1078

    
1079
                return rc;
1080
        }
1081

    
1082
        /**
1083
         * This method override the existing LoadToken to generate load token statistic
1084
         * 
1085
         * @param adminUserAlias
1086
         * @param adminUserPassword
1087
         * @param requiredField1
1088
         *            = fileName
1089
         * @param requiredField2
1090
         *            = importKey/ passsphrase / fileName
1091
         * @param requiredField3
1092
         *            = batchId/ null
1093
         * @return LoadTokenBean
1094
         * @throws Exception
1095
         */
1096
        public LoadTokenBean LoadTokenWithStats(String adminUserAlias, String adminUserPassword,
1097
                        String requiredField1, String requiredField2, String requiredField3) throws Exception {
1098
                LoadTokenBean loadTokenBean = new LoadTokenBean();
1099

    
1100
                // verify supervisor password
1101
                int rc = verifyStaticPasswordService.verifyStaticPassword(
1102
                                adminUserAlias, adminUserPassword, true,
1103
                                Constants.UTYPE_STATE_ADMIN);
1104

    
1105
                rc = 0;
1106

    
1107
                if (rc != Constants.ERR_SUCCESS) {
1108
                        loadTokenBean.setResponseCode(rc);
1109

    
1110
                } else {
1111
                        loadTokenBean = loadTokenService.loadToken(requiredField1, requiredField2, requiredField3,
1112
                                        UPassFactory.getTokenMode());
1113
                }
1114

    
1115
                return loadTokenBean;
1116
        }
1117

    
1118
        /**
1119
         * This method override the existing LoadToken to generate load token statistic
1120
         * 
1121
         * @param adminUserAlias
1122
         * @param adminUserPassword
1123
         * @param requiredField1
1124
         *            = userAlias
1125
         * @param requiredField2
1126
         *            = Otp 1
1127
         * @param requiredField3
1128
         *            = Otp 2
1129
         * @return LoadTokenBean
1130
         * @throws Exception
1131
         */
1132
        public int SynchronizeToken(String adminUserAlias, String adminUserPassword,
1133
                        String userAlias, String otp1, String otp2) {
1134

    
1135
                // verify supervisor password
1136
                int rc = verifyStaticPasswordService.verifyStaticPassword(
1137
                                adminUserAlias, adminUserPassword, true,
1138
                                Constants.UTYPE_STATE_ADMIN);
1139

    
1140
                if (rc != Constants.ERR_SUCCESS)
1141
                {
1142
                        return rc;
1143
                }
1144

    
1145
                rc = synchronizeTokenService.syncToken(userAlias, otp1, otp2);
1146

    
1147
                logger.info("SyncToken - useralias: [" + userAlias
1148
                                + "] first OTP: [" + otp1 + "] Second OTP: [" + otp2 + "] Return: " + rc);
1149
                return rc;
1150

    
1151
        }
1152

    
1153
        /**
1154
         * This method is to get Specified token vendor name in Token Controller
1155
         * 
1156
         * @return token Vendor name
1157
         */
1158
        public String getTokenVendor() {
1159

    
1160
                return queryInfoService.getTokenVendor();
1161

    
1162
        }
1163

    
1164
        // ///////////////////////////////////////////////////////////////////////////////
1165
        // token area end
1166
        // ///////////////////////////////////////////////////////////////////////////////
1167

    
1168
        private Date StringToDate(String dateString)
1169
        {
1170
                String DATE_FORMAT = "yyyyMMddHHmmss";
1171
                SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
1172
                Date parsedDate = new Date();
1173

    
1174
                try
1175
                {
1176
                        parsedDate = format.parse(dateString);
1177
                } catch (ParseException pe)
1178
                {
1179
                        logger.info("ERROR: Cannot parse date in String " + dateString);
1180
                }
1181

    
1182
                return parsedDate;
1183
        }
1184

    
1185
        // ///////////////////////////////////////////////////////////////////////////////
1186
        // Security code area
1187
        // ///////////////////////////////////////////////////////////////////////////////
1188

    
1189
        public String GenerateSecurityCode(String identifier)
1190
        {
1191
                String sRc = generateSecurityCodeService
1192
                                .generateSecurityCode(identifier);
1193

    
1194
                logger.info(identifier + " Return=" + sRc.substring(2));
1195

    
1196
                return sRc;
1197
        }
1198

    
1199
        public int VerifySecurityCode(String identifier, String securityCode)
1200
        {
1201
                int rc = verifySecurityCodeService.verifySecurityCode(
1202
                                identifier, securityCode);
1203

    
1204
                logger.info("VerifySecurityCode - identifier: [" + identifier
1205
                                + "] Return: " + rc);
1206

    
1207
                return rc;
1208
        }
1209

    
1210
        public int VerifyPasswordComplexity(String password, int applicationId) {
1211
                int rc = verifyPasswordComplexityService.verifyPasswordComplexity(password, applicationId);
1212

    
1213
                logger.info("VerifyPasswordComplexity: - password[" + password
1214
                                + "] Return: " + rc);
1215

    
1216
                return rc;
1217
        }
1218

    
1219
        /**
1220
         * This method to add admin users to the system
1221
         * 
1222
         * @param rootAlias
1223
         * @param rootPassword
1224
         * @param adminUserAlias
1225
         * @param adminDesc
1226
         * @param adminUserPassword
1227
         * @return ERR_code defined in the MinimalConstants<br/>
1228
         *         ERR_SUCCESS<br/>
1229
         *         ERR_SYSTEM_NOT_READY<br/>
1230
         *         ERR_USERALIAS_NOT_FOUND <br/>
1231
         *         ERR_INVALID_STATE - root not active or temporary suspended.<br/>
1232
         *         ERR_APP_SERV_NOT_PERMITTED - for operation not allowed for the user type.<br/>
1233
         *         ERR_EXCEED_MAX_TRIES<br/>
1234
         *         ERR_INVALID_CREDENTIAL<br/>
1235
         *         ERR_INVALID_INPUT - internal error.<br/>
1236
         *         ERR_ALREADY_EXIST<br/>
1237
         *         ERR_INVALID_USERALIAS - User alias does not match with defined pattern <br/>
1238
         *         ERR_PASSWORD_SAMEAS_USERALIAS - password is same is user name error <br/>
1239
         */
1240
        public int AD_AddUser(
1241
                        String rootAlias, String rootPassword,
1242
                        String adminUserAlias, String adminDesc, String adminUserPassword) {
1243

    
1244
                // check if password is similar to user alias
1245
                if (rootAlias.equalsIgnoreCase(rootPassword)) {
1246
                        return MinimalConstants.ERR_PASSWORD_SAMEAS_USERALIAS;
1247
                }
1248
                int rc = verifyStaticPasswordService.verifyStaticPassword(
1249
                                rootAlias, rootPassword, true, MinimalConstants.UTYPE_STATE_ROOT);
1250

    
1251
                if (rc != MinimalConstants.ERR_SUCCESS) {
1252
                        return rc;
1253
                }
1254
                rc = createUserService.addUser(adminUserAlias,
1255
                                MinimalConstants.UTYPE_STATE_ADMIN, adminDesc, adminUserPassword,
1256
                                MinimalConstants.UID_STATE_ACTIVE, MinimalConstants.SYSTEM_ID);
1257

    
1258
                logger.info("AD_AddUser - admin user alias: [" + adminUserAlias + "] Return: " + rc);
1259

    
1260
                return rc;
1261
        }
1262
}