Revision 31:a51e40b36aab

View differences:

src/main/java/my/com/upass/MinimalUPassControllerV2.java
37 37
	}
38 38

  
39 39
	protected void initializeConfigurations() {
40
		try
41
		{
40
		try {
42 41
			ConfigurationDAO configurationDAO = MinimalDAOFactory.minimalInstance().getConfigurationDAO();
43 42
			boolean isConfigChange = configurationDAO.isConfigChanged();
44 43

  
45
			if (configFirstLoad || isConfigChange)
46
			{
44
			if (configFirstLoad || isConfigChange) {
45

  
47 46
				logger.info("Refresh Configuration ....");
48 47

  
49 48
				List configurations = configurationDAO.getConfigurationsFromStore();
......
52 51

  
53 52
				int configType;
54 53
				Iterator itr = configurations.iterator();
55
				while (itr.hasNext())
56
				{
54
				while (itr.hasNext()) {
57 55
					configPojo = (ConfigurationBean) itr.next();
58 56
					configType = configPojo.getApplicationId();
59 57

  
60 58
					configBean = (ConfigBean) configurationMap.get(new Integer(configType));
61
					if (configBean == null)
62
					{
59
					if (configBean == null) {
63 60
						configBean = new ConfigBean();
64 61
					}
65

  
66 62
					logger.info("COnfig Type:" + configType + "=config name:" + configPojo.getConfigName()
67 63
							+ "=config Value:" + configPojo.getConfigValue());
68 64
					configBean.setConfigBean(configPojo.getConfigName(), configPojo.getConfigValue());
......
74 70
				}
75 71
				logger.info("Refresh Configuration Done ....");
76 72
			}
77
		} catch (Exception e)
78
		{
73
		} catch (Exception e) {
79 74
			logger.error(e);
80 75
		}
81 76
	}
......
99 94
			String configValue = (String) paramMap.get(configName);
100 95
			configBean.setConfigBean(configName, configValue);
101 96
		}
102

  
103 97
		return configBean;
104 98
	}
105 99

  
......
155 149
		if (userAlias.equalsIgnoreCase(doubleHashedPassword)) {
156 150
			return MinimalConstants.ERR_PASSWORD_SAMEAS_USERALIAS;
157 151
		}
158
		int rc = verifyStaticPasswordService.verifyStaticPassword(
159
				appAccessId, hashedSecretKey, true, MinimalConstants.UTYPE_STATE_USER, txSession);
160

  
161
		if (rc != MinimalConstants.ERR_SUCCESS) {
162
			return rc;
163
		}
164
		Integer appId = null;
152
		int rc;
165 153
		try {
166
			appId = appAccessMgtService.getAppIdForAdmin(appAccessId, txSession);
154
			Integer appId = checkAppAccess(appAccessId, hashedSecretKey);
167 155

  
168 156
			if (appId == null)
169 157
				rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
......
177 165
		} catch (MultipleAppAccessesFound e) {
178 166
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
179 167
			e.printStackTrace();
168

  
169
		} catch (UPassException e) {
170
			rc = e.getErrorCode();
171
			e.printStackTrace();
180 172
		}
181 173
		logger.info("addUser - user alias: [" + userAlias + "] Return: " + rc);
182 174
		return rc;
......
203 195
		return rc;
204 196
	}
205 197

  
206
	public int verifyStaticPasswordPerApp(
198
	public int verifyStaticPassword_withAppChecked(
207 199
			String appAccessId, String hashedSecretKey,
208 200
			String username, String hashedPassword) {
209 201

  
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;
202
		int rc;
218 203
		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

  
204
			checkAppAccessToUser(appAccessId, hashedSecretKey, username);
229 205
			rc = verifyStaticPasswordService.verifyStaticPassword(
230 206
					username, hashedPassword, false, 0);
231 207

  
232 208
		} catch (MultipleAppAccessesFound e) {
233 209
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
234 210
			e.printStackTrace();
211

  
212
		} catch (UPassException e) {
213
			rc = e.getErrorCode();
214
			e.printStackTrace();
235 215
		}
236
		logger.info("verifyStaticPassword - user alias: [" + username + "] Return: " + rc);
216
		logger.info("verifyStaticPassword_withAppChecked - user alias: [" + username + "] Return: " + rc);
237 217
		return rc;
238 218
	}
239 219

  
......
273 253
				adminUserAlias, adminUserPassword, true,
274 254
				MinimalConstants.UTYPE_STATE_ADMIN);
