Revision 30:e5f8d6632d21

View differences:

src/main/java/my/com/upass/MinimalUPassControllerV2.java
13 13
import my.com.upass.pojo.MinimalUserBean;
14 14
import my.com.upass.services.AppAccessMgtService;
15 15
import my.com.upass.services.AppAccessMgtService.MultipleAppAccessesFound;
16
import my.com.upass.services.ChangeStaticPasswordService;
16 17
import my.com.upass.services.CreateUserService;
17 18
import my.com.upass.services.ModifyUserService;
18 19
import my.com.upass.services.VerifyStaticPasswordService;
......
29 30
	protected CreateUserService createUserService = new CreateUserService(this);
30 31
	protected ModifyUserService modifyUserService = new ModifyUserService(this);
31 32
	protected AppAccessMgtService appAccessMgtService = new AppAccessMgtService();
33
	protected ChangeStaticPasswordService changeStaticPasswordService = new ChangeStaticPasswordService(this);
34

  
35
	public MinimalUPassControllerV2() {
36
		initializeConfigurations();
37
	}
32 38

  
33 39
	protected void initializeConfigurations() {
34 40
		try
......
197 203
		return rc;
198 204
	}
199 205

  
206
	public int verifyStaticPasswordPerApp(
207
			String appAccessId, String hashedSecretKey,
208
			String username, String hashedPassword) {
209

  
210
		int rc = verifyStaticPasswordService.verifyStaticPassword(
211
				appAccessId, hashedSecretKey, true,
212
				MinimalConstants.UTYPE_STATE_USER);
213

  
214
		if (rc != MinimalConstants.ERR_SUCCESS)
215
			return rc;
216

  
217
		Integer appId = null;
218
		try {
219
			appId = appAccessMgtService.getAppIdForAdmin(appAccessId, null);
220

  
221
			List appIdsForUser = appAccessMgtService.listAppIdsForUser(username, null);
222
			rc = appIdsForUser.contains(appId) ?
223
					MinimalConstants.ERR_SUCCESS
224
					: MinimalConstants.ERR_USERALIAS_NOT_FOUND;
225

  
226
			if (rc != MinimalConstants.ERR_SUCCESS)
227
				return rc;
228

  
229
			rc = verifyStaticPasswordService.verifyStaticPassword(
230
					username, hashedPassword, false, 0);
231

  
232
		} catch (MultipleAppAccessesFound e) {
233
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
234
			e.printStackTrace();
235
		}
236
		logger.info("verifyStaticPassword - user alias: [" + username + "] Return: " + rc);
237
		return rc;
238
	}
239

  
200 240
	/**
201 241
	 * This method to Modify online users to the system
202 242
	 * 
......
248 288
		return rc;
249 289
	}
250 290

  
251
	public int updateProfileShallowly(String appAccessId, String hashedSecretKey, UserProfile profile, Session txSession) {
291
	public int updateProfileShallowly(
292
			String appAccessId, String hashedSecretKey,
293
			UserProfile profile, Session txSession) {
252 294

  
253 295
		MinimalUserBean user = profile.getMinUser();
254 296
		final String userAlias = user.getUserAlias();
......
286 328
		logger.info("updateProfileShallowly - user alias: [" + userAlias + "] Return: " + rc);
287 329
		return rc;
288 330
	}
331

  
332
	/**
333
	 * This method generate static password and to be using SP_VerifyStaticPassword()
334
	 * 
335
	 * @param userAlias
336
	 * @param newPassword
337
	 * @param oldPassword
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 - user 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 - used ModifyUser to reset password.<br/>
345
	 *         ERR_INVALID_CREDENTIAL<br/>
346
	 *         ERR_REUSED_PASSWD - reuse previous generated password.<br/>
347
	 */
348
	public int SP_ChangeStaticPassword(String userAlias, String newPassword, String oldPassword) {
349
		int rc = changeStaticPasswordService.changeStaticPassword(userAlias, newPassword, oldPassword, true);
350
		logger.info("SP_ChangeStaticPassword - user alias: [" + userAlias + "] Return: " + rc);
351
		return rc;
352
	}
289 353
}
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java
313 313
		}
314 314
	}
