Revision 43:c0c5cde243f2
src/main/java/my/com/upass/MinimalUPassControllerV2.java | ||
---|---|---|
142 | 142 |
if (rc != MinimalConstants.ERR_SUCCESS) { |
143 | 143 |
return rc; |
144 | 144 |
} |
145 |
rc = createUserService.addUser(userAlias, MinimalConstants.UTYPE_STATE_USER, |
|
146 |
userDesc, userPassword, MinimalConstants.UID_STATE_ACTIVE, appId); |
|
145 |
rc = createUserService.addUser( |
|
146 |
userAlias, MinimalConstants.UTYPE_STATE_USER, userDesc, |
|
147 |
userPassword, MinimalConstants.UID_STATE_ACTIVE, appId); |
|
147 | 148 |
|
148 | 149 |
logger.info("UA_AddUser - user alias: [" + userAlias + "] Return: " + rc); |
149 | 150 |
return rc; |
150 | 151 |
} |
151 | 152 |
|
152 |
public int addUser(String appAccessId, String hashedSecretKey, MinimalUserBean user, Session txSession) { |
|
153 |
return addUser(appAccessId, hashedSecretKey, user, txSession, true); |
|
153 |
public int addUser( |
|
154 |
String appAccessId, String hashedSecretKey, MinimalUserBean user, |
|
155 |
char accessType, Session txSession) { |
|
156 |
|
|
157 |
return addUser(appAccessId, hashedSecretKey, user, accessType, txSession, true); |
|
154 | 158 |
} |
155 | 159 |
|
156 |
public int addUser(String appAccessId, String hashedSecretKey, MinimalUserBean user, Session txSession, |
|
157 |
boolean checkPassword) { |
|
160 |
public int addUser( |
|
161 |
String appAccessId, String hashedSecretKey, MinimalUserBean user, |
|
162 |
char accessType, Session txSession, boolean checkPassword) { |
|
158 | 163 |
|
159 | 164 |
final String userAlias = user.getUserAlias(); |
160 | 165 |
final String doubleHashedPassword = user.getPcipherText(); |
... | ... | |
173 | 178 |
else { |
174 | 179 |
user.setUserType(MinimalConstants.UTYPE_STATE_USER); |
175 | 180 |
user.setPstate(MinimalConstants.UID_STATE_ACTIVE); |
176 |
rc = createUserService.addUser(user, appId.intValue(), txSession, checkPassword); |
|
181 |
rc = createUserService.addUser( |
|
182 |
user, appId.intValue(), accessType, txSession, checkPassword); |
|
177 | 183 |
} |
178 | 184 |
|
179 | 185 |
} catch (MultipleAppAccessesFound e) { |
... | ... | |
419 | 425 |
return appId; |
420 | 426 |
} |
421 | 427 |
|
422 |
public UserProfile findProfile(String appAccessId, String hashedSecretKey, String username, Session txSession) |
|
428 |
public UserProfile findProfile( |
|
429 |
String appAccessId, String hashedSecretKey, String username, Session txSession) |
|
423 | 430 |
throws UPassException { |
424 | 431 |
|
425 | 432 |
try { |
... | ... | |
444 | 451 |
return null; |
445 | 452 |
} |
446 | 453 |
} catch (MultipleAppAccessesFound e) { |
447 |
throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED); |
|
454 |
throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED, e);
|
|
448 | 455 |
} |
449 | 456 |
} |
450 | 457 |
|
src/main/java/my/com/upass/UPassException.java | ||
---|---|---|
7 | 7 |
private final int errorCode; |
8 | 8 |
|
9 | 9 |
public UPassException(int errorCode) { |
10 |
this(errorCode, null); |
|
11 |
} |
|
12 |
|
|
13 |
public UPassException(int errorCode, Throwable cause) { |
|
14 |
super(cause); |
|
10 | 15 |
this.errorCode = errorCode; |
11 | 16 |
} |
12 | 17 |
|
src/main/java/my/com/upass/dao/UserDAO.java | ||
---|---|---|
75 | 75 |
|
76 | 76 |
boolean updateUserToStore(MinimalUserBean MinimalUserBean, final Session txSession) throws Exception; |
77 | 77 |
|
78 |
List/*<UserProfile>*/ listProfilesFor(String username, final Session txSession) throws Exception; |
|
78 |
List/* <UserProfile> */listProfilesFor( |
|
79 |
String username, final Session txSession) throws Exception; |
|
80 |
|
|
81 |
List/* <UserProfile> */listProfilesByExamples( |
|
82 |
List/* <UserProfile> */exampleProfiles, final Session txSession) |
|
83 |
throws Exception; |
|
79 | 84 |
} |
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java | ||
---|---|---|
12 | 12 |
package my.com.upass.dao.hibernate; |
13 | 13 |
|
14 | 14 |
import java.util.ArrayList; |
15 |
import java.util.Iterator; |
|
15 | 16 |
import java.util.List; |
16 | 17 |
|
17 | 18 |
import my.com.upass.MinimalConstants; |
18 | 19 |
import my.com.upass.dao.UserDAO; |
20 |
import my.com.upass.maybank.entities.Im2uUser; |
|
21 |
import my.com.upass.maybank.entities.StockUser; |
|
19 | 22 |
import my.com.upass.maybank.entities.UserProfile; |
20 | 23 |
import my.com.upass.pojo.MinimalUserBean; |
21 | 24 |
import my.com.upass.pojo.MinimalUserBeanBackup; |
... | ... | |
29 | 32 |
import org.hibernate.FetchMode; |
30 | 33 |
import org.hibernate.Query; |
31 | 34 |
import org.hibernate.Session; |
35 |
import org.hibernate.criterion.Example; |
|
32 | 36 |
import org.hibernate.criterion.Restrictions; |
33 | 37 |
|
34 | 38 |
/** |
... | ... | |
478 | 482 |
} |
479 | 483 |
return profiles; |
480 | 484 |
} |
485 |
|
|
486 |
public List/* <UserProfile> */listProfilesByExamples( |
|
487 |
List/* <UserProfile> */exampleProfiles, Session txSession) |
|
488 |
throws Exception { |
|
489 |
|
|
490 |
List profiles = new ArrayList(5); |
|
491 |
Session session = null; |
|
492 |
try { |
|
493 |
session = txSession != null ? txSession : getSession(); |
|
494 |
|
|
495 |
for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) { |
|
496 |
UserProfile example = (UserProfile) iter.next(); |
|
497 |
|
|
498 |
Criteria c = session.createCriteria(example.getClass()) |
|
499 |
.add(Example.create(example).ignoreCase().enableLike()); |
|
500 |
|
|
501 |
final String username = example.getMinUser().getUsername(); |
|
502 |
if (username != null) { |
|
503 |
final String MU = "mu"; |
|
504 |
if (example instanceof StockUser || example instanceof Im2uUser) { |
|
505 |
c.createAlias("m2uUser", "m2u"); |
|
506 |
c.createAlias("m2u.minUser", MU); |
|
507 |
|
|
508 |
} else { |
|
509 |
c.createAlias("minUser", MU); |
|
510 |
} |
|
511 |
c.add(Restrictions.ilike(MU + ".userAlias", username)); |
|
512 |
} |
|
513 |
profiles.addAll(c.list()); |
|
514 |
} |
|
515 |
} finally { |
|
516 |
if (txSession == null) |
|
517 |
closeSessionIfAny(session); |
|
518 |
} |
|
519 |
return profiles; |
|
520 |
} |
|
481 | 521 |
} |
src/main/java/my/com/upass/maybank/MinimalMaybankFacadeImpl.java | ||
---|---|---|
8 | 8 |
import my.com.upass.maybank.entities.M2uUser; |
9 | 9 |
import my.com.upass.maybank.entities.UserProfile; |
10 | 10 |
import my.com.upass.pojo.MinimalUserBean; |
11 |
import my.com.upass.pojo.UserAppAccess; |
|
11 | 12 |
import net.penril.generic.hibernate.GenericDAOHibernate; |
12 | 13 |
import net.penril.generic.hibernate.HibernateUtils; |
13 | 14 |
|
14 |
import org.apache.commons.lang.NotImplementedException; |
|
15 | 15 |
import org.apache.log4j.Logger; |
16 | 16 |
import org.hibernate.Session; |
17 | 17 |
|
... | ... | |
71 | 71 |
String appAccessId, String hashedSecretKey, |
72 | 72 |
String username, String pan1) { |
73 | 73 |
|
74 |
throw new NotImplementedException(); |
|
75 |
// return minUpcV2.updateProfileShallowly( |
|
76 |
// appAccessId, hashedSecretKey, "", null); |
|
74 |
return changePans(appAccessId, hashedSecretKey, username, pan1, null); |
|
77 | 75 |
} |
78 | 76 |
|
79 | 77 |
public int changePan2( |
80 | 78 |
String appAccessId, String hashedSecretKey, |
81 | 79 |
String username, String pan2) { |
82 | 80 |
|
83 |
// TODO Auto-generated method stub |
|
84 |
throw new NotImplementedException(); |
|
81 |
return changePans(appAccessId, hashedSecretKey, username, null, pan2); |
|
85 | 82 |
} |
86 | 83 |
|
87 | 84 |
public Response lookupUsername_internal( |
... | ... | |
104 | 101 |
} catch (UPassException e) { |
105 | 102 |
LOGGER.info(e, e); |
106 | 103 |
res.setCode(e.getErrorCode()); |
107 |
|
|
104 |
|
|
108 | 105 |
} catch (Exception e) { |
109 | 106 |
LOGGER.error(e, e); |
110 | 107 |
res.setCode(MinimalConstants.ERR_UNKNOWN); |
... | ... | |
126 | 123 |
session = HibernateUtils.currentSession(); |
127 | 124 |
session.beginTransaction(); |
128 | 125 |
|
129 |
rc = minUpcV2.addUser(appAccessId, hashedSecretKey, profile.getMinUser(), session); |
|
126 |
rc = minUpcV2.addUser( |
|
127 |
appAccessId, hashedSecretKey, profile.getMinUser(), UserAppAccess.TYPE_USER, session); |
|
130 | 128 |
|
131 | 129 |
if (rc == MinimalConstants.ERR_SUCCESS) { |
132 | 130 |
rc = minUpcV2.updateProfileShallowly(appAccessId, hashedSecretKey, profile, session); |
... | ... | |
144 | 142 |
} |
145 | 143 |
return rc; |
146 | 144 |
} |
145 |
|
|
146 |
/** |
|
147 |
* It will update pan1 and pan2, but only if they are not null. |
|
148 |
* That is, null values will be ignored. |
|
149 |
*/ |
|
150 |
protected int changePans( |
|
151 |
String appAccessId, String hashedSecretKey, |
|
152 |
String username, String pan1, String pan2) { |
|
153 |
|
|
154 |
Session session = null; |
|
155 |
try { |
|
156 |
session = HibernateUtils.currentSession(); |
|
157 |
session.beginTransaction(); |
|
158 |
|
|
159 |
UserProfile profile = minUpcV2.findProfile( |
|
160 |
appAccessId, hashedSecretKey, username, session); |
|
161 |
|
|
162 |
if (profile instanceof M2uUser) { |
|
163 |
|
|
164 |
M2uUser m2uUser = (M2uUser) profile; |
|
165 |
|
|
166 |
if (pan1 != null) |
|
167 |
m2uUser.setPan1(pan1); |
|
168 |
|
|
169 |
if (pan2 != null) |
|
170 |
m2uUser.setPan1(pan2); |
|
171 |
|
|
172 |
int rc = minUpcV2.updateProfileShallowly( |
|
173 |
appAccessId, hashedSecretKey, m2uUser, session); |
|
174 |
|
|
175 |
session.getTransaction().commit(); |
|
176 |
return rc; |
|
177 |
|
|
178 |
} else { |
|
179 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
180 |
return MinimalConstants.ERR_APP_SERV_NOT_PERMITTED; |
|
181 |
} |
|
182 |
} catch (UPassException e) { |
|
183 |
LOGGER.info(e, e); |
|
184 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
185 |
return e.getErrorCode(); |
|
186 |
|
|
187 |
} catch (Exception e) { |
|
188 |
LOGGER.error(e, e); |
|
189 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
190 |
return MinimalConstants.ERR_UNKNOWN; |
|
191 |
|
|
192 |
} finally { |
|
193 |
GenericDAOHibernate.closeSessionIfAny(session); |
|
194 |
} |
|
195 |
} |
|
147 | 196 |
} |
src/main/java/my/com/upass/maybank/entities/IbccUser.java | ||
---|---|---|
15 | 15 |
|
16 | 16 |
// |
17 | 17 |
|
18 |
public IbccUser() { |
|
19 |
minUser = new MinimalUserBean(); |
|
20 |
} |
|
21 |
|
|
18 | 22 |
public String getPanCc() { |
19 | 23 |
return panCc; |
20 | 24 |
} |
... | ... | |
47 | 51 |
map.put("panCc", panCc); |
48 | 52 |
return map; |
49 | 53 |
} |
54 |
|
|
55 |
public void mapToProperties(Map map) { |
|
56 |
final String username = (String) map.get("username"); |
|
57 |
minUser.setUsername(username); |
|
58 |
setPanCc((String) map.get("panCc")); |
|
59 |
} |
|
50 | 60 |
} |
src/main/java/my/com/upass/maybank/entities/Im2uUser.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
// |
21 | 21 |
|
22 |
public Im2uUser() { |
|
23 |
m2uUser = new M2uUser(); |
|
24 |
} |
|
25 |
|
|
22 | 26 |
public String getWsFlag() { |
23 | 27 |
return wsFlag; |
24 | 28 |
} |
... | ... | |
89 | 93 |
return map; |
90 | 94 |
} |
91 | 95 |
|
96 |
public void mapToProperties(Map map) { |
|
97 |
m2uUser.mapToProperties(map); |
|
98 |
wsFlag = (String) map.get("wsFlag"); |
|
99 |
wsIdentCode = (String) map.get("wsIdentCode"); |
|
100 |
wsMySgId = (String) map.get("wsMySgId"); |
|
101 |
wsRegTimeStamp = (Date) map.get("wsRegTimeStamp"); |
|
102 |
} |
|
103 |
|
|
92 | 104 |
} |
src/main/java/my/com/upass/maybank/entities/M2uUser.java | ||
---|---|---|
15 | 15 |
private String pan2; |
16 | 16 |
|
17 | 17 |
// |
18 |
|
|
19 |
public M2uUser() { |
|
20 |
minUser = new MinimalUserBean(); |
|
21 |
} |
|
18 | 22 |
|
19 | 23 |
public String getPan1() { |
20 | 24 |
return pan1; |
... | ... | |
58 | 62 |
map.put("username", minUser.getUsername()); |
59 | 63 |
return map; |
60 | 64 |
} |
65 |
|
|
66 |
public void mapToProperties(Map map) { |
|
67 |
final String username = (String) map.get("username"); |
|
68 |
minUser.setUsername(username); |
|
69 |
setPan1((String) map.get("pan1")); |
|
70 |
setPan2((String) map.get("pan2")); |
|
71 |
} |
|
61 | 72 |
} |
src/main/java/my/com/upass/maybank/entities/StockUser.java | ||
---|---|---|
15 | 15 |
|
16 | 16 |
// |
17 | 17 |
|
18 |
public StockUser() { |
|
19 |
m2uUser = new M2uUser(); |
|
20 |
} |
|
21 |
|
|
18 | 22 |
public String getIdNo() { |
19 | 23 |
return idNo; |
20 | 24 |
} |
... | ... | |
57 | 61 |
map.putAll(m2uUser.propertiesToMap()); |
58 | 62 |
return map; |
59 | 63 |
} |
64 |
|
|
65 |
public void mapToProperties(Map map) { |
|
66 |
m2uUser.mapToProperties(map); |
|
67 |
idNo = (String) map.get("idNo"); |
|
68 |
} |
|
60 | 69 |
} |
src/main/java/my/com/upass/maybank/entities/TicketingUser.java | ||
---|---|---|
17 | 17 |
private String payeeCode; |
18 | 18 |
|
19 | 19 |
// |
20 |
|
|
21 |
public TicketingUser() { |
|
22 |
minUser = new MinimalUserBean(); |
|
23 |
} |
|
20 | 24 |
|
21 | 25 |
public String getFullName() { |
22 | 26 |
return fullName; |
... | ... | |
77 | 81 |
map.put("username", minUser.getUsername()); |
78 | 82 |
return map; |
79 | 83 |
} |
84 |
|
|
85 |
public void mapToProperties(Map map) { |
|
86 |
final String username = (String) map.get("username"); |
|
87 |
minUser.setUsername(username); |
|
88 |
fullName = (String) map.get("fullName"); |
|
89 |
firstName = (String) map.get("firstName"); |
|
90 |
lastName = (String) map.get("lastName"); |
|
91 |
payeeCode = (String) map.get("payeeCode"); |
|
92 |
} |
|
80 | 93 |
} |
src/main/java/my/com/upass/maybank/entities/UserProfile.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
void setMinUser(MinimalUserBean maybankUser); |
13 | 13 |
|
14 |
Map propertiesToMap(); |
|
14 |
Map/* <String, Object */propertiesToMap(); |
|
15 |
|
|
16 |
void mapToProperties(Map/* <String, Object> */map); |
|
15 | 17 |
} |
src/main/java/my/com/upass/services/CreateUserService.java | ||
---|---|---|
47 | 47 |
|
48 | 48 |
public int addUser( |
49 | 49 |
String userAlias, int userType, String userDesc, |
50 |
String userPassword, int userState, int applicationId, Session txSession, boolean checkPassword) { |
|
50 |
String userPassword, int userState, int applicationId, |
|
51 |
char accessType, Session txSession, boolean checkPassword) { |
|
51 | 52 |
|
52 | 53 |
int rc = MinimalConstants.ERR_SYSTEM_NOT_READY; |
53 | 54 |
|
54 | 55 |
if (userAlias == null) { |
55 | 56 |
return MinimalConstants.ERR_INVALID_INPUT; |
56 | 57 |
} |
57 |
|
|
58 |
if(checkPassword && userPassword == null){
|
|
58 |
|
|
59 |
if (checkPassword && userPassword == null) {
|
|
59 | 60 |
return MinimalConstants.ERR_INVALID_INPUT; |
60 | 61 |
} |
61 |
|
|
62 |
|
|
62 | 63 |
UserDAO userDao; |
63 | 64 |
try { |
64 | 65 |
userDao = MinimalDAOFactory.minimalInstance().getUserDAO(); |
... | ... | |
76 | 77 |
ub.setUstate(userState); |
77 | 78 |
ub.setUdateCreated(new Date()); |
78 | 79 |
ub.setPdateCreated(new Date()); |
79 |
//ub.setApplicationId(new Integer(applicationId)); //has been moved to UserAppAccess |
|
80 |
// ub.setApplicationId(new Integer(applicationId)); //has been moved to UserAppAccess
|
|
80 | 81 |
|
81 | 82 |
PasswordController pc = MinimalUPassFactory.getPasswordController(ub, |
82 | 83 |
upc.getConfigurationsMap()); |
... | ... | |
86 | 87 |
return rc; |
87 | 88 |
} |
88 | 89 |
|
89 |
if(checkPassword){
|
|
90 |
if (checkPassword) {
|
|
90 | 91 |
rc = pc.GeneratePassword(userPassword, true); |
91 |
|
|
92 |
|
|
92 | 93 |
if (rc != MinimalConstants.ERR_SUCCESS) { |
93 | 94 |
return rc; |
94 | 95 |
} |
95 | 96 |
} |
96 |
|
|
97 |
|
|
97 | 98 |
ub = (MinimalUserBean) pc.getUpdatedObject(); |
98 | 99 |
|
99 | 100 |
// UserMasterBean master = new UserMasterBean (); |
... | ... | |
110 | 111 |
UserAppAccess access = new UserAppAccess(); |
111 | 112 |
access.setUserId(nextVal); |
112 | 113 |
access.setAppId(applicationId); |
113 |
access.setAccessType(UserAppAccess.TYPE_USER);
|
|
114 |
access.setAccessType(accessType);
|
|
114 | 115 |
access.setRegistrationTime(new Date()); |
115 | 116 |
|
116 | 117 |
userDao.addUserAppAccess(access, txSession); |
... | ... | |
132 | 133 |
public int addUser( |
133 | 134 |
String userAlias, int userType, String userDesc, |
134 | 135 |
String userPassword, int userState, int applicationId, Session txSession) { |
135 |
return addUser(userAlias, userType, userDesc, userPassword, userState, applicationId, txSession, true); |
|
136 |
|
|
137 |
final char notApplicable = '\0'; |
|
138 |
return addUser( |
|
139 |
userAlias, userType, userDesc, userPassword, userState, |
|
140 |
applicationId, notApplicable, txSession, true); |
|
136 | 141 |
} |
137 |
|
|
142 |
|
|
138 | 143 |
public int addUser( |
139 | 144 |
String userAlias, int userType, String userDesc, |
140 | 145 |
String userPassword, int userState, int applicationId) { |
... | ... | |
142 | 147 |
return addUser(userAlias, userType, userDesc, userPassword, userState, applicationId, null); |
143 | 148 |
} |
144 | 149 |
|
145 |
public int addUser(MinimalUserBean user, int appId, Session txSession, boolean checkPassword) { |
|
150 |
public int addUser( |
|
151 |
MinimalUserBean user, int appId, char accessType, |
|
152 |
Session txSession, boolean checkPassword) { |
|
153 |
|
|
146 | 154 |
return addUser( |
147 | 155 |
user.getUserAlias(), user.getUserType(), user.getDescription(), |
148 |
user.getPcipherText(), user.getPstate(), appId, txSession, checkPassword); |
|
156 |
user.getPcipherText(), user.getPstate(), appId, |
|
157 |
accessType, txSession, checkPassword); |
|
149 | 158 |
} |
150 | 159 |
} |
src/main/java/my/com/upass/services/ModifyUserService.java | ||
---|---|---|
155 | 155 |
return rc; |
156 | 156 |
} |
157 | 157 |
|
158 |
public List/* <UserProfile> */listProfiles(String username, Session txSession) throws UPassException { |
|
158 |
public List/* <UserProfile> */listProfiles( |
|
159 |
String username, Session txSession) throws UPassException { |
|
159 | 160 |
|
160 | 161 |
// int rc = MinimalConstants.ERR_SYSTEM_NOT_READY; |
161 | 162 |
if (username == null) { |
... | ... | |
175 | 176 |
} |
176 | 177 |
return null; |
177 | 178 |
} |
179 |
|
|
180 |
public List/* <UserProfile> */listProfilesByExamples( |
|
181 |
List/* <UserProfile> */exampleProfiles, Session txSession) throws UPassException { |
|
182 |
|
|
183 |
// int rc = MinimalConstants.ERR_SYSTEM_NOT_READY; |
|
184 |
if (exampleProfiles == null) { |
|
185 |
throw new UPassException(MinimalConstants.ERR_INVALID_INPUT); |
|
186 |
} |
|
187 |
try { |
|
188 |
UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO(); |
|
189 |
return userDao.listProfilesByExamples(exampleProfiles, txSession); |
|
190 |
|
|
191 |
} catch (Exception e) { |
|
192 |
if (e instanceof UPassException) { |
|
193 |
UPassException upassEx = (UPassException) e; |
|
194 |
throw upassEx; |
|
195 |
|
|
196 |
} else |
|
197 |
e.printStackTrace(); |
|
198 |
} |
|
199 |
return null; |
|
200 |
} |
|
201 |
|
|
178 | 202 |
} |
Also available in: Unified diff