275 255

  
276
		if (rc != MinimalConstants.ERR_SUCCESS)
277
		{
256
		if (rc != MinimalConstants.ERR_SUCCESS) {
278 257
			return rc;
279 258
		}
280 259

  
......
294 273

  
295 274
		MinimalUserBean user = profile.getMinUser();
296 275
		final String userAlias = user.getUserAlias();
297
		final String doubleHashedPassword = user.getPcipherText();
298 276

  
299 277
		// // check if password is similar to user alias
300 278
		// if (userAlias.equalsIgnoreCase(doubleHashedPassword)) {
301 279
		// return MinimalConstants.ERR_PASSWORD_SAMEAS_USERALIAS;
302 280
		// }
303 281

  
304
		int rc = verifyStaticPasswordService.verifyStaticPassword(
305
				appAccessId, hashedSecretKey, true,
306
				MinimalConstants.UTYPE_STATE_USER, txSession);
307

  
308
		if (rc != MinimalConstants.ERR_SUCCESS)
309
			return rc;
310

  
311
		Integer appId = null;
282
		int rc;
312 283
		try {
313
			appId = appAccessMgtService.getAppIdForAdmin(appAccessId, txSession);
284
			Integer appId = checkAppAccess(appAccessId, hashedSecretKey);
314 285

  
315 286
			final Object appIdObj = AppAccessMgtService.profileToAppMap.get(profile.getClass());
316 287
			final int appIdForProfile = ((Integer) appIdObj).intValue();
......
324 295
		} catch (MultipleAppAccessesFound e) {
325 296
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
326 297
			e.printStackTrace();
298

  
299
		} catch (UPassException e) {
300
			rc = e.getErrorCode();
301
			e.printStackTrace();
327 302
		}
328 303
		logger.info("updateProfileShallowly - user alias: [" + userAlias + "] Return: " + rc);
329 304
		return rc;
......
350 325
		logger.info("SP_ChangeStaticPassword - user alias: [" + userAlias + "] Return: " + rc);
351 326
		return rc;
352 327
	}
328

  
329
	public int changeStaticPassword_withAppChecked(
330
			String appAccessId, String hashedSecretKey,
331
			String username, String newHashedPassword, String oldHashedPassword) {
332

  
333
		int rc;
334
		try {
335
			checkAppAccessToUser(appAccessId, hashedSecretKey, username);
336
			rc = changeStaticPasswordService.changeStaticPassword(
337
					username, newHashedPassword, oldHashedPassword, true);
338

  
339
		} catch (MultipleAppAccessesFound e) {
340
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
341
			e.printStackTrace();
342

  
343
		} catch (UPassException e) {
344
			rc = e.getErrorCode();
345
			e.printStackTrace();
346
		}
347
		logger.info("changeStaticPassword_withAppChecked - user alias: [" + username + "] Return: " + rc);
348
		return rc;
349
	}
350

  
351
	public int resetPassword_withAppChecked(
352
			String appAccessId, String hashedSecretKey,
353
			String username, String newHashedPassword) {
354

  
355
		int rc;
356
		try {
357
			checkAppAccessToUser(appAccessId, hashedSecretKey, username);
358
			rc = modifyUserService.modifyUser(
359
					username, MinimalConstants.UTYPE_STATE_USER, "",
360
					newHashedPassword, MinimalConstants.UID_STATE_ACTIVE);
361

  
362
		} catch (MultipleAppAccessesFound e) {
363
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
364
			e.printStackTrace();
365

  
366
		} catch (UPassException e) {
367
			rc = e.getErrorCode();
368
			e.printStackTrace();
369
		}
370
		logger.info("resetPassword_withAppChecked - user alias: [" + username + "] Return: " + rc);
371
		return rc;
372
	}
