Revision 37:ba861318d360

View differences:

src/main/java/my/com/upass/MinimalUPassControllerV2.java
143 143
	public int addUser(String appAccessId, String hashedSecretKey, MinimalUserBean user, Session txSession) {
144 144
		return addUser(appAccessId, hashedSecretKey, user, txSession, true);
145 145
	}
146
	
147
	public int addUser(String appAccessId, String hashedSecretKey, MinimalUserBean user, Session txSession, boolean checkPassword) {
146

  
147
	public int addUser(String appAccessId, String hashedSecretKey, MinimalUserBean user, Session txSession,
148
			boolean checkPassword) {
148 149

  
149 150
		final String userAlias = user.getUserAlias();
150 151
		final String doubleHashedPassword = user.getPcipherText();
......
408 409
		Integer appId = appAccessMgtService.getAppIdForAdmin(appAccessId, txSession);
409 410
		return appId;
410 411
	}
412

  
413
	public UserProfile findProfile(String appAccessId, String hashedSecretKey, String username, Session txSession)
414
			throws UPassException {
415

  
416
		try {
417
			Integer invokingAppId = checkAppAccess(appAccessId, hashedSecretKey, txSession);
418

  
419
			if (invokingAppId == null)
420
				throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED);
421

  
422
			else {
423
				List profiles = modifyUserService.listProfiles(username, txSession);
424

  
425
				for (Iterator profileIter = profiles.iterator(); profileIter.hasNext();) {
426
					UserProfile profile = (UserProfile) profileIter.next();
427

  
428
					final Integer appIdForProfile = (Integer) AppAccessMgtService
429
							.profileToAppMap.get(profile.getClass());
430

  
431
					if (invokingAppId.equals(appIdForProfile)) {
432
						return profile;
433
					}
434
				}
435
				return null;
436
			}
437
		} catch (MultipleAppAccessesFound e) {
438
			throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED);
439
		}
440
	}
411 441
}
src/main/java/my/com/upass/dao/UserDAO.java
74 74
	boolean updateProfileShallowly(UserProfile profile, final Session txSession) throws Exception;
75 75

  
76 76
	boolean updateUserToStore(MinimalUserBean MinimalUserBean, final Session txSession) throws Exception;
77

  
78
	List/*<UserProfile>*/ listProfilesFor(String username, final Session txSession) throws Exception;
77 79
}
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java
11 11

  
12 12
package my.com.upass.dao.hibernate;
13 13

  
14
import java.util.ArrayList;
14 15
import java.util.List;
15 16

  
16 17
import my.com.upass.MinimalConstants;
......
21 22
import my.com.upass.pojo.UserAppAccess;
22 23
import net.penril.generic.hibernate.GenericDAOHibernate;
23 24

  
25
import org.apache.commons.collections.CollectionUtils;
26
import org.apache.commons.collections.PredicateUtils;
24 27
import org.apache.log4j.Logger;
25 28
import org.hibernate.Criteria;
26 29
import org.hibernate.FetchMode;
......
429 432
		}
430 433
		return successful;
431 434
	}
435

  
436
	public List/* <UserProfile> */listProfilesFor(String username, Session txSession) throws Exception {
437

  
438
		List profiles = new ArrayList(5);
439
		Session session = null;
440
		try {
441
			session = txSession != null ? txSession : getSession();
442

  
443
			// Retrieving IbccUser
444
			Query ibccQuery = session.createQuery(
445
					"FROM IbccUser u WHERE u.minUser.userAlias = :userAlias ");
446

  
447
			profiles.add(ibccQuery.setString("userAlias", username).uniqueResult());
448

  
449
			// Retrieving Im2uUser
450
			Query im2uQuery = session.createQuery(
451
					"FROM Im2uUser u WHERE u.m2uUser.minUser.userAlias = :userAlias ");
452

  
453
			profiles.add(im2uQuery.setString("userAlias", username).uniqueResult());
454

  
455
			// Retrieving M2uUser
456
			Query m2uQuery = session.createQuery(
457
					"FROM M2uUser u WHERE u.minUser.userAlias = :userAlias ");
458

  
459
			profiles.add(m2uQuery.setString("userAlias", username).uniqueResult());
460

  
461
			// Retrieving StockUser
462
			Query stockQuery = session.createQuery(
463
					"FROM StockUser u WHERE u.m2uUser.minUser.userAlias = :userAlias ");
464

  
465
			profiles.add(stockQuery.setString("userAlias", username).uniqueResult());
466

  
467
			// Retrieving TicketingUser
468
			Query ticketingQuery = session.createQuery(
469
					"FROM TicketingUser u WHERE u.minUser.userAlias = :userAlias ");
470

  
471
			profiles.add(ticketingQuery.setString("userAlias", username).uniqueResult());
472

  
473
			CollectionUtils.filter(profiles, PredicateUtils.notNullPredicate());
474

  
475
		} finally {
476
			if (txSession == null)
477
				closeSessionIfAny(session);
478
		}
479
		return profiles;
480
	}
