Statistics
| Branch: | Revision:

m2u-upass-core / src / my / com / upass / services / ChangeStaticPasswordService.java @ 0:02300db8682b

History | View | Annotate | Download (2.42 KB)

1
/**
2
 * Copyright (c) 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

    
12
package my.com.upass.services;
13

    
14
import my.com.upass.Constants;
15
import my.com.upass.UPassControllerV2;
16
import my.com.upass.dao.DAOFactoryProvider;
17
import my.com.upass.dao.UserDAO;
18
import my.com.upass.factory.UPassFactory;
19
import my.com.upass.pojo.UserBean;
20
import my.com.upass.spassword.PasswordController;
21

    
22
/**
23
 * PROGRAMMER: Danniell
24
 * CHANGE-NO:
25
 * TASK-NO:
26
 * DATE CREATED: Dec 28, 2011
27
 * TAG AS:
28
 * REASON(S):
29
 * MODIFICATION:
30
 */
31

    
32
/**
33
 * <Class description>
34
 */
35
public class ChangeStaticPasswordService
36
{
37
        private UPassControllerV2 upc;
38
        
39
        public ChangeStaticPasswordService(UPassControllerV2 upc)
40
        {
41
                this.upc = upc;
42
        }
43
        
44
        public int changeStaticPassword(String userAlias, String newPassword, String oldPassword, boolean checkChangeInterval) 
45
        {
46
                int rc = Constants.ERR_SYSTEM_NOT_READY;
47
                
48
                try
49
                {
50
                        UserDAO userDao = DAOFactoryProvider.getDAOFactory ().getUserDAO ();
51
                        UserBean userBean = userDao.getUserFromStore(userAlias);
52
                        
53
                        if (userBean == null) 
54
                        {
55
                                return Constants.ERR_USERALIAS_NOT_FOUND;
56
                        }
57
                        
58
                        userBean.getPdateCreated();
59
                        
60
                        // verify user
61
                        PasswordController pc = UPassFactory.getPasswordController(userBean, upc.getConfigurationsMap ());
62
                        
63
                        if (checkChangeInterval == true)
64
                        {
65
                                rc = pc.checkRegeneratePassword();
66
                                if (rc == Constants.ERR_PASSWD_CHANGE_INTERVAL ) 
67
                                {
68
                                        return Constants.ERR_PASSWD_CHANGE_INTERVAL;
69
                                }
70
                        }
71
                        
72
                        rc = pc.VerifyPassword(oldPassword);
73
                        
74
                        if (rc == Constants.ERR_SUCCESS || 
75
                                        rc == Constants.ERR_PASSWD_EXPIRED || 
76
                                        rc == Constants.ERR_PASSWD_EXPIRED_NOTIFICATION) 
77
                        {
78
                                rc = pc.GeneratePassword(newPassword, true);
79
                        }
80
                        
81
                        userBean = (UserBean) pc.getUpdatedObject();
82
                        
83
                        // update database
84
                        boolean lrc = userDao.updateUserToStore(userBean);
85
                        
86
                        if (!lrc) 
87
                        {
88
                                rc = Constants.ERR_SYSTEM_NOT_READY;
89
                        }
90
                }
91
                catch(Exception e)
92
                {
93
                        e.printStackTrace ();
94
                }
95
                
96
                return rc;
97
        }
98
}