373

  
374
	// Helper methods
375

  
376
	protected Integer checkAppAccessToUser(String appAccessId, String hashedSecretKey, String username)
377
			throws MultipleAppAccessesFound, UPassException {
378

  
379
		Integer appId = checkAppAccess(appAccessId, hashedSecretKey);
380

  
381
		List appIdsForUser = appAccessMgtService.listAppIdsForUser(username, null);
382
		int rc = appIdsForUser.contains(appId) ?
383
				MinimalConstants.ERR_SUCCESS
384
				: MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
385

  
386
		if (rc != MinimalConstants.ERR_SUCCESS)
387
			throw new UPassException(rc);
388

  
389
		return appId;
390
	}
391

  
392
	protected Integer checkAppAccess(String appAccessId, String hashedSecretKey)
393
			throws UPassException, MultipleAppAccessesFound {
394

  
395
		int rc = verifyStaticPasswordService.verifyStaticPassword(
396
				appAccessId, hashedSecretKey, true,
397
				MinimalConstants.UTYPE_STATE_USER);
398

  
399
		if (rc != MinimalConstants.ERR_SUCCESS)
400
			throw new UPassException(rc);
401

  
402
		Integer appId = appAccessMgtService.getAppIdForAdmin(appAccessId, null);
403
		return appId;
404
	}
353 405
}
src/main/java/my/com/upass/UPassException.java
1
package my.com.upass;
2

  
3
public class UPassException extends Exception {
4

  
5
	private static final long serialVersionUID = 1L;
6

  
7
	private final int errorCode;
8

  
9
	public UPassException(int errorCode) {
10
		this.errorCode = errorCode;
11
	}
12

  
13
	public int getErrorCode() {
14
		return errorCode;
15
	}
16
}
src/main/java/my/com/upass/maybank/MinimalMaybankFacade.java
11 11
			String username, String hashedPassword, 
12 12
			String pan1, String pan2);
13 13

  
14
	int newPublicUser(
15
			String appAccessId, String hashedSecretKey, 
16
			String username, String hashedPassword, String panCC);
17

  
18 14
	int changePassword(
19 15
			String appAccessId, String hashedSecretKey,
20 16
			String username, String oldHashedPassword, String newHashedPassword);
src/main/java/my/com/upass/maybank/MinimalMaybankFacadeImpl.java
29 29
			String appAccessId, String hashedSecretKey,
30 30
			String username, String hashedPassword) {
31 31

  
32
		return minUpcV2.verifyStaticPasswordPerApp(
32
		return minUpcV2.verifyStaticPassword_withAppChecked(
33 33
				appAccessId, hashedSecretKey, username, hashedPassword);
34 34
	}
35 35

  
......
49 49
		return newUser(appAccessId, hashedSecretKey, m2uUser);
50 50
	}
51 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 52
	public int changePassword(
68 53
			String appAccessId, String hashedSecretKey,
69 54
			String username, String oldHashedPassword, String newHashedPassword) {
70 55

  
71
		return minUpcV2.UA_ModifyUser(appAccessId, hashedSecretKey, username, "", newHashedPassword);
56
		return minUpcV2.changeStaticPassword_withAppChecked(
57
				appAccessId, hashedSecretKey, username, newHashedPassword, oldHashedPassword);
72 58
	}
73 59

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

  
78
		// TODO Auto-generated method stub
79
		throw new NotImplementedException();
64
		return minUpcV2.resetPassword_withAppChecked(
65
				appAccessId, hashedSecretKey, username, newHashedPassword);
80 66
	}
81 67

  
82 68
	// protected methods

Also available in: Unified diff