432 481
}
src/main/java/my/com/upass/maybank/MinimalMaybankFacade.java
3 3
public interface MinimalMaybankFacade {
4 4

  
5 5
	int authenticateUser(
6
			String appAccessId, String hashedSecretKey, 
6
			String appAccessId, String hashedSecretKey,
7 7
			String username, String hashedPassword);
8 8

  
9 9
	int newUser(
10
			String appAccessId, String hashedSecretKey, 
11
			String username, String hashedPassword, 
10
			String appAccessId, String hashedSecretKey,
11
			String username, String hashedPassword,
12 12
			String pan1, String pan2);
13 13

  
14 14
	int changePassword(
......
16 16
			String username, String oldHashedPassword, String newHashedPassword);
17 17

  
18 18
	int resetPassword(
19
			String appAccessId, String hashedSecretKey, 
19
			String appAccessId, String hashedSecretKey,
20 20
			String username, String newHashedPassword);
21

  
22
	int changePan1(
23
			String appAccessId, String hashedSecretKey,
24
			String username, String pan1);
25

  
26
	int changePan2(
27
			String appAccessId, String hashedSecretKey,
28
			String username, String pan2);
29

  
30
	Response lookupUsername_internal(
31
			String appAccessId, String hashedSecretKey,
32
			String username);
21 33
}
src/main/java/my/com/upass/maybank/MinimalMaybankFacadeImpl.java
1 1
package my.com.upass.maybank;
2 2

  
3
import java.util.Map;
4

  
3 5
import my.com.upass.MinimalConstants;
4 6
import my.com.upass.MinimalUPassControllerV2;
7
import my.com.upass.UPassException;
5 8
import my.com.upass.maybank.entities.M2uUser;
6 9
import my.com.upass.maybank.entities.UserProfile;
7 10
import my.com.upass.pojo.MinimalUserBean;
8 11
import net.penril.generic.hibernate.GenericDAOHibernate;
9 12
import net.penril.generic.hibernate.HibernateUtils;
10 13

  
14
import org.apache.commons.lang.NotImplementedException;
11 15
import org.apache.log4j.Logger;
12 16
import org.hibernate.Session;
13 17

  
......
63 67
				appAccessId, hashedSecretKey, username, newHashedPassword);
64 68
	}
65 69

  
70
	public int changePan1(
71
			String appAccessId, String hashedSecretKey,
72
			String username, String pan1) {
73

  
74
		throw new NotImplementedException();
75
		// return minUpcV2.updateProfileShallowly(
76
		// appAccessId, hashedSecretKey, "", null);
77
	}
78

  
79
	public int changePan2(
80
			String appAccessId, String hashedSecretKey,
81
			String username, String pan2) {
82

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

  
87
	public Response lookupUsername_internal(
88
			String appAccessId, String hashedSecretKey,
89
			String username) {
90

  
91
		Response res = new Response();
92

  
93
		Session session = null;
94
		try {
95
			session = HibernateUtils.currentSession();
96

  
97
			UserProfile profile = minUpcV2.findProfile(
98
					appAccessId, hashedSecretKey, username, session);
99

  
100
			final Map map = profile.propertiesToMap();
101
			res.setMap(map);
102
			res.setCode(MinimalConstants.ERR_SUCCESS);
103

  
104
		} catch (UPassException e) {
105
			LOGGER.info(e, e);
106
			res.setCode(e.getErrorCode());
107
		
108
		} catch (Exception e) {
109
			LOGGER.error(e, e);
110
			res.setCode(MinimalConstants.ERR_UNKNOWN);
111

  
112
		} finally {
113
			GenericDAOHibernate.closeSessionIfAny(session);
114
		}
115
		return res;
116
	}
117

  
66 118
	// protected methods
67 119

  
68 120
	protected int newUser(
src/main/java/my/com/upass/maybank/Response.java
1
package my.com.upass.maybank;
2

  
3
import java.util.Map;
4

  
5
public class Response {
6

  
7
	private int code;
8
	private Map/*<String, String>*/ map;
9

  
10
	//
11

  
12
	public int getCode() {
13
		return code;
14
	}
15

  
16
	public void setCode(int code) {
17
		this.code = code;
18
	}
19

  
20
	public Map getMap() {
21
		return map;
22
	}
23

  
24
	public void setMap(Map map) {
25
		this.map = map;
26
	}
27
}
src/main/java/my/com/upass/maybank/entities/IbccUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

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

  
5 8
public class IbccUser implements UserProfile {
......
37 40
	public void setUserId(Long userId) {
38 41
		this.userId = userId;
39 42
	}
43

  
44
	public Map propertiesToMap() {
45
		Map map = new HashMap(2, 1.0f);
46
		map.put("username", minUser.getUsername());
47
		map.put("panCc", panCc);
48
		return map;
49
	}
40 50
}
src/main/java/my/com/upass/maybank/entities/Im2uUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3 3
import java.util.Date;
4
import java.util.HashMap;
5
import java.util.Map;
4 6

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

  
......
9 11
	private static final long serialVersionUID = 1L;
10 12

  
11 13
	private Long userId;
14
	private M2uUser m2uUser;
12 15
	private String wsFlag;
13 16
	private String wsIdentCode;
14 17
	private String wsMySgId;
15 18
	private Date wsRegTimeStamp;
16
	private M2uUser m2uUser;
17
	
19

  
18 20
	//
19 21

  
20 22
	public String getWsFlag() {
......
66 68
		if (minUser != null)
67 69
			this.userId = m2uUser.getUserId();
68 70
	}
69
	
71

  
70 72
	public M2uUser getM2uUser() {
71 73
		return m2uUser;
72 74
	}
......
76 78
		if (m2uUser != null)
77 79
			this.userId = m2uUser.getUserId();
78 80
	}
81

  
82
	public Map propertiesToMap() {
83
		Map map = new HashMap(2, 1.0f);
84
		map.put("wsFlag", wsFlag);
85
		map.put("wsIdentCode", wsIdentCode);
86
		map.put("wsMySgId", wsMySgId);
87
		map.put("wsRegTimeStamp", wsRegTimeStamp);
88
		map.putAll(m2uUser.propertiesToMap());
89
		return map;
90
	}
91

  
79 92
}
src/main/java/my/com/upass/maybank/entities/M2uUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

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

  
5 8
public class M2uUser implements UserProfile {
......
48 51

  
49 52
	}
