Revision 75:19f5d64d6b4e

View differences:

src/main/java/my/com/upass/MinimalUPassControllerV2.java
9 9

  
10 10
import my.com.upass.dao.ConfigurationDAO;
11 11
import my.com.upass.dao.MinimalDAOFactory;
12
import my.com.upass.maybank.entities.M2uUser;
13
import my.com.upass.maybank.entities.M2uUserContainer;
14
import my.com.upass.maybank.entities.StockUser;
12 15
import my.com.upass.maybank.entities.UserProfile;
13 16
import my.com.upass.pojo.AuthenticationBean;
14 17
import my.com.upass.pojo.ClientApp;
......
24 27
import my.com.upass.services.VerifyStaticPasswordService.ReturnBundle;
25 28
import my.com.upass.spring.ldap.MaybankLdapDAO;
26 29

  
30
import org.apache.commons.lang.NotImplementedException;
27 31
import org.apache.log4j.Logger;
28 32
import org.hibernate.Session;
29 33
import org.springframework.beans.factory.BeanFactory;
......
317 321
		} catch (UPassException e) {
318 322
			rc = e.getErrorCode();
319 323
			e.printStackTrace();
324

  
325
		} catch (Exception e) {
326
			rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
327
			e.printStackTrace();
320 328
		}
321 329
		logger.info("verifyStaticPassword_withAppChecked - user alias: [" + username + "] Return: " + rc);
322 330
		return rc;
......
401 409
				rc = updateProfileShallowly_noAccessCheck(profile, txSession);
402 410
			else
403 411
				rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
404
			
412

  
405 413
		} catch (MultipleAppAccessesFound e) {
406 414
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
407 415
			e.printStackTrace();
......
411 419
	}
412 420

  
413 421
	public int updateProfileShallowly_noAccessCheck(UserProfile profile, Session txSession)
414
			throws MultipleAppAccessesFound {
422
			throws UPassException {
415 423

  
416 424
		final MinimalUserBean user = profile.getMinUser();
425
		final String username = user.getUsername();
426

  
427
		if (profile instanceof M2uUserContainer) {
428
			UserProfile m2uUser = findProfile_noAccessCheck(username, ClientApp.APP_ID_M2U, txSession);
429
			if (m2uUser == null)
430
				throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED);
431
		}
417 432
		final int appIdForProfile = AppAccessMgtService.getAppIdForProfile(profile).intValue();
418 433

  
419
		List grantedAppAccesses = appAccessMgtService.listAppIdsForUser(user.getUsername(), txSession);
434
		List grantedAppAccesses = appAccessMgtService.listAppIdsForUser(username, txSession);
420 435

  
421 436
		boolean granted = false;
422 437
		granted = (grantedAppAccesses.contains(new Integer(appIdForProfile))) ?
......
496 511
		return rc;
497 512
	}
498 513

  
499
	// Helper methods
514
	// Helper methods and classes
500 515

  
501 516
	public class AccessCheckResult {
502 517

  
......
561 576
		return result;
562 577
	}
563 578

  
579
	private AccessCheckResult checkAppAccessToUser(AuthenticationBean authBean) {
580

  
581
		// ReturnBundle ret = verifyStaticPasswordService.verifyStaticPassword_returnUser(authBean, false, 0);
582
		//
583
		// final int retCode = ret.getCode();
584
		// if (retCode != MinimalConstants.ERR_SUCCESS)
585
		// throw new UPassException(retCode);
586
		//
587
		// AccessCheckResult result = new AccessCheckResult();
588
		// result.invokerUserType = new Integer(ret.getUser().getUserType());
589
		//
590
		// if (result.hasUPassAdminAccess())
591
		// return result;
592
		//
593
		// result.invokerAppId = appAccessMgtService.getAppIdForAdmin(authBean);
594
		// return result;
595
		throw new NotImplementedException();
596
	}