315 315

  
316
	public List listUserAppAccesses(String appAccessId, final Session txSession) throws Exception {
316
	public List listUserAppAccesses(String username, final Session txSession) throws Exception {
317 317
		List accesses = null;
318 318
		Session session = null;
319 319
		try {
......
321 321

  
322 322
			Query query = session.createQuery(
323 323
					"FROM UserAppAccess aa WHERE aa.user.userAlias = :userAlias");
324
			accesses = query.setString("userAlias", appAccessId).list();
324
			accesses = query.setString("userAlias", username).list();
325 325

  
326 326
		} finally {
327 327
			if (txSession == null)
......
332 332

  
333 333
	/**
334 334
	 * 
335
	 * @param appAccessId
335
	 * @param username
336 336
	 * @param type
337 337
	 *            One of the following values: <br>
338 338
	 *            {@link UserAppAccess#TYPE_ADMIN} <br>
339 339
	 *            {@link UserAppAccess#TYPE_USER}
340 340
	 */
341
	public List listUserAppAccesses(String appAccessId, char accessType, final Session txSession)
341
	public List listUserAppAccesses(String username, char accessType, final Session txSession)
342 342
			throws Exception {
343 343

  
344 344
		List accesses = null;
......
352 352
							+ "AND aa.accessType = :accessType");
353 353

  
354 354
			accesses = query
355
					.setString("userAlias", appAccessId)
355
					.setString("userAlias", username)
356 356
					.setCharacter("accessType", accessType)
357 357
					.list();
358 358

  
src/main/java/my/com/upass/maybank/MinimalMaybankFacadeImpl.java
2 2

  
3 3
import my.com.upass.MinimalConstants;
4 4
import my.com.upass.MinimalUPassControllerV2;
5
import my.com.upass.maybank.entities.IbccUser;
5 6
import my.com.upass.maybank.entities.M2uUser;
7
import my.com.upass.maybank.entities.UserProfile;
6 8
import my.com.upass.pojo.MinimalUserBean;
7 9
import net.penril.generic.hibernate.GenericDAOHibernate;
8 10
import net.penril.generic.hibernate.HibernateUtils;
......
27 29
			String appAccessId, String hashedSecretKey,
28 30
			String username, String hashedPassword) {
29 31

  
30
		// TODO Auto-generated method stub
31
		// return minUpcV2.SP_VerifyStaticPassword(username, hashedPassword);
32
		throw new NotImplementedException();
32
		return minUpcV2.verifyStaticPasswordPerApp(
33
				appAccessId, hashedSecretKey, username, hashedPassword);
33 34
	}
34 35

  
35 36
	public int newUser(
36 37
			String appAccessId, String hashedSecretKey,
37 38
			String username, String hashedPassword, String pan1, String pan2) {
38 39

  
40
		MinimalUserBean minUser = new MinimalUserBean();
41
		minUser.setUsername(username);
42
		minUser.setHashedPassword(hashedPassword);
43

  
44
		M2uUser m2uUser = new M2uUser();
45
		m2uUser.setPan1(pan1);
46
		m2uUser.setPan2(pan2);
47
		m2uUser.setMinUser(minUser);
48

  
49
		return newUser(appAccessId, hashedSecretKey, m2uUser);
50
	}
51

  
52
	public int newPublicUser(
53
			String appAccessId, String hashedSecretKey,
54
			String username, String hashedPassword, String panCc) {
55

  
56
		IbccUser ibccUser = new IbccUser();
57
		ibccUser.setPanCc(panCc);
58

  
59
		MinimalUserBean minUser = new MinimalUserBean();
60
		minUser.setUsername(username);
61
		minUser.setHashedPassword(hashedPassword);
62
		ibccUser.setMinUser(minUser);
63

  
64
		return newUser(appAccessId, hashedSecretKey, ibccUser);
65
	}
66

  
67
	public int changePassword(
68
			String appAccessId, String hashedSecretKey,
69
			String username, String oldHashedPassword, String newHashedPassword) {
70

  
71
		return minUpcV2.UA_ModifyUser(appAccessId, hashedSecretKey, username, "", newHashedPassword);
72
	}
73

  
74
	public int resetPassword(
75
			String appAccessId, String hashedSecretKey,
76
			String username, String newHashedPassword) {
77

  
78
		// TODO Auto-generated method stub
79
		throw new NotImplementedException();
80
	}
81

  
82
	// protected methods
83

  
84
	protected int newUser(
85
			String appAccessId, String hashedSecretKey, UserProfile profile) {
86

  
39 87
		int rc = MinimalConstants.ERR_UNKNOWN;
40 88
		Session session = null;
41 89
		try {
42 90
			session = HibernateUtils.currentSession();
43 91
			session.beginTransaction();
44 92

  
45
			MinimalUserBean minUser = new MinimalUserBean();
46
			minUser.setUsername(username);
47
			minUser.setHashedPassword(hashedPassword);
48

  
49
			M2uUser m2uUser = new M2uUser();
50
			m2uUser.setMinUser(minUser);
51
			m2uUser.setPan1(pan1);
52
			m2uUser.setPan2(pan2);
53

  
54
			rc = minUpcV2.addUser(appAccessId, hashedSecretKey, minUser, session);
93
			rc = minUpcV2.addUser(appAccessId, hashedSecretKey, profile.getMinUser(), session);
55 94

  
56 95
			if (rc == MinimalConstants.ERR_SUCCESS) {
57
				rc = minUpcV2.updateProfileShallowly(appAccessId, hashedSecretKey, m2uUser, session);
96
				rc = minUpcV2.updateProfileShallowly(appAccessId, hashedSecretKey, profile, session);
58 97
				session.getTransaction().commit();
59 98

  
60 99
			} else
......
69 108
		}
70 109
		return rc;
71 110
	}
72

  
73
	public int newPublicUser(
74
			String appAccessId, String hashedSecretKey,
75
			String username, String hashedPassword, String panCC) {
76

  
77
		// TODO Auto-generated method stub
78
		throw new NotImplementedException();
79
	}
80

  
81
	public int changePassword(
82
			String appAccessId, String hashedSecretKey,
83
			String username, String oldHashedPassword, String newHashedPassword) {
84

  
85
		// TODO Auto-generated method stub
86
		throw new NotImplementedException();
87
	}
88

  
89
	public int resetPassword(
90
			String appAccessId, String hashedSecretKey,
91
			String username, String newHashedPassword) {
92

  
93
		// TODO Auto-generated method stub
94
		throw new NotImplementedException();
95
	}
96 111
}
src/main/java/my/com/upass/services/AppAccessMgtService.java
11 11

  
12 12
package my.com.upass.services;
13 13

  
14
import java.util.ArrayList;
14 15
import java.util.HashMap;
16
import java.util.Iterator;
17
import java.util.LinkedList;
15 18
import java.util.List;
16 19
import java.util.Map;
17 20

  
......
85 88
		return appId;
86 89
	}