50 53

  
54
	public Map propertiesToMap() {
55
		Map map = new HashMap(2, 1.0f);
56
		map.put("pan1", pan1);
57
		map.put("pan2", pan2);
58
		map.put("username", minUser.getUsername());
59
		return map;
60
	}
51 61
}
src/main/java/my/com/upass/maybank/entities/StockUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

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

  
5 8
public class StockUser implements UserProfile {
......
8 11

  
9 12
	private Long userId;
10 13
	private M2uUser m2uUser;
11
	private String palAccountNo;
12
	private String stAccountNo;
13 14
	private String idNo;
14
	private String highNetWorthAttr;
15
	private Integer custType;
16
	private String activeAttr;
17 15

  
18 16
	//
19 17

  
20
	public String getPalAccountNo() {
21
		return palAccountNo;
22
	}
23

  
24
	public void setPalAccountNo(String palAccountNo) {
25
		this.palAccountNo = palAccountNo;
26
	}
27

  
28
	public String getStAccountNo() {
29
		return stAccountNo;
30
	}
31

  
32
	public void setStAccountNo(String stAccountNo) {
33
		this.stAccountNo = stAccountNo;
34
	}
35

  
36 18
	public String getIdNo() {
37 19
		return idNo;
38 20
	}
......
41 23
		this.idNo = idNo;
42 24
	}
43 25

  
44
	public String getHighNetWorthAttr() {
45
		return highNetWorthAttr;
46
	}
47

  
48
	public void setHighNetWorthAttr(String highNetWorthAttr) {
49
		this.highNetWorthAttr = highNetWorthAttr;
50
	}
51

  
52
	public Integer getCustType() {
53
		return custType;
54
	}
55

  
56
	public void setCustType(Integer custType) {
57
		this.custType = custType;
58
	}
59

  
60 26
	public M2uUser getM2uUser() {
61 27
		return m2uUser;
62 28
	}
......
75 41
		this.userId = userId;
76 42
	}
77 43

  
78
	public String getActiveAttr() {
79
		return activeAttr;
80
	}
81

  
82
	public void setActiveAttr(String activeAttr) {
83
		this.activeAttr = activeAttr;
84
	}
85

  
86 44
	public MinimalUserBean getMinUser() {
87 45
		return m2uUser.getMinUser();
88 46
	}
......
92 50
		if (minUser != null)
93 51
			this.userId = m2uUser.getUserId();
94 52
	}
53

  
54
	public Map propertiesToMap() {
55
		Map map = new HashMap(2, 1.0f);
56
		map.put("idNo", idNo);
57
		map.putAll(m2uUser.propertiesToMap());
58
		return map;
59
	}