597

  
564 598
	/**
565 599
	 * This methods identifies the target app using <code>appAccessId</code>,
566 600
	 * hence meant for {@link ClientApp}s
......
604 638
					throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED);
605 639
				}
606 640
			}
607
			List profiles = modifyUserService.listProfiles(username, txSession);
608
			for (Iterator profileIter = profiles.iterator(); profileIter.hasNext();) {
609
				UserProfile profile = (UserProfile) profileIter.next();
610

  
611
				final Integer appIdForProfile = (Integer) AppAccessMgtService.getAppIdForProfile(profile);
612

  
613
				if (targetAppId.equals(appIdForProfile))
614
					return profile;
615
			}
616
			return null;
641
			return findProfile_noAccessCheck(username, targetAppId, txSession);
617 642

  
618 643
		} catch (MultipleAppAccessesFound e) {
619 644
			throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED, e);
620 645
		}
621 646
	}
622 647

  
648
	protected UserProfile findProfile_noAccessCheck(
649
			String username, Integer targetAppId, Session txSession)
650
			throws UPassException {
651

  
652
		List profiles = modifyUserService.listProfiles(username, txSession);
653
		for (Iterator profileIter = profiles.iterator(); profileIter.hasNext();) {
654
			UserProfile profile = (UserProfile) profileIter.next();
655

  
656
			final Integer appIdForProfile = (Integer) AppAccessMgtService.getAppIdForProfile(profile);
657

  
658
			if (targetAppId.equals(appIdForProfile))
659
				return profile;
660
		}
661
		return null;
662
	}
663

  
623 664
	public List/* <UserProfile> */listProfilesByExamples(
624 665
			String appAccessId, String hashedSecretKey,
625 666
			List/* <UserProfile> */exampleProfiles, Session txSession)
src/main/java/my/com/upass/dao/UserDAO.java
16 16

  
17 17
import my.com.upass.generic.hibernate.GenericDAO;
18 18
import my.com.upass.maybank.entities.UserProfile;
19
import my.com.upass.pojo.AuthenticationBean;
19 20
import my.com.upass.pojo.ClientApp;
20 21
import my.com.upass.pojo.MinimalUserBean;
21 22
import my.com.upass.pojo.MinimalUserBeanBackup;
......
42 43

  
43 44
	boolean deleteUser(MinimalUserBean userBean, final Session txSession) throws Exception;
44 45

  
45
	boolean deleteProfile(String username, Class/* <UserProfile> */profileClass, Session txSession) throws Exception;
46
	boolean deleteProfile(String username, Class/* <UserProfile> */profileClass, final Session txSession) throws Exception;
46 47

  
47 48
	MinimalUserBean getTbAmUserByUserAlias(String userAlias, final Session txSession) throws Exception;
48 49

  
......
64 65
	 */
65 66
	List listAllClientApps(final Session txSession) throws Exception;
66 67

  
67
	boolean addUserAppAccess(UserAppAccess access, Session txSession) throws Exception;
68
	boolean addUserAppAccess(UserAppAccess access, final Session txSession) throws Exception;
68 69

  
69
	boolean removeUserAppAccess(String username, int appId, Session txSession) throws Exception;
70
	boolean removeUserAppAccess(String username, int appId, final Session txSession) throws Exception;
70 71

  
71 72
	/**
72 73
	 * @param appAccessId
......
93 94
	List/* <UserProfile> */listProfilesByExamples(
94 95
			List/* <UserProfile> */exampleProfiles, final Session txSession)
95 96
			throws Exception;
96
	
97

  
97 98
	List/* <UserProfile> */listProfilesByExamples(
98 99
			List/* <UserProfile> */exampleProfiles, Date fromDate, Date toDate, final Session txSession)
99 100
			throws Exception;
100 101

  
102
	AuthenticationBean retrieveAuthBeanFor(
103
			String invokerUsername, String invokerHashedPassword,
104
			String targetUsername, String targetHashedPassword, final Session txSession)
105
			throws Exception;
101 106
}
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java
16 16
import java.util.Date;
17 17
import java.util.GregorianCalendar;
18 18
import java.util.Iterator;
19
import java.util.LinkedList;
19 20
import java.util.List;
20 21

  
21 22
import my.com.upass.MinimalConstants;
......
24 25
import my.com.upass.maybank.entities.Im2uUser;
25 26
import my.com.upass.maybank.entities.StockUser;
26 27
import my.com.upass.maybank.entities.UserProfile;
28
import my.com.upass.pojo.AuthenticationBean;
27 29
import my.com.upass.pojo.ClientApp;
28 30
import my.com.upass.pojo.MinimalUserBean;
29 31
import my.com.upass.pojo.MinimalUserBeanBackup;
......
275 277
			Criteria m_oCriteria = session.createCriteria(MinimalUserBean.class);