87 90

  
91
	public List/* <Integer> */listAppIdsForUser(String username, Session txSession)
92
			throws MultipleAppAccessesFound {
93

  
94
		List appIds = new ArrayList(5);
95
		UserDAO userDao;
96
		try {
97
			userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
98
			List accessList = userDao.listUserAppAccesses(username, txSession);
99
			Iterator iterator = accessList.iterator();
100
			while (iterator.hasNext()) {
101
				UserAppAccess access = (UserAppAccess) iterator.next();
102
				appIds.add(new Integer(access.getAppId()));
103
			}
104
		} catch (Exception e) {
105
			e.printStackTrace();
106
		}
107
		return appIds;
108
	}
109

  
88 110
	//
89 111

  
90 112
	public class MultipleAppAccessesFound extends Exception {
src/main/java/my/com/upass/services/ChangeStaticPasswordService.java
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.MinimalConstants;
15
import my.com.upass.MinimalUPassControllerV2;
16
import my.com.upass.dao.MinimalDAOFactory;
17
import my.com.upass.dao.UserDAO;
18
import my.com.upass.factory.MinimalUPassFactory;
19
import my.com.upass.pojo.MinimalUserBean;
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 MinimalUPassControllerV2 upc;
38

  
39
	public ChangeStaticPasswordService(MinimalUPassControllerV2 upc)
40
	{
41
		this.upc = upc;
42
	}
43

  
44
	public int changeStaticPassword(String userAlias, String newPassword, String oldPassword,
45
			boolean checkChangeInterval)
46
	{
47
		int rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
48

  
49
		try
50
		{
51
			UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
52
			MinimalUserBean userBean = userDao.getUserFromStore(userAlias, null);
53

  
54
			if (userBean == null)
55
			{
56
				return MinimalConstants.ERR_USERALIAS_NOT_FOUND;
57
			}
58

  
59
			userBean.getPdateCreated();
60

  
61
			// verify user
62
			PasswordController pc = MinimalUPassFactory.getPasswordController(userBean, upc.getConfigurationsMap());
63

  
64
			if (checkChangeInterval == true)
65
			{
66
				rc = pc.checkRegeneratePassword();
67
				if (rc == MinimalConstants.ERR_PASSWD_CHANGE_INTERVAL)
68
				{
69
					return MinimalConstants.ERR_PASSWD_CHANGE_INTERVAL;
70
				}
71
			}
72

  
73
			rc = pc.VerifyPassword(oldPassword);
74

  
75
			if (rc == MinimalConstants.ERR_SUCCESS ||
76
					rc == MinimalConstants.ERR_PASSWD_EXPIRED ||
77
					rc == MinimalConstants.ERR_PASSWD_EXPIRED_NOTIFICATION)
78
			{
79
				rc = pc.GeneratePassword(newPassword, true);
80
			}
81

  
82
			userBean = (MinimalUserBean) pc.getUpdatedObject();
83

  
84
			// update database
85
			boolean lrc = userDao.updateUserToStore(userBean, null);
86

  
87
			if (!lrc)
88
			{
89
				rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
90
			}
91
		} catch (Exception e)
92
		{
93
			e.printStackTrace();
94
		}
95

  
96
		return rc;
97
	}
98
}
src/main/java/my/com/upass/services/CheckPasswordReusedService.java
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 java.util.Date;
15
import java.util.StringTokenizer;
16

  
17
import my.com.upass.MinimalConstants;
18
import my.com.upass.MinimalUPassControllerV2;
19
import my.com.upass.dao.MinimalDAOFactory;
20
import my.com.upass.dao.UserDAO;
21
import my.com.upass.factory.MinimalUPassFactory;
22
import my.com.upass.pojo.MinimalUserBean;
23
import my.com.upass.spassword.PasswordController;
24

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

  
35
/**
36
 * <Class description>
37
 */