95 60
}
src/main/java/my/com/upass/maybank/entities/TicketingUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

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

  
5 8
public class TicketingUser implements UserProfile {
6 9

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

  
9 12
	private Long userId;
10 13
	private MinimalUserBean minUser;
11 14
	private String fullName;
......
64 67
	public void setUserId(Long userId) {
65 68
		this.userId = userId;
66 69
	}
70

  
71
	public Map propertiesToMap() {
72
		Map map = new HashMap(2, 1.0f);
73
		map.put("fullName", fullName);
74
		map.put("firstName", firstName);
75
		map.put("lastName", lastName);
76
		map.put("payeeCode", payeeCode);
77
		map.put("username", minUser.getUsername());
78
		return map;
79
	}
67 80
}
src/main/java/my/com/upass/maybank/entities/UserProfile.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3 3
import java.io.Serializable;
4
import java.util.Map;
4 5

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

  
8 8
public interface UserProfile extends Serializable {
......
10 10
	MinimalUserBean getMinUser();
11 11

  
12 12
	void setMinUser(MinimalUserBean maybankUser);
13

  
14
	Map propertiesToMap();
13 15
}
src/main/java/my/com/upass/services/AppAccessMgtService.java
14 14
import java.util.ArrayList;
15 15
import java.util.HashMap;
16 16
import java.util.Iterator;
17
import java.util.LinkedList;
18 17
import java.util.List;
19 18
import java.util.Map;
20 19

  
......
42 41

  
43 42
public class AppAccessMgtService {
44 43

  
44
	/* Class<Integer, Class<UserProfile>> */
45 45
	public static final Map appToProfileMap = createAppToProfileMap();
46

  
47
	/* Map<Class<UserProfile>, Integer> */
46 48
	public static final Map profileToAppMap = createProfileToAppMap();
47 49

  
48 50
	//
src/main/java/my/com/upass/services/ModifyUserService.java
11 11

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

  
14
import java.util.List;
15

  
14 16
import my.com.upass.MinimalConstants;
15 17
import my.com.upass.MinimalUPassControllerV2;
18
import my.com.upass.UPassException;
16 19
import my.com.upass.dao.MinimalDAOFactory;
17 20
import my.com.upass.dao.UserDAO;
18 21
import my.com.upass.factory.MinimalUPassFactory;
......
48 51
			String userPassword, int userState) {
49 52

  
50 53
		int rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
51

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

  
56
		UserDAO userDao;
57

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

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

  
66 64
			if (userPassword != null) {
67 65
				// Generate new paswword
68 66
				PasswordController pc = MinimalUPassFactory.getPasswordController(ub,
......
76 74
				}
77 75
				ub = (MinimalUserBean) pc.getUpdatedObject();
78 76
			}
79

  
80 77
			if (userDesc != null) {
81 78
				ub.setDescription(userDesc);
82 79
			}
83

  
84 80
			ub.setUserType(userType);
85 81
			ub.setUstate(userState);
86 82

  
......
124 120
		}
125 121
		return rc;
126 122
	}
123

  
124
	public List/* <UserProfile> */listProfiles(String username, Session txSession) throws UPassException {
125

  
126
		// int rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
127
		if (username == null) {
128
			throw new UPassException(MinimalConstants.ERR_INVALID_INPUT);
129
		}
130
		try {
131
			UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
132
			return userDao.listProfilesFor(username, txSession);
133

  
134
		} catch (Exception e) {
135
			if (e instanceof UPassException) {
136
				UPassException upassEx = (UPassException) e;
137
				throw upassEx;
138

  
139
			} else
140
				e.printStackTrace();
141
		}
142
		return null;
143
	}
127 144
}
src/main/resources/my/com/upass/maybank/entities/hibernate/StockUser.hbm.xml
11 11
		<property name="activeAttr" type="string">
12 12
			<column name="ACTIVE_ATTR" length="1" />
13 13
		</property>
14
		 -->
15 14
		<property name="highNetWorthAttr" type="string">
16 15
			<column name="HIGH_NET_WORTH_ATTR" length="1" />
17 16
		</property>
18 17
		<property name="custType" type="integer">
19 18
			<column name="CUST_TYPE" />
20 19
		</property>
20
		 -->
21 21
		<property name="idNo" type="string">
22 22
			<column name="ID_NO" length="20" />
23 23
		</property>
24
		<property name="stAccountNo" type="string">
25
			<column name="ST_ACCOUNT_NO" length="20" />
24
		<!-- 
25
		<column name="ST_ACCOUNT_NO" length="20" />
26 26
		</property>
27 27
		<property name="palAccountNo" type="string">
28 28
			<column name="PAL_ACCOUNT_NO" length="20" />
29 29
		</property>
30
 		<property name="stAccountNo" type="string">
31
		 -->
30 32
		<one-to-one name="m2uUser" class="my.com.upass.maybank.entities.M2uUser" constrained="true"></one-to-one>
31 33
	</class>
32 34
</hibernate-mapping>

Also available in: Unified diff