276 278
			m_oCriteria.add(Restrictions.eq("userAlias", userAlias));
277 279
			minUser = (MinimalUserBean) m_oCriteria.uniqueResult();
278
			
280

  
279 281
			if (txSession == null)
280 282
				Hibernate.initialize(minUser);
281 283

  
......
399 401
					.setString("userAlias", username)
400 402
					.setCharacter("accessType", accessType)
401 403
					.list();
402
			
404

  
403 405
			if (txSession == null)
404 406
				Hibernate.initialize(accesses);
405 407

  
......
709 711
		return isSuccessful;
710 712
	}
711 713

  
714
	public AuthenticationBean retrieveAuthBeanFor(
715
			String invokerUsername, String invokerHashedPassword,
716
			String targetUsername, String targetHashedPassword, Session txSession)
717
			throws Exception {
718

  
719
		AuthenticationBean authBean = new AuthenticationBean(
720
				invokerUsername, invokerHashedPassword,
721
				targetUsername, targetHashedPassword);
722

  
723
		final LinkedList invokerAccesses = new LinkedList();
724
		final LinkedList targetAccesses = new LinkedList();
725

  
726
		Session session = null;
727
		try {
728
			session = txSession != null ? txSession : getSession();
729

  
730
			Query query = session.createQuery(
731
					"SELECT a, u FROM UserAppAccess a"
732
							+ " RIGHT OUTER JOIN a.user u"
733
							+ " WHERE u.userAlias = :invokerUsername"
734
							+ " OR u.userAlias = :targetUsername");
735

  
736
			List/* <Object[]> */records = query.list();
737

  
738
			for (Iterator iterator = records.iterator(); iterator.hasNext();) {
739
				Object[] record = (Object[]) iterator.next();
740
				final UserAppAccess access = (UserAppAccess) record[0];
741
				final MinimalUserBean user = (MinimalUserBean) record[1];
742

  
743
				if (user.getUsername().equals(invokerUsername)) {
744
					authBean.setLoadedInvoker(user);
745
					if (access != null)
746
						invokerAccesses.add(access);
747

  
748
				} else {
749
					authBean.setLoadedTarget(user);
750
					if (access != null)
751
						targetAccesses.add(access);
752
				}
753
			}
754
			authBean.setLoadedInvokerAccessList(invokerAccesses);
755
			authBean.setLoadedTargetAccessList(targetAccesses);
756

  
757
			if (txSession == null)
758
				Hibernate.initialize(records);
759

  
760
		} finally {
761
			if (txSession == null)
762
				closeSessionIfAny(session);
763
		}
764
		return authBean;
765
	}
766

  
712 767
	// Helper methods
713 768

  
714 769
	private void ensureUserInitialized(List/* <UserProfile> */profiles) {
......
717 772
			Hibernate.initialize(profile.getMinUser());
718 773
		}
719 774
	}
720

  
721 775
}
src/main/java/my/com/upass/db/MinimalDbOperations.java
282 282

  
283 283
			java.sql.Timestamp today = getCurrentSqlDate();
284 284
			pstmt.setTimestamp(3, today); // last used
285
			pstmt.setInt(4, ub.getUuseCount() + 1);
285
			pstmt.setLong(4, ub.getUuseCount() + 1);
286 286
			pstmt.setTimestamp(5, convertSqlDate(ub.getUdateLastActivated())); // last act
287 287
			pstmt.setTimestamp(6, convertSqlDate(ub.getUdateLastLocked())); // last lock
288 288

  
......
294 294
			pstmt.setTimestamp(12, convertSqlDate(ub.getUdateCreated())); // generated
295 295
			pstmt.setTimestamp(13, convertSqlDate(ub.getPdateFirstUsed())); // 1st used
296 296
			pstmt.setTimestamp(14, convertSqlDate(ub.getPdateLastUsed())); // 1ast used
297
			pstmt.setInt(15, ub.getPuseCount());
297
			pstmt.setLong(15, ub.getPuseCount());
298 298
			pstmt.setInt(16, ub.getPerrorCount());