38
public class CheckPasswordReusedService
39
{
40
	private MinimalUPassControllerV2 upc;
41

  
42
	public CheckPasswordReusedService(MinimalUPassControllerV2 upc)
43
	{
44
		this.upc = upc;
45
	}
46

  
47
	public int CheckPasswordReused(String userAlias, String password)
48
	{
49
		String token;
50

  
51
		if (userAlias == null || password == null)
52
		{
53
			return MinimalConstants.ERR_INVALID_INPUT;
54
		}
55

  
56
		try
57
		{
58
			UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
59
			MinimalUserBean userBean = userDao.getUserFromStore(userAlias, null);
60

  
61
			if (userBean == null)
62
			{
63
				return MinimalConstants.ERR_USERALIAS_NOT_FOUND;
64
			}
65

  
66
			// verify user state, must be active (not inactive|locked|deleted)
67
			switch (userBean.getUstate())
68
			{
69
			case (MinimalConstants.UID_STATE_ACTIVE):
70
				break;
71
			case (MinimalConstants.UID_STATE_TMP_LOCKED):
72
				Date now = new Date();
73
				if (userBean.getUdateLockedTo().after(now))
74
				{
75
					return MinimalConstants.ERR_INVALID_STATE;
76
				}
77
				break;
78
			default:
79
				return MinimalConstants.ERR_INVALID_STATE;
80
			}
81

  
82
			PasswordController pc = MinimalUPassFactory.getPasswordController(
83
					userBean, upc.getConfigurationsMap());
84
			String cipherText = pc.SHA256(userBean.getUserAlias(), password);
85

  
86
			if (userBean.getPhistoryList() != null)
87
			{
88
				StringTokenizer stz = new StringTokenizer(
89
						userBean.getPhistoryList(), ":");
90
				while (stz.hasMoreTokens())
91
				{
92
					token = stz.nextToken();
93
					if (cipherText.equals(token))
94
					{
95
						return MinimalConstants.ERR_REUSED_PASSWD;
96
					}
97
				}
98
			}
99
			return MinimalConstants.ERR_SUCCESS;
100
		} catch (Exception e)
101
		{
102
			e.printStackTrace();
103
			return MinimalConstants.ERR_SYSTEM_NOT_READY;
104
		}
105
	}
106
}
src/main/java/my/com/upass/services/VerifyPasswordComplexityService.java
1
package my.com.upass.services;
2

  
3
import my.com.upass.ConfigBean;
4
import my.com.upass.MinimalConstants;
5
import my.com.upass.MinimalUPassControllerV2;
6
import my.com.upass.pojo.MinimalUserBean;
7
import my.com.upass.spassword.PasswordController;
8

  
9
public class VerifyPasswordComplexityService {
10
	private MinimalUPassControllerV2 upc;
11

  
12
	public VerifyPasswordComplexityService(MinimalUPassControllerV2 upc) {
13
		this.upc = upc;
14
	}
15

  
16
	public int verifyPasswordComplexity(String userPassword, int applicationId) {
17
		int rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
18
		try {
19
			MinimalUserBean ub = new MinimalUserBean();
20
			PasswordController pc = new PasswordController(ub, upc.getConfigurationsMap());
21
			ConfigBean configBean = pc.getConfigBean();
22

  
23
			if (pc.patternValidator(userPassword, configBean.getPasswordAcceptPattern())) {
24
				rc = MinimalConstants.ERR_SUCCESS;
25

  
26
			} else {
27
				rc = MinimalConstants.ERR_PASSWD_WEAK;
28
			}
29
		} catch (Exception e) {
30
			e.printStackTrace();
31
		}
32
		return rc;
33
	}
34
}

Also available in: Unified diff