299 299
			pstmt.setInt(17, ub.getPexpiredStatus());
300 300
			pstmt.setTimestamp(18, convertSqlDate(ub.getPdateExpired()));
src/main/java/my/com/upass/maybank/entities/Im2uUser.java
10 10

  
11 11
import my.com.upass.pojo.MinimalUserBean;
12 12

  
13
public class Im2uUser implements UserProfile {
13
public class Im2uUser implements UserProfile, M2uUserContainer {
14 14

  
15 15
	private static final long serialVersionUID = 1L;
16 16

  
src/main/java/my/com/upass/maybank/entities/M2uUserContainer.java
1
package my.com.upass.maybank.entities;
2

  
3
public interface M2uUserContainer {
4

  
5
	M2uUser getM2uUser();
6

  
7
	void setM2uUser(M2uUser user);
8
}
src/main/java/my/com/upass/maybank/entities/StockUser.java
5 5

  
6 6
import my.com.upass.pojo.MinimalUserBean;
7 7

  
8
public class StockUser implements UserProfile {
8
public class StockUser implements UserProfile, M2uUserContainer {
9 9

  
10 10
	private static final long serialVersionUID = 1L;
11 11

  
src/main/java/my/com/upass/pojo/AuthenticationBean.java
88 88
	public void setLoadedTargetAccessList(List/* <UserAppAccess> */userAccesses) {
89 89
		this.loadedTargetAccessList = userAccesses;
90 90
	}
91

  
91 92
}
src/main/java/my/com/upass/pojo/MinimalUserBean.java
16 16
	private String description;
17 17
	private Date udateCreated;
18 18
	private Date udateLastUsed;
19
	private int uuseCount;
19
	private long uuseCount;
20 20
	private Date udateLastActivated;
21 21
	private Date udateLastLocked;
22 22
	private int ustate;
......
27 27
	private Date pdateCreated;
28 28
	private Date pdateFirstUsed;
29 29
	private Date pdateLastUsed;
30
	private int puseCount;
30
	private long puseCount;
31 31
	private int perrorCount;
32 32
	private String phistoryList;
33 33
	private int pexpiredStatus;
......
87 87
		this.udateLastUsed = udateLastUsed;
88 88
	}
89 89

  
90
	public int getUuseCount() {
90
	public long getUuseCount() {
91 91
		return uuseCount;
92 92
	}
93 93

  
94
	public void setUuseCount(int uuseCount) {
94
	public void setUuseCount(long uuseCount) {
95 95
		this.uuseCount = uuseCount;
96 96
	}
97 97

  
......
175 175
		this.pdateLastUsed = pdateLastUsed;
176 176
	}
177 177

  
178
	public int getPuseCount() {
178
	public long getPuseCount() {
179 179
		return puseCount;
180 180
	}
181 181

  
182
	public void setPuseCount(int puseCount) {
182
	public void setPuseCount(long puseCount) {
183 183
		this.puseCount = puseCount;
184 184
	}
185 185

  
src/main/java/my/com/upass/pojo/MinimalUserBeanBackup.java
3 3
import java.io.Serializable;
4 4
import java.util.Date;
5 5

  
6
public class MinimalUserBeanBackup implements Serializable{
6
public class MinimalUserBeanBackup implements Serializable {
7 7

  
8 8
	/**
9 9
	 * 
......
16 16
	private String description;
17 17
	private Date udateCreated;
18 18
	private Date udateLastUsed;
19
	private int uuseCount;
19
	private long uuseCount;
20 20
	private Date udateLastActivated;
21 21
	private Date udateLastLocked;
22 22
	private int ustate;
......
27 27
	private Date pdateCreated;
28 28
	private Date pdateFirstUsed;
29 29
	private Date pdateLastUsed;
30
	private int puseCount;
30
	private long puseCount;
31 31
	private int perrorCount;
32 32
	private String phistoryList;
33 33
	private int pexpiredStatus;
34 34
	private Date pdateExpired;
35 35
	private int applicationId;
36

  
36 37
	public long getUserID() {
37 38
		return userID;
38 39
	}
......
81 82
		this.udateLastUsed = udateLastUsed;
82 83
	}
83 84

  
84
	public int getUuseCount() {
85
	public long getUuseCount() {
85 86
		return uuseCount;
86 87
	}
87 88

  
88
	public void setUuseCount(int uuseCount) {
89
	public void setUuseCount(long uuseCount) {
89 90
		this.uuseCount = uuseCount;
90 91
	}
91 92

  
......
169 170
		this.pdateLastUsed = pdateLastUsed;
170 171
	}
171 172

  
172
	public int getPuseCount() {
173
	public long getPuseCount() {
173 174
		return puseCount;
174 175
	}
175 176

  
176
	public void setPuseCount(int puseCount) {
177
	public void setPuseCount(long puseCount) {
177 178
		this.puseCount = puseCount;
178 179
	}
179 180

  
......
218 219
	}
219 220

  
220 221
	/**
221
	 * @param oid the oid to set
222
	 * @param oid
223
	 *            the oid to set
222 224
	 */
223 225
	public void setOid(int oid) {
224 226
		this.oid = oid;
src/main/java/my/com/upass/services/VerifyStaticPasswordService.java
22 22
import my.com.upass.dao.MinimalDAOFactory;
23 23
import my.com.upass.dao.UserDAO;
24 24
import my.com.upass.factory.MinimalUPassFactory;
25
import my.com.upass.pojo.AuthenticationBean;
25 26
import my.com.upass.pojo.MinimalUserBean;
26 27
import my.com.upass.spassword.PasswordController;
27 28

  
......
261 262
			return user;
262 263
		}
263 264
	}
265

  
266
	public AuthenticationBean retrieveAuthBeanFor(
267
			String invokerUsername, String invokerHashedPassword,
268
			String targetUsername, String targetHashedPassword)
269
			throws Exception {
270

  
271
		UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
272
		return userDao.retrieveAuthBeanFor(
273
				invokerUsername, invokerHashedPassword,
274
				targetUsername, targetHashedPassword, null);
275
	}
264 276
}
src/main/resources/my/com/upass/hibernate/TbAmUser.hbm.xml
23 23
		<property name="udateLastUsed" type="timestamp">
24 24
			<column name="U_DATE_LAST_USED" />
25 25
		</property>
26
		<property name="uuseCount" type="integer">
27
			<column name="U_USE_COUNT" precision="6" not-null="true" />
26
		<property name="uuseCount" type="long">
27
			<column name="U_USE_COUNT" precision="19" not-null="true" />
28 28
		</property>
29 29
		<property name="udateLastActivated" type="timestamp">
30 30
			<column name="U_DATE_LAST_ACT" />
......
56 56
		<property name="pdateLastUsed" type="timestamp">
57 57
			<column name="P_DATE_LAST_USED" />
58 58
		</property>
59
		<property name="puseCount" type="integer">
60
			<column name="P_USE_COUNT" precision="6" not-null="true" />
59
		<property name="puseCount" type="long">
60
			<column name="P_USE_COUNT" precision="19" not-null="true" />
61 61
		</property>
62 62
		<property name="perrorCount" type="integer">
63 63
			<column name="P_ERROR_COUNT" precision="2" not-null="true" />
src/main/resources/my/com/upass/hibernate/TbAmUserBackup.hbm.xml
27 27
		<property name="udateLastUsed" type="timestamp">
28 28
			<column name="U_DATE_LAST_USED" />
29 29
		</property>
30
		<property name="uuseCount" type="integer">
31
			<column name="U_USE_COUNT" precision="6" />
30
		<property name="uuseCount" type="long">
31
			<column name="U_USE_COUNT" precision="19" />
32 32
		</property>
33 33
		<property name="udateLastActivated" type="timestamp">
34 34
			<column name="U_DATE_LAST_ACT" />
......
60 60
		<property name="pdateLastUsed" type="timestamp">
61 61
			<column name="P_DATE_LAST_USED" />
62 62
		</property>
63
		<property name="puseCount" type="integer">
64
			<column name="P_USE_COUNT" precision="6"/>
63
		<property name="puseCount" type="long">
64
			<column name="P_USE_COUNT" precision="19"/>
65 65
		</property>
66 66
		<property name="perrorCount" type="integer">
67 67
			<column name="P_ERROR_COUNT" precision="2"/>

Also available in: Unified diff