Revision 52:d41114597ce0
src/main/java/my/com/upass/ConfigBean.java | ||
---|---|---|
18 | 18 |
* |
19 | 19 |
*/ |
20 | 20 |
public class ConfigBean { |
21 |
|
|
22 |
/** |
|
23 |
* @see #MIGRATION_PERIOD |
|
24 |
*/ |
|
25 |
private boolean inMigrationPeriod = false; |
|
26 |
|
|
21 | 27 |
// password controller |
22 | 28 |
int passwordMaxTryError = 3; // maximum allowable password error encountered per user |
23 | 29 |
int passwordMaxReuse = 6; // number of password non repeatable |
... | ... | |
40 | 46 |
int passwordComplexitySymbol = 0; |
41 | 47 |
int passwordComplexityUpperAlpha = 0; |
42 | 48 |
|
49 |
/** |
|
50 |
* This property can be set to 'Y' or 'N' in configurations, |
|
51 |
* but will be converted to boolean inside the app. |
|
52 |
* |
|
53 |
* @see #inMigrationPeriod |
|
54 |
*/ |
|
55 |
private static final String MIGRATION_PERIOD = "MIGRATION_PERIOD"; |
|
56 |
|
|
43 | 57 |
static String PASSWORD_MAX_ERROR = "PASSWORD_MAX_ERROR"; |
44 | 58 |
static String PASSWORD_GENERATION = "PASSWORD_GENERATION"; |
45 | 59 |
static String PASSWORD_EXPIRY_DAY = "PASSWORD_EXPIRY_DAY"; |
... | ... | |
84 | 98 |
static String SC_LIFTSPAN_TIMEOUT = "SC_LIFTSPAN_TIMEOUT"; |
85 | 99 |
static String SC_REPEAT_TIMEOUT = "SC_REPEAT_TIMEOUT"; |
86 | 100 |
|
87 |
public void setConfigBean(String paramName, String paramValue) |
|
88 |
{ |
|
101 |
public void setConfigBean(String paramName, String paramValue) {
|
|
102 |
|
|
89 | 103 |
if (PASSWORD_MAX_ERROR.equalsIgnoreCase(paramName)) { |
90 | 104 |
this.setPasswordMaxTryError(Integer.parseInt(paramValue)); |
91 |
} |
|
92 |
else if (PASSWORD_GENERATION.equalsIgnoreCase(paramName)) { |
|
105 |
|
|
106 |
} else if (PASSWORD_GENERATION.equalsIgnoreCase(paramName)) {
|
|
93 | 107 |
this.setPasswordMaxReuse(Integer.parseInt(paramValue)); |
94 |
} |
|
95 |
else if (PASSWORD_EXPIRY_DAY.equalsIgnoreCase(paramName)) { |
|
108 |
|
|
109 |
} else if (PASSWORD_EXPIRY_DAY.equalsIgnoreCase(paramName)) {
|
|
96 | 110 |
this.setPasswordExpiry(Integer.parseInt(paramValue)); |
97 |
} |
|
98 |
else if (PASSWORD_PATTERN.equalsIgnoreCase(paramName)) { |
|
111 |
|
|
112 |
} else if (PASSWORD_PATTERN.equalsIgnoreCase(paramName)) {
|
|
99 | 113 |
this.setPasswordValidPattern(paramValue); |
100 |
} |
|
101 |
else if (USERNAME_PATTERN.equalsIgnoreCase(paramName)) { |
|
114 |
|
|
115 |
} else if (USERNAME_PATTERN.equalsIgnoreCase(paramName)) {
|
|
102 | 116 |
this.setUserNameValidPattern(paramValue); |
103 |
} |
|
104 |
else if (USER_DORMANT_PERIOD.equalsIgnoreCase(paramName)) { |
|
117 |
|
|
118 |
} else if (USER_DORMANT_PERIOD.equalsIgnoreCase(paramName)) {
|
|
105 | 119 |
this.setUserDormantPeriod(Integer.parseInt(paramValue)); |
106 |
} |
|
107 |
else if (PASSWORD_MIN_LENGTH.equalsIgnoreCase(paramName)) { |
|
120 |
|
|
121 |
} else if (PASSWORD_MIN_LENGTH.equalsIgnoreCase(paramName)) {
|
|
108 | 122 |
this.setPasswordMinLength(Integer.parseInt(paramValue)); |
109 |
} |
|
110 |
else if (NOTIF_ALERT.equalsIgnoreCase(paramName)) { |
|
123 |
|
|
124 |
} else if (NOTIF_ALERT.equalsIgnoreCase(paramName)) {
|
|
111 | 125 |
this.setNotifAlert(Integer.parseInt(paramValue)); |
112 |
} |
|
113 |
else if (CHANGE_PASSWORD_INTERVAL.equalsIgnoreCase(paramName)) { |
|
126 |
|
|
127 |
} else if (CHANGE_PASSWORD_INTERVAL.equalsIgnoreCase(paramName)) {
|
|
114 | 128 |
this.setChangePasswordInterval(Integer.parseInt(paramValue)); |
115 |
} |
|
116 |
else if (PASSWORD_ACCEPT_PATTERN.equalsIgnoreCase(paramName)) { |
|
129 |
|
|
130 |
} else if (PASSWORD_ACCEPT_PATTERN.equalsIgnoreCase(paramName)) {
|
|
117 | 131 |
this.setPasswordAcceptPattern(paramValue); |
118 |
} |
|
119 |
else if (PASSWORD_COMPLEXITY.equalsIgnoreCase(paramName)) { |
|
132 |
|
|
133 |
} else if (PASSWORD_COMPLEXITY.equalsIgnoreCase(paramName)) {
|
|
120 | 134 |
this.setPasswordComplexity(Integer.parseInt(paramValue)); |
121 |
} |
|
122 |
else if (PASSWORD_COMPLEXITY_LOWER_ALPHA.equalsIgnoreCase(paramName)) { |
|
135 |
|
|
136 |
} else if (PASSWORD_COMPLEXITY_LOWER_ALPHA.equalsIgnoreCase(paramName)) {
|
|
123 | 137 |
this.setPasswordComplexityLowerAlpha(Integer.parseInt(paramValue)); |
124 |
} |
|
125 |
else if (PASSWORD_COMPLEXITY_NUMERIC.equalsIgnoreCase(paramName)) { |
|
138 |
|
|
139 |
} else if (PASSWORD_COMPLEXITY_NUMERIC.equalsIgnoreCase(paramName)) {
|
|
126 | 140 |
this.setPasswordComplexityNumeric(Integer.parseInt(paramValue)); |
127 |
} |
|
128 |
else if (PASSWORD_COMPLEXITY_SYMBOL.equalsIgnoreCase(paramName)) { |
|
141 |
|
|
142 |
} else if (PASSWORD_COMPLEXITY_SYMBOL.equalsIgnoreCase(paramName)) {
|
|
129 | 143 |
this.setPasswordComplexitySymbol(Integer.parseInt(paramValue)); |
130 |
} |
|
131 |
else if (PASSWORD_COMPLEXITY_UPPER_ALPHA.equalsIgnoreCase(paramName)) { |
|
144 |
|
|
145 |
} else if (PASSWORD_COMPLEXITY_UPPER_ALPHA.equalsIgnoreCase(paramName)) {
|
|
132 | 146 |
this.setPasswordComplexityUpperAlpha(Integer.parseInt(paramValue)); |
133 |
} |
|
134 |
else if (AUTO_LOGOFF.equalsIgnoreCase(paramName)) { |
|
147 |
|
|
148 |
} else if (AUTO_LOGOFF.equalsIgnoreCase(paramName)) {
|
|
135 | 149 |
this.setAutoLogoff(Integer.parseInt(paramValue)); |
136 |
} |
|
137 |
else if (USER_DEACTIVATE_PERIOD.equalsIgnoreCase(paramName)) { |
|
150 |
|
|
151 |
} else if (USER_DEACTIVATE_PERIOD.equalsIgnoreCase(paramName)) {
|
|
138 | 152 |
this.setUserDeactivatePeriod(Integer.parseInt(paramValue)); |
139 |
} |
|
140 |
else if (SINGLE_SIGNON.equalsIgnoreCase(paramName)) { |
|
153 |
|
|
154 |
} else if (SINGLE_SIGNON.equalsIgnoreCase(paramName)) {
|
|
141 | 155 |
this.setSingleSingon(Integer.parseInt(paramValue)); |
142 |
} |
|
143 | 156 |
|
144 |
else if (TAC_TIME_OUT.equalsIgnoreCase(paramName)) { |
|
157 |
} else if (TAC_TIME_OUT.equalsIgnoreCase(paramName)) {
|
|
145 | 158 |
this.setTACTTimeOut(Integer.parseInt(paramValue)); |
146 |
} |
|
147 |
else if (TAC_MAX_ERROR.equalsIgnoreCase(paramName)) { |
|
159 |
|
|
160 |
} else if (TAC_MAX_ERROR.equalsIgnoreCase(paramName)) {
|
|
148 | 161 |
this.setTACMaxTryError(Integer.parseInt(paramValue)); |
149 |
} |
|
150 |
else if (TAC_MAX_USE.equalsIgnoreCase(paramName)) { |
|
162 |
|
|
163 |
} else if (TAC_MAX_USE.equalsIgnoreCase(paramName)) {
|
|
151 | 164 |
this.setTACMaxUse(Integer.parseInt(paramValue)); |
152 |
} |
|
153 |
else if (TAC_LIFTSPAN_TIMEOUT.equalsIgnoreCase(paramName)) { |
|
165 |
|
|
166 |
} else if (TAC_LIFTSPAN_TIMEOUT.equalsIgnoreCase(paramName)) {
|
|
154 | 167 |
this.setTACLifeSpanTimeOut(Integer.parseInt(paramValue)); |
155 |
} |
|
156 |
else if (TAC_REPEAT_TIMEOUT.equalsIgnoreCase(paramName)) { |
|
168 |
|
|
169 |
} else if (TAC_REPEAT_TIMEOUT.equalsIgnoreCase(paramName)) {
|
|
157 | 170 |
this.setTACRepeatTimeOut(Integer.parseInt(paramValue)); |
158 |
} |
|
159 | 171 |
|
160 |
else if (SC_TIME_OUT.equalsIgnoreCase(paramName)) { |
|
172 |
} else if (SC_TIME_OUT.equalsIgnoreCase(paramName)) {
|
|
161 | 173 |
this.setSCTimeOut(Integer.parseInt(paramValue)); |
162 |
} |
|
163 |
else if (SC_MAX_ERROR.equalsIgnoreCase(paramName)) { |
|
174 |
|
|
175 |
} else if (SC_MAX_ERROR.equalsIgnoreCase(paramName)) {
|
|
164 | 176 |
this.setSCMaxError(Integer.parseInt(paramValue)); |
165 |
} |
|
166 |
else if (SC_MAX_USE.equalsIgnoreCase(paramName)) { |
|
177 |
|
|
178 |
} else if (SC_MAX_USE.equalsIgnoreCase(paramName)) {
|
|
167 | 179 |
this.setSCMaxUse(Integer.parseInt(paramValue)); |
168 |
} |
|
169 |
else if (SC_LIFTSPAN_TIMEOUT.equalsIgnoreCase(paramName)) { |
|
180 |
|
|
181 |
} else if (SC_LIFTSPAN_TIMEOUT.equalsIgnoreCase(paramName)) {
|
|
170 | 182 |
this.setSCLifeSpanTimeOut(Integer.parseInt(paramValue)); |
171 |
} |
|
172 |
else if (SC_REPEAT_TIMEOUT.equalsIgnoreCase(paramName)) { |
|
183 |
|
|
184 |
} else if (SC_REPEAT_TIMEOUT.equalsIgnoreCase(paramName)) {
|
|
173 | 185 |
this.setSCRepeatTimeOut(Integer.parseInt(paramValue)); |
186 |
|
|
187 |
} else if (MIGRATION_PERIOD.equals(paramName)) { |
|
188 |
this.setInMigrationPeriod("Y".equals(paramValue)); |
|
174 | 189 |
} |
175 | 190 |
} |
176 | 191 |
|
177 | 192 |
/* ======================getter setter for TAC Controller======================= */ |
193 |
|
|
178 | 194 |
public int getTACMaxTryError() { |
179 | 195 |
return TACMaxTryError; |
180 | 196 |
} |
... | ... | |
251 | 267 |
} |
252 | 268 |
|
253 | 269 |
/* ======================getter setter for password Controller======================= */ |
270 |
|
|
254 | 271 |
public int getPasswordMaxTryError() { |
255 | 272 |
return passwordMaxTryError; |
256 | 273 |
} |
... | ... | |
426 | 443 |
} |
427 | 444 |
|
428 | 445 |
/* ======================getter setter for SC Controller======================= */ |
429 |
/** |
|
430 |
* @return the sCTimeOut |
|
431 |
*/ |
|
432 |
public int getSCTimeOut() |
|
433 |
{ |
|
446 |
|
|
447 |
public int getSCTimeOut() { |
|
434 | 448 |
return SCTimeOut; |
435 | 449 |
} |
436 | 450 |
|
437 |
/** |
|
438 |
* @param sCTimeOut |
|
439 |
* the sCTimeOut to set |
|
440 |
*/ |
|
441 |
public void setSCTimeOut(int sCTimeOut) |
|
442 |
{ |
|
451 |
public void setSCTimeOut(int sCTimeOut) { |
|
443 | 452 |
SCTimeOut = sCTimeOut; |
444 | 453 |
} |
445 | 454 |
|
446 |
/** |
|
447 |
* @return the sCMaxError |
|
448 |
*/ |
|
449 |
public int getSCMaxError() |
|
450 |
{ |
|
455 |
public int getSCMaxError() { |
|
451 | 456 |
return SCMaxError; |
452 | 457 |
} |
453 | 458 |
|
454 |
/** |
|
455 |
* @param sCMaxError |
|
456 |
* the sCMaxError to set |
|
457 |
*/ |
|
458 |
public void setSCMaxError(int sCMaxError) |
|
459 |
{ |
|
459 |
public void setSCMaxError(int sCMaxError) { |
|
460 | 460 |
SCMaxError = sCMaxError; |
461 | 461 |
} |
462 | 462 |
|
463 |
/** |
|
464 |
* @return the sCMaxUser |
|
465 |
*/ |
|
466 |
public int getSCMaxUse() |
|
467 |
{ |
|
463 |
public int getSCMaxUse() { |
|
468 | 464 |
return SCMaxUse; |
469 | 465 |
} |
470 | 466 |
|
471 |
/** |
|
472 |
* @param sCMaxUse |
|
473 |
* the sCMaxUse to set |
|
474 |
*/ |
|
475 |
public void setSCMaxUse(int sCMaxUse) |
|
476 |
{ |
|
467 |
public void setSCMaxUse(int sCMaxUse) { |
|
477 | 468 |
SCMaxUse = sCMaxUse; |
478 | 469 |
} |
479 | 470 |
|
480 |
/** |
|
481 |
* @return the sCLifeSpanTimeOut |
|
482 |
*/ |
|
483 |
public int getSCLifeSpanTimeOut() |
|
484 |
{ |
|
471 |
public int getSCLifeSpanTimeOut() { |
|
485 | 472 |
return SCLifeSpanTimeOut; |
486 | 473 |
} |
487 | 474 |
|
488 |
/** |
|
489 |
* @param sCLifeSpanTimeOut |
|
490 |
* the sCLifeSpanTimeOut to set |
|
491 |
*/ |
|
492 |
public void setSCLifeSpanTimeOut(int sCLifeSpanTimeOut) |
|
493 |
{ |
|
475 |
public void setSCLifeSpanTimeOut(int sCLifeSpanTimeOut) { |
|
494 | 476 |
SCLifeSpanTimeOut = sCLifeSpanTimeOut; |
495 | 477 |
} |
496 | 478 |
|
497 |
/** |
|
498 |
* @return the sCRepeatTimeOut |
|
499 |
*/ |
|
500 |
public int getSCRepeatTimeOut() |
|
501 |
{ |
|
479 |
public int getSCRepeatTimeOut() { |
|
502 | 480 |
return SCRepeatTimeOut; |
503 | 481 |
} |
504 | 482 |
|
505 |
/** |
|
506 |
* @param sCRepeatTimeOut |
|
507 |
* the sCRepeatTimeOut to set |
|
508 |
*/ |
|
509 |
public void setSCRepeatTimeOut(int sCRepeatTimeOut) |
|
510 |
{ |
|
483 |
public void setSCRepeatTimeOut(int sCRepeatTimeOut) { |
|
511 | 484 |
SCRepeatTimeOut = sCRepeatTimeOut; |
512 | 485 |
} |
486 |
|
|
487 |
public boolean isInMigrationPeriod() { |
|
488 |
return inMigrationPeriod; |
|
489 |
} |
|
490 |
|
|
491 |
public void setInMigrationPeriod(boolean inMigrationPeriod) { |
|
492 |
this.inMigrationPeriod = inMigrationPeriod; |
|
493 |
} |
|
513 | 494 |
} |
src/main/java/my/com/upass/MinimalConstants.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
public class MinimalConstants { |
9 | 9 |
|
10 |
public static final String PROP_MIGRATION_PERIOD_FLAG = "MIGRATION_PERIOD"; |
|
11 |
|
|
12 | 10 |
public static final int ERR_SUCCESS = 0; |
13 | 11 |
public static final int ERR_INVALID_USERALIAS = 16; |
14 | 12 |
public static final int ERR_PASSWORD_SAMEAS_USERALIAS = 17; |
src/main/java/my/com/upass/dao/ConfigurationDAO.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import java.util.List; |
15 | 15 |
|
16 |
import my.com.upass.generic.hibernate.GenericDAO; |
|
16 | 17 |
import my.com.upass.pojo.ConfigurationBean; |
17 |
import net.penril.generic.hibernate.GenericDAO; |
|
18 | 18 |
|
19 | 19 |
/** |
20 | 20 |
* PROGRAMMER: Danniell |
src/main/java/my/com/upass/dao/MinimalHibernateDAOFactory.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import my.com.upass.dao.hibernate.ConfigurationDAOHibernate; |
4 | 4 |
import my.com.upass.dao.hibernate.UserDAOHibernate; |
5 |
import net.penril.generic.hibernate.GenericDAOHibernate;
|
|
5 |
import my.com.upass.generic.hibernate.GenericDAOHibernate;
|
|
6 | 6 |
|
7 | 7 |
public class MinimalHibernateDAOFactory extends MinimalDAOFactory { |
8 | 8 |
|
src/main/java/my/com/upass/dao/UserDAO.java | ||
---|---|---|
14 | 14 |
import java.util.Date; |
15 | 15 |
import java.util.List; |
16 | 16 |
|
17 |
import my.com.upass.generic.hibernate.GenericDAO; |
|
17 | 18 |
import my.com.upass.maybank.entities.UserProfile; |
18 | 19 |
import my.com.upass.pojo.MinimalUserBean; |
19 | 20 |
import my.com.upass.pojo.MinimalUserBeanBackup; |
20 | 21 |
import my.com.upass.pojo.UserAppAccess; |
21 |
import net.penril.generic.hibernate.GenericDAO; |
|
22 | 22 |
|
23 | 23 |
import org.hibernate.Session; |
24 | 24 |
|
src/main/java/my/com/upass/dao/hibernate/ConfigurationDAOHibernate.java | ||
---|---|---|
15 | 15 |
import java.util.List; |
16 | 16 |
|
17 | 17 |
import my.com.upass.dao.ConfigurationDAO; |
18 |
import my.com.upass.generic.hibernate.GenericDAOHibernate; |
|
18 | 19 |
import my.com.upass.pojo.ConfigurationBean; |
19 |
import net.penril.generic.hibernate.GenericDAOHibernate; |
|
20 | 20 |
|
21 | 21 |
import org.apache.commons.lang.StringUtils; |
22 | 22 |
import org.apache.log4j.Logger; |
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java | ||
---|---|---|
20 | 20 |
|
21 | 21 |
import my.com.upass.MinimalConstants; |
22 | 22 |
import my.com.upass.dao.UserDAO; |
23 |
import my.com.upass.generic.hibernate.GenericDAOHibernate; |
|
23 | 24 |
import my.com.upass.maybank.entities.Im2uUser; |
24 | 25 |
import my.com.upass.maybank.entities.StockUser; |
25 | 26 |
import my.com.upass.maybank.entities.UserProfile; |
26 | 27 |
import my.com.upass.pojo.MinimalUserBean; |
27 | 28 |
import my.com.upass.pojo.MinimalUserBeanBackup; |
28 | 29 |
import my.com.upass.pojo.UserAppAccess; |
29 |
import net.penril.generic.hibernate.GenericDAOHibernate; |
|
30 | 30 |
|
31 | 31 |
import org.apache.commons.collections.CollectionUtils; |
32 | 32 |
import org.apache.commons.collections.PredicateUtils; |
... | ... | |
497 | 497 |
|
498 | 498 |
for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) { |
499 | 499 |
UserProfile example = (UserProfile) iter.next(); |
500 |
|
|
500 |
|
|
501 | 501 |
Criteria c = session.createCriteria(example.getClass()) |
502 | 502 |
.add(Example.create(example).ignoreCase().enableLike()); |
503 | 503 |
|
... | ... | |
513 | 513 |
} |
514 | 514 |
c.add(Restrictions.ilike(MU + ".userAlias", username)); |
515 | 515 |
} |
516 |
|
|
516 |
|
|
517 | 517 |
profiles.addAll(c.list()); |
518 | 518 |
} |
519 | 519 |
} finally { |
... | ... | |
522 | 522 |
} |
523 | 523 |
return profiles; |
524 | 524 |
} |
525 |
|
|
525 |
|
|
526 | 526 |
public List/* <UserProfile> */listProfilesByExamples( |
527 | 527 |
List/* <UserProfile> */exampleProfiles, Date fromDate, Date toDate, Session txSession) |
528 | 528 |
throws Exception { |
... | ... | |
534 | 534 |
|
535 | 535 |
for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) { |
536 | 536 |
UserProfile example = (UserProfile) iter.next(); |
537 |
|
|
537 |
|
|
538 | 538 |
Criteria c = session.createCriteria(example.getClass()) |
539 | 539 |
.add(Example.create(example).ignoreCase().enableLike()); |
540 | 540 |
|
... | ... | |
546 | 546 |
} else { |
547 | 547 |
c.createAlias("minUser", MU); |
548 | 548 |
} |
549 |
|
|
549 |
|
|
550 | 550 |
final String username = example.getMinUser().getUsername(); |
551 | 551 |
if (username != null) { |
552 | 552 |
c.add(Restrictions.ilike(MU + ".userAlias", username)); |
553 | 553 |
} |
554 |
|
|
554 |
|
|
555 | 555 |
Integer userStatus = null; |
556 | 556 |
boolean userStatusSelected = true; |
557 |
try{ |
|
558 |
userStatus = Integer.valueOf(example.getMinUser().getUstate()); |
|
559 |
}catch (NumberFormatException e){ |
|
557 |
try { |
|
558 |
userStatus = new Integer(example.getMinUser().getUstate()); |
|
559 |
|
|
560 |
} catch (NumberFormatException e) { |
|
560 | 561 |
userStatusSelected = false; |
561 | 562 |
} |
562 | 563 |
if (userStatusSelected) { |
563 | 564 |
c.add(Restrictions.eq(MU + ".ustate", userStatus)); |
564 | 565 |
} |
565 |
|
|
566 |
|
|
566 | 567 |
Calendar calender = new GregorianCalendar(); |
567 | 568 |
if (fromDate != null) { |
568 | 569 |
calender.setTime(fromDate); |
569 | 570 |
calender.add(Calendar.DATE, -1); |
570 | 571 |
c.add(Restrictions.gt(MU + ".udateCreated", calender.getTime())); |
571 | 572 |
} |
572 |
else if (toDate != null){ |
|
573 |
else if (toDate != null) {
|
|
573 | 574 |
calender.setTime(toDate); |
574 | 575 |
calender.add(Calendar.DATE, 1); |
575 | 576 |
c.add(Restrictions.lt(MU + ".udateCreated", calender.getTime())); |
576 | 577 |
} |
577 |
|
|
578 |
|
|
578 | 579 |
profiles.addAll(c.list()); |
579 | 580 |
} |
580 | 581 |
} finally { |
src/main/java/my/com/upass/generic/hibernate/GenericDAO.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (M) 2009 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 |
package my.com.upass.generic.hibernate; |
|
12 |
|
|
13 |
import java.io.Serializable; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.hibernate.Session; |
|
17 |
|
|
18 |
/** |
|
19 |
* PROGRAMMER: Danniell |
|
20 |
* CHANGE-NO: |
|
21 |
* TASK-NO: |
|
22 |
* DATE CREATED: Oct 27, 2010 |
|
23 |
* TAG AS: |
|
24 |
* REASON(S): |
|
25 |
* MODIFICATION: |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* Represents Base Data Access Object |
|
30 |
*/ |
|
31 |
public interface GenericDAO { |
|
32 |
|
|
33 |
Object findById(Serializable id, boolean lock) throws Exception; |
|
34 |
|
|
35 |
List findAll() throws Exception; |
|
36 |
|
|
37 |
List findByExample(Object exampleInstance, String[] excludeProperty) throws Exception; |
|
38 |
|
|
39 |
Object makePersistent(Object entity) throws Exception; |
|
40 |
|
|
41 |
void makeTransient(Object entity) throws Exception; |
|
42 |
|
|
43 |
void flush() throws Exception; |
|
44 |
|
|
45 |
void clear() throws Exception; |
|
46 |
|
|
47 |
long getNextSequenceNumber(String sequenceName, Session txSession) throws Exception; |
|
48 |
|
|
49 |
long getCurrentSequenceNumber(String sequenceName, Session txSession) throws Exception; |
|
50 |
|
|
51 |
Class getEntityClass(); |
|
52 |
} |
src/main/java/my/com/upass/generic/hibernate/GenericDAOHibernate.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (M) 2009 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 |
package my.com.upass.generic.hibernate; |
|
12 |
|
|
13 |
import java.io.Serializable; |
|
14 |
import java.math.BigDecimal; |
|
15 |
import java.sql.CallableStatement; |
|
16 |
import java.sql.Connection; |
|
17 |
import java.sql.DatabaseMetaData; |
|
18 |
import java.sql.SQLException; |
|
19 |
import java.util.List; |
|
20 |
|
|
21 |
import org.hibernate.Criteria; |
|
22 |
import org.hibernate.LockMode; |
|
23 |
import org.hibernate.Session; |
|
24 |
import org.hibernate.Transaction; |
|
25 |
import org.hibernate.criterion.Criterion; |
|
26 |
import org.hibernate.criterion.Example; |
|
27 |
|
|
28 |
public abstract class GenericDAOHibernate implements GenericDAO { |
|
29 |
|
|
30 |
private Class persistentClass; |
|
31 |
private Session session; |
|
32 |
|
|
33 |
public GenericDAOHibernate() { |
|
34 |
this.persistentClass = getEntityClass(); |
|
35 |
} |
|
36 |
|
|
37 |
public void setSession(Session s) { |
|
38 |
this.session = s; |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* |
|
43 |
* Will override the current session |
|
44 |
* |
|
45 |
* @param hibernateCfgPath |
|
46 |
* The Hibernate configuration file path |
|
47 |
*/ |
|
48 |
public void setSession(String hibernateCfgPath) { |
|
49 |
HibernateUtils.overrideSession(hibernateCfgPath); |
|
50 |
this.session = HibernateUtils.currentSession(); |
|
51 |
} |
|
52 |
|
|
53 |
protected Session getSession() throws Exception { |
|
54 |
if (session == null || session.isOpen() == false) { |
|
55 |
session = HibernateUtils.currentSession(); |
|
56 |
} |
|
57 |
return session; |
|
58 |
} |
|
59 |
|
|
60 |
public Class getPersistentClass() { |
|
61 |
return persistentClass; |
|
62 |
} |
|
63 |
|
|
64 |
public void clear() throws Exception { |
|
65 |
getSession().clear(); |
|
66 |
} |
|
67 |
|
|
68 |
public List findAll() throws Exception { |
|
69 |
return findByCriteria(null); |
|
70 |
} |
|
71 |
|
|
72 |
protected List findByCriteria(Criterion[] criterion) throws Exception { |
|
73 |
Criteria crit = getSession().createCriteria(getPersistentClass()); |
|
74 |
if (criterion != null) { |
|
75 |
for (int i = 0; i < criterion.length; i++) { |
|
76 |
crit.add(criterion[0]); |
|
77 |
} |
|
78 |
} |
|
79 |
return crit.list(); |
|
80 |
} |
|
81 |
|
|
82 |
public List findByExample(Object exampleInstance, String[] excludeProperty) throws Exception { |
|
83 |
Criteria crit = getSession().createCriteria(getPersistentClass()); |
|
84 |
Example example = Example.create(exampleInstance); |
|
85 |
|
|
86 |
for (int i = 0; i < excludeProperty.length; i++) { |
|
87 |
example.excludeProperty(excludeProperty[0]); |
|
88 |
} |
|
89 |
|
|
90 |
crit.add(example); |
|
91 |
return crit.list(); |
|
92 |
} |
|
93 |
|
|
94 |
public Object findById(Serializable id, boolean lock) throws Exception { |
|
95 |
Object entity; |
|
96 |
if (lock) { |
|
97 |
entity = getSession().get(getPersistentClass(), id, LockMode.UPGRADE); |
|
98 |
} else { |
|
99 |
entity = getSession().get(getPersistentClass(), id); |
|
100 |
} |
|
101 |
return entity; |
|
102 |
} |
|
103 |
|
|
104 |
public void flush() throws Exception { |
|
105 |
getSession().flush(); |
|
106 |
} |
|
107 |
|
|
108 |
public Object makePersistent(Object entity) throws Exception { |
|
109 |
getSession().saveOrUpdate(entity); |
|
110 |
return entity; |
|
111 |
} |
|
112 |
|
|
113 |
public void makeTransient(Object entity) throws Exception { |
|
114 |
getSession().delete(entity); |
|
115 |
} |
|
116 |
|
|
117 |
public long getNextSequenceNumber(String sequenceName, Session txSession) throws Exception { |
|
118 |
BigDecimal nextValue = new BigDecimal(0); |
|
119 |
|
|
120 |
// TODO: Don't forget to remove the following line! |
|
121 |
System.out.println("########## Retrieving next value for" |
|
122 |
+ " sequence: " + sequenceName); |
|
123 |
|
|
124 |
Session session = null; |
|
125 |
Transaction tx = null; |
|
126 |
try { |
|
127 |
session = txSession != null ? txSession : getSession(); |
|
128 |
Connection conn = session.connection(); |
|
129 |
DatabaseMetaData metaData = conn.getMetaData(); |
|
130 |
String jdbcUrl = metaData.getURL(); |
|
131 |
if (jdbcUrl.startsWith("jdbc:oracle")) { |
|
132 |
nextValue = (BigDecimal) session.createSQLQuery( |
|
133 |
"select " + sequenceName + ".nextval from dual") |
|
134 |
.uniqueResult(); |
|
135 |
|
|
136 |
} else if (jdbcUrl.startsWith("jdbc:sqlserver")) { |
|
137 |
// TODO: Don't forget to remove the following line! |
|
138 |
System.out |
|
139 |
.println("########## Simulating sequences in SQL Server."); |
|
140 |
|
|
141 |
if (txSession == null) |
|
142 |
session.beginTransaction(); |
|
143 |
|
|
144 |
CallableStatement cstmt = conn.prepareCall(// |
|
145 |
"{call nextval_" + sequenceName + "(?)}"); |
|
146 |
cstmt.registerOutParameter(1, java.sql.Types.BIGINT); |
|
147 |
cstmt.execute(); |
|
148 |
nextValue = cstmt.getBigDecimal(1); |
|
149 |
|
|
150 |
if (txSession == null) |
|
151 |
tx.commit(); |
|
152 |
|
|
153 |
} else |
|
154 |
throw new RuntimeException( |
|
155 |
"The jdbc driver is not in supported."); |
|
156 |
|
|
157 |
} catch (SQLException e) { |
|
158 |
if (txSession == null) |
|
159 |
rollbackTransactionIfAny(session); |
|
160 |
throw new RuntimeException(e); |
|
161 |
|
|
162 |
} finally { |
|
163 |
if (txSession == null) |
|
164 |
closeSessionIfAny(session); |
|
165 |
} |
|
166 |
long longValue = nextValue.longValue(); |
|
167 |
// TODO: Don't forget to remove the following line! |
|
168 |
System.out.println("########## Last sequence value: " + longValue); |
|
169 |
return longValue; |
|
170 |
} |
|
171 |
|
|
172 |
public long getCurrentSequenceNumber(String sequenceName, Session txSession) throws Exception { |
|
173 |
BigDecimal currentValue = new BigDecimal(0); |
|
174 |
|
|
175 |
// TODO: Don't forget to remove the following line! |
|
176 |
System.out.println("########## Retrieving current value for" |
|
177 |
+ " sequence: " + sequenceName); |
|
178 |
Session session = null; |
|
179 |
try { |
|
180 |
session = txSession != null ? txSession : getSession(); |
|
181 |
Connection conn = session.connection(); |
|
182 |
DatabaseMetaData metaData = conn.getMetaData(); |
|
183 |
String jdbcUrl = metaData.getURL(); |
|
184 |
if (jdbcUrl.startsWith("jdbc:oracle")) { |
|
185 |
currentValue = (BigDecimal) getSession().createSQLQuery( |
|
186 |
"select " + sequenceName + ".currval from dual") |
|
187 |
.uniqueResult(); |
|
188 |
|
|
189 |
} else if (jdbcUrl.startsWith("jdbc:sqlserver")) { |
|
190 |
currentValue = (BigDecimal) getSession().createSQLQuery( |
|
191 |
"select seq_value from " + sequenceName).uniqueResult(); |
|
192 |
} else |
|
193 |
throw new RuntimeException( |
|
194 |
"The jdbc driver is not in supported."); |
|
195 |
|
|
196 |
} catch (SQLException e) { |
|
197 |
throw new RuntimeException(e); |
|
198 |
|
|
199 |
} finally { |
|
200 |
if (txSession == null) |
|
201 |
closeSessionIfAny(session); |
|
202 |
} |
|
203 |
long longValue = currentValue.longValue(); |
|
204 |
// TODO: Don't forget to remove the following line! |
|
205 |
System.out.println("########## Current sequence value: " + longValue); |
|
206 |
return longValue; |
|
207 |
} |
|
208 |
|
|
209 |
// Some Utility Methods |
|
210 |
|
|
211 |
public static void closeSessionIfAny(Session session) { |
|
212 |
if (session != null && session.isOpen()) |
|
213 |
session.close(); |
|
214 |
} |
|
215 |
|
|
216 |
public static void rollbackTransactionIfAny(Session session) { |
|
217 |
if (session != null && session.isOpen()) { |
|
218 |
Transaction tx = session.getTransaction(); |
|
219 |
if (tx != null && tx.isActive()) |
|
220 |
tx.rollback(); |
|
221 |
} |
|
222 |
} |
|
223 |
} |
src/main/java/my/com/upass/generic/hibernate/HibernateUtils.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2009 Penril Datability (SEA) 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 (SEA) Sdn Bhd or its assignees. This software is |
|
7 |
* provided under the terms of a license between Penril Datability (SEA) |
|
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.generic.hibernate; |
|
13 |
|
|
14 |
import org.hibernate.HibernateException; |
|
15 |
import org.hibernate.Session; |
|
16 |
import org.hibernate.SessionFactory; |
|
17 |
import org.hibernate.cfg.Configuration; |
|
18 |
|
|
19 |
/** |
|
20 |
* Configures and provides access to Hibernate sessions, tied to the current |
|
21 |
* thread of execution. Follows the Thread Local Session pattern, see {@link http://hibernate.org/42.html}. |
|
22 |
* |
|
23 |
* <pre> |
|
24 |
* For this project, all the hibernate configuration file must be at the "/com/ib/ibss/hibernate/configuration/hibernate.cfg.xml". |
|
25 |
* It is hard coded. Just make sure out the hibernate configuration file at the mentioned path. |
|
26 |
* </pre> |
|
27 |
*/ |
|
28 |
public class HibernateUtils { |
|
29 |
|
|
30 |
private static final Object CONFIG_LOCK = new Object(); |
|
31 |
|
|
32 |
/** |
|
33 |
* <pre> |
|
34 |
* Location of hibernate.cfg.xml file. NOTICE: Location should be on the |
|
35 |
* classpath as Hibernate uses #resourceAsStream style lookup for its |
|
36 |
* configuration file. That is place the config file in a Java package - the |
|
37 |
* default location is the default Java package. |
|
38 |
* |
|
39 |
* Examples: |
|
40 |
* <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml". |
|
41 |
* CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code> |
|
42 |
* |
|
43 |
* For this project, all the hibernate configuration file must be at the "/com/ib/ibss/hibernate/configuration/hibernate.cfg.xml". |
|
44 |
* It is hard coded. Just make sure out the hibernate configuration file at the mentioned path. |
|
45 |
* </pre> |
|
46 |
*/ |
|
47 |
private static String CONFIG_FILE_LOCATION = "/com/ib/hibernate/configuration/hibernate.cfg.xml"; |
|
48 |
private static Configuration cfg = null; |
|
49 |
private static SessionFactory sessionFactory = null; |
|
50 |
private static ThreadLocal session = null; |
|
51 |
|
|
52 |
/** |
|
53 |
* To create a new session |
|
54 |
*/ |
|
55 |
private static void init() { |
|
56 |
synchronized (CONFIG_LOCK) { |
|
57 |
if (session == null) { |
|
58 |
/** The single instance of hibernate configuration */ |
|
59 |
cfg = new Configuration(); |
|
60 |
|
|
61 |
/** The single instance of hibernate SessionFactory */ |
|
62 |
sessionFactory = cfg.configure(CONFIG_FILE_LOCATION).buildSessionFactory(); |
|
63 |
|
|
64 |
/** Holds a single instance of Session */ |
|
65 |
session = new ThreadLocal(); |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* |
|
72 |
* Override the current session if already exist. If not, create a new session. |
|
73 |
* |
|
74 |
* @param p |
|
75 |
*/ |
|
76 |
public static void overrideSession(String p) { |
|
77 |
synchronized (CONFIG_LOCK) { |
|
78 |
/** The single instance of hibernate configuration */ |
|
79 |
cfg = new Configuration(); |
|
80 |
|
|
81 |
/** The single instance of hibernate SessionFactory */ |
|
82 |
sessionFactory = cfg.configure(p).buildSessionFactory(); |
|
83 |
|
|
84 |
/** Holds a single instance of Session */ |
|
85 |
session = new ThreadLocal(); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Returns the ThreadLocal Session instance. Lazy initialize the <code>SessionFactory</code> if needed. |
|
91 |
* Will instantiate the hibernate session if not exist. |
|
92 |
* |
|
93 |
* @return Session The hirbernate session. |
|
94 |
* @throws HibernateException |
|
95 |
*/ |
|
96 |
public static Session currentSession() throws HibernateException { |
|
97 |
init(); |
|
98 |
Session m_oSession = (Session) session.get(); |
|
99 |
// Open a new Session, if this Thread has none yet |
|
100 |
if (m_oSession == null || (m_oSession != null && !m_oSession.isConnected())) { |
|
101 |
try { |
|
102 |
m_oSession = sessionFactory.openSession(); |
|
103 |
session.set(m_oSession); |
|
104 |
|
|
105 |
} catch (Throwable ex) { |
|
106 |
// Make sure you log the exception, as it might be swallowed |
|
107 |
throw new ExceptionInInitializerError(ex); |
|
108 |
} |
|
109 |
} |
|
110 |
return m_oSession; |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Close the single hibernate session instance. |
|
115 |
* |
|
116 |
* @throws HibernateException |
|
117 |
*/ |
|
118 |
public static void closeSession() throws HibernateException { |
|
119 |
Session m_oSession = (Session) session.get(); |
|
120 |
session.set(null); |
|
121 |
if (m_oSession != null) { |
|
122 |
m_oSession.close(); |
|
123 |
} |
|
124 |
} |
|
125 |
} |
src/main/java/my/com/upass/maybank/MinimalMaybankFacade.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
Response lookupPanCc_internal( |
43 | 43 |
String appAccessId, String hashedSecretKey, String panCc); |
44 |
|
|
45 |
int convertPublicToM2u( |
|
46 |
String appAccessId, String hashedSecretKey, |
|
47 |
String username, String pan1, String pan2); |
|
44 | 48 |
} |
src/main/java/my/com/upass/maybank/MinimalMaybankFacadeImpl.java | ||
---|---|---|
7 | 7 |
import my.com.upass.MinimalConstants; |
8 | 8 |
import my.com.upass.MinimalUPassControllerV2; |
9 | 9 |
import my.com.upass.UPassException; |
10 |
import my.com.upass.generic.hibernate.GenericDAOHibernate; |
|
11 |
import my.com.upass.generic.hibernate.HibernateUtils; |
|
10 | 12 |
import my.com.upass.maybank.entities.IbccUser; |
11 | 13 |
import my.com.upass.maybank.entities.M2uUser; |
12 | 14 |
import my.com.upass.maybank.entities.UserProfile; |
13 | 15 |
import my.com.upass.pojo.ClientApp; |
14 | 16 |
import my.com.upass.pojo.MinimalUserBean; |
15 | 17 |
import my.com.upass.pojo.UserAppAccess; |
16 |
import net.penril.generic.hibernate.GenericDAOHibernate; |
|
17 |
import net.penril.generic.hibernate.HibernateUtils; |
|
18 | 18 |
|
19 | 19 |
import org.apache.log4j.Logger; |
20 | 20 |
import org.hibernate.Session; |
... | ... | |
168 | 168 |
return lookupProfileByExample(appAccessId, hashedSecretKey, ClientApp.APP_ID_CCPP, example); |
169 | 169 |
} |
170 | 170 |
|
171 |
public int convertPublicToM2u(String appAccessId, String hashedSecretKey, String username, String pan1, String pan2) { |
|
172 |
// TODO Auto-generated method stub |
|
173 |
return 0; |
|
174 |
} |
|
175 |
|
|
171 | 176 |
// protected methods |
172 | 177 |
|
173 | 178 |
protected int newUser( |
... | ... | |
298 | 303 |
} |
299 | 304 |
return res; |
300 | 305 |
} |
306 |
|
|
301 | 307 |
} |
src/main/java/my/com/upass/services/ChangeStaticPasswordService.java | ||
---|---|---|
14 | 14 |
import java.util.HashMap; |
15 | 15 |
import java.util.Map; |
16 | 16 |
|
17 |
import net.penril.generic.hibernate.GenericDAOHibernate; |
|
18 |
import net.penril.generic.hibernate.HibernateUtils; |
|
19 | 17 |
|
20 | 18 |
import org.hibernate.Session; |
21 | 19 |
|
22 | 20 |
import my.com.upass.Config; |
21 |
import my.com.upass.ConfigBean; |
|
23 | 22 |
import my.com.upass.MinimalConstants; |
24 | 23 |
import my.com.upass.MinimalUPassControllerV2; |
25 | 24 |
import my.com.upass.UPassException; |
26 | 25 |
import my.com.upass.dao.MinimalDAOFactory; |
27 | 26 |
import my.com.upass.dao.UserDAO; |
28 | 27 |
import my.com.upass.factory.MinimalUPassFactory; |
28 |
import my.com.upass.generic.hibernate.GenericDAOHibernate; |
|
29 |
import my.com.upass.generic.hibernate.HibernateUtils; |
|
29 | 30 |
import my.com.upass.pojo.MinimalUserBean; |
30 | 31 |
import my.com.upass.spassword.PasswordController; |
31 | 32 |
import my.com.upass.spring.ldap.MaybankLdapConstant; |
... | ... | |
43 | 44 |
/** |
44 | 45 |
* <Class description> |
45 | 46 |
*/ |
46 |
public class ChangeStaticPasswordService |
|
47 |
{ |
|
47 |
public class ChangeStaticPasswordService {
|
|
48 |
|
|
48 | 49 |
private MinimalUPassControllerV2 upc; |
49 | 50 |
|
50 | 51 |
public ChangeStaticPasswordService(MinimalUPassControllerV2 upc) |
... | ... | |
96 | 97 |
try { |
97 | 98 |
session = HibernateUtils.currentSession(); |
98 | 99 |
session.beginTransaction(); |
99 |
|
|
100 |
|
|
100 | 101 |
// update database |
101 | 102 |
boolean lrc = userDao.updateUserToStore(userBean, session); |
102 | 103 |
if (!lrc) { |
103 | 104 |
rc = MinimalConstants.ERR_SYSTEM_NOT_READY; |
104 | 105 |
} |
105 |
|
|
106 |
//update ldap |
|
107 |
Config cfg = Config.getInstance(); |
|
108 |
if("Y".equals(cfg.get(MinimalConstants.PROP_MIGRATION_PERIOD_FLAG).toString())){ |
|
106 |
|
|
107 |
// update ldap |
|
108 |
if (pc.getConfigBean().isInMigrationPeriod()) { |
|
109 | 109 |
Map attrMap = new HashMap(); |
110 | 110 |
attrMap.put(MaybankLdapConstant.ATTR_PASSWORD, newPassword); |
111 | 111 |
MinimalUPassControllerV2.getMaybankLdapDAO().updateUser(userBean.getUserAlias(), attrMap); |
112 | 112 |
} |
113 | 113 |
|
114 | 114 |
session.getTransaction().commit(); |
115 |
|
|
115 |
|
|
116 | 116 |
} catch (UPassException e) { |
117 | 117 |
rc = e.getErrorCode(); |
118 | 118 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
119 |
} finally {
|
|
119 |
} finally { |
|
120 | 120 |
GenericDAOHibernate.closeSessionIfAny(session); |
121 | 121 |
} |
122 | 122 |
} catch (Exception e) { |
src/main/java/my/com/upass/services/ModifyUserService.java | ||
---|---|---|
17 | 17 |
import java.util.Map; |
18 | 18 |
|
19 | 19 |
import my.com.upass.Config; |
20 |
import my.com.upass.ConfigBean; |
|
20 | 21 |
import my.com.upass.MinimalConstants; |
21 | 22 |
import my.com.upass.MinimalUPassControllerV2; |
22 | 23 |
import my.com.upass.UPassException; |
23 | 24 |
import my.com.upass.dao.MinimalDAOFactory; |
24 | 25 |
import my.com.upass.dao.UserDAO; |
25 | 26 |
import my.com.upass.factory.MinimalUPassFactory; |
27 |
import my.com.upass.generic.hibernate.GenericDAOHibernate; |
|
28 |
import my.com.upass.generic.hibernate.HibernateUtils; |
|
26 | 29 |
import my.com.upass.maybank.entities.UserProfile; |
27 | 30 |
import my.com.upass.pojo.MinimalUserBean; |
28 | 31 |
import my.com.upass.spassword.PasswordController; |
29 | 32 |
import my.com.upass.spring.ldap.MaybankLdapConstant; |
30 |
import net.penril.generic.hibernate.GenericDAOHibernate; |
|
31 |
import net.penril.generic.hibernate.HibernateUtils; |
|
32 | 33 |
|
33 | 34 |
import org.hibernate.Session; |
34 | 35 |
|
... | ... | |
56 | 57 |
public int modifyUser( |
57 | 58 |
String userAlias, int userType, String userDesc, |
58 | 59 |
String userPassword, int userState) { |
60 |
|
|
59 | 61 |
return modifyUser(userAlias, userType, userDesc, userPassword, userState, true); |
60 | 62 |
} |
61 |
|
|
63 |
|
|
62 | 64 |
public int modifyUser( |
63 | 65 |
String userAlias, int userType, String userDesc, |
64 | 66 |
String userPassword, int userState, boolean updateLdap) { |
... | ... | |
67 | 69 |
if (userAlias == null) { |
68 | 70 |
return MinimalConstants.ERR_INVALID_INPUT; |
69 | 71 |
} |
72 |
Session session = null; |
|
70 | 73 |
try { |
74 |
session = HibernateUtils.currentSession(); |
|
75 |
session.beginTransaction(); |
|
76 |
|
|
71 | 77 |
UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO(); |
72 |
MinimalUserBean ub = userDao.getUserFromStore(userAlias, null);
|
|
78 |
MinimalUserBean ub = userDao.getUserFromStore(userAlias, session);
|
|
73 | 79 |
|
74 | 80 |
if (ub == null) { |
75 | 81 |
return MinimalConstants.ERR_USERALIAS_NOT_FOUND; |
76 | 82 |
} |
83 |
PasswordController pc = null; |
|
77 | 84 |
if (userPassword != null) { |
78 | 85 |
// Generate new paswword |
79 |
PasswordController pc = MinimalUPassFactory.getPasswordController(ub,
|
|
80 |
upc.getConfigurationsMap()); |
|
86 |
pc = MinimalUPassFactory.getPasswordController(
|
|
87 |
ub, upc.getConfigurationsMap());
|
|
81 | 88 |
// rc = pc.GeneratePassword(userPassword, false); //disable |
82 | 89 |
// password hist check 20081220 |
83 | 90 |
rc = pc.GeneratePassword(userPassword, true); |
... | ... | |
93 | 100 |
ub.setUserType(userType); |
94 | 101 |
ub.setUstate(userState); |
95 | 102 |
|
96 |
Session session = null; |
|
97 |
try { |
|
98 |
session = HibernateUtils.currentSession(); |
|
99 |
session.beginTransaction(); |
|
100 |
|
|
101 |
if (userDao.updateUserToStore(ub, session)) { |
|
102 |
rc = MinimalConstants.ERR_SUCCESS; |
|
103 |
} else { |
|
104 |
rc = MinimalConstants.ERR_UNKNOWN; |
|
105 |
} |
|
106 |
|
|
107 |
//update ldap |
|
108 |
Config cfg = Config.getInstance(); |
|
109 |
if(updateLdap && "Y".equals(cfg.get(MinimalConstants.PROP_MIGRATION_PERIOD_FLAG).toString())){ |
|
110 |
Map attrMap = new HashMap(); |
|
111 |
attrMap.put(MaybankLdapConstant.ATTR_PASSWORD, userPassword); |
|
112 |
MinimalUPassControllerV2.getMaybankLdapDAO().updateUser(userAlias, attrMap); |
|
113 |
} |
|
103 |
if (userDao.updateUserToStore(ub, session)) { |
|
104 |
rc = MinimalConstants.ERR_SUCCESS; |
|
105 |
} else { |
|
106 |
rc = MinimalConstants.ERR_UNKNOWN; |
|
107 |
} |
|
114 | 108 |
|
115 |
session.getTransaction().commit();
|
|
116 |
|
|
117 |
} catch (UPassException e) {
|
|
118 |
rc = e.getErrorCode(); |
|
119 |
GenericDAOHibernate.rollbackTransactionIfAny(session);
|
|
120 |
} finally {
|
|
121 |
GenericDAOHibernate.closeSessionIfAny(session);
|
|
109 |
// update ldap
|
|
110 |
if (updateLdap |
|
111 |
&& pc != null && pc.getConfigBean().isInMigrationPeriod()) {
|
|
112 |
|
|
113 |
Map attrMap = new HashMap();
|
|
114 |
attrMap.put(MaybankLdapConstant.ATTR_PASSWORD, userPassword);
|
|
115 |
MinimalUPassControllerV2.getMaybankLdapDAO().updateUser(userAlias, attrMap);
|
|
122 | 116 |
} |
123 |
|
|
117 |
session.getTransaction().commit(); |
|
118 |
|
|
119 |
} catch (UPassException e) { |
|
120 |
e.printStackTrace(); |
|
121 |
rc = e.getErrorCode(); |
|
122 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
123 |
|
|
124 | 124 |
} catch (Exception e) { |
125 | 125 |
e.printStackTrace(); |
126 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
127 |
|
|
128 |
} finally { |
|
129 |
GenericDAOHibernate.closeSessionIfAny(session); |
|
126 | 130 |
} |
127 | 131 |
return rc; |
128 | 132 |
} |
src/main/java/my/com/upass/services/VerifyStaticPasswordService.java | ||
---|---|---|
139 | 139 |
ret.code = MinimalConstants.ERR_USERALIAS_NOT_FOUND; |
140 | 140 |
return ret; |
141 | 141 |
} |
142 |
PasswordController pc = (PasswordController) MinimalUPassFactory.getPasswordController( |
|
143 |
ret.user, upc.getConfigurationsMap()); |
|
144 |
ConfigBean configBean = pc.getConfigBean(); |
|
145 |
|
|
142 | 146 |
// -- migration period checking : START -- |
143 |
Config cfg = Config.getInstance(); |
|
144 |
if ("Y".equals(cfg.get(MinimalConstants.PROP_MIGRATION_PERIOD_FLAG).toString()) |
|
147 |
if (configBean.isInMigrationPeriod() |
|
145 | 148 |
&& ret.user.getHashedPassword() == null) { // password null, so the user haven't get migrated. |
146 | 149 |
|
147 | 150 |
// authenticate to ldap |
... | ... | |
157 | 160 |
ret.code = responseCode; |
158 | 161 |
return ret; |
159 | 162 |
} |
160 |
|
|
161 | 163 |
// reload profile with password |
162 | 164 |
ret.user = userDao.getUserFromStore(userAlias, txSession); |
163 | 165 |
} |
... | ... | |
185 | 187 |
ret.code = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED; |
186 | 188 |
return ret; |
187 | 189 |
} |
188 |
|
|
189 |
PasswordController pc = (PasswordController) MinimalUPassFactory.getPasswordController( |
|
190 |
ret.user, upc.getConfigurationsMap()); |
|
191 |
ConfigBean configBean = pc.getConfigBean(); |
|
192 |
|
|
193 | 190 |
ret.user = (MinimalUserBean) pc.getUpdatedObject(); |
194 | 191 |
|
195 | 192 |
// verify user dormant period |
src/main/java/net/penril/generic/hibernate/GenericDAO.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (M) 2009 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 |
package net.penril.generic.hibernate; |
|
12 |
|
|
13 |
import java.io.Serializable; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.hibernate.Session; |
|
17 |
|
|
18 |
/** |
|
19 |
* PROGRAMMER: Danniell |
|
20 |
* CHANGE-NO: |
|
21 |
* TASK-NO: |
|
22 |
* DATE CREATED: Oct 27, 2010 |
|
23 |
* TAG AS: |
|
24 |
* REASON(S): |
|
25 |
* MODIFICATION: |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* Represents Base Data Access Object |
|
30 |
*/ |
|
31 |
public interface GenericDAO { |
|
32 |
|
|
33 |
Object findById(Serializable id, boolean lock) throws Exception; |
|
34 |
|
|
35 |
List findAll() throws Exception; |
|
36 |
|
|
37 |
List findByExample(Object exampleInstance, String[] excludeProperty) throws Exception; |
|
38 |
|
|
39 |
Object makePersistent(Object entity) throws Exception; |
|
40 |
|
|
41 |
void makeTransient(Object entity) throws Exception; |
|
42 |
|
|
43 |
void flush() throws Exception; |
|
44 |
|
|
45 |
void clear() throws Exception; |
|
46 |
|
|
47 |
long getNextSequenceNumber(String sequenceName, Session txSession) throws Exception; |
|
48 |
|
|
49 |
long getCurrentSequenceNumber(String sequenceName, Session txSession) throws Exception; |
|
50 |
|
|
51 |
Class getEntityClass(); |
|
52 |
} |
src/main/java/net/penril/generic/hibernate/GenericDAOHibernate.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (M) 2009 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 |
package net.penril.generic.hibernate; |
|
12 |
|
|
13 |
import java.io.Serializable; |
|
14 |
import java.math.BigDecimal; |
|
15 |
import java.sql.CallableStatement; |
|
16 |
import java.sql.Connection; |
|
17 |
import java.sql.DatabaseMetaData; |
|
18 |
import java.sql.SQLException; |
|
19 |
import java.util.List; |
|
20 |
|
|
21 |
import org.hibernate.Criteria; |
|
22 |
import org.hibernate.LockMode; |
|
23 |
import org.hibernate.Session; |
|
24 |
import org.hibernate.Transaction; |
|
25 |
import org.hibernate.criterion.Criterion; |
|
26 |
import org.hibernate.criterion.Example; |
|
27 |
|
|
28 |
public abstract class GenericDAOHibernate implements GenericDAO |
|
29 |
{ |
|
30 |
private Class persistentClass; |
|
31 |
private Session session; |
|
32 |
|
|
33 |
public GenericDAOHibernate() |
|
34 |
{ |
|
35 |
this.persistentClass = getEntityClass(); |
|
36 |
} |
|
37 |
|
|
38 |
public void setSession(Session s) |
|
39 |
{ |
|
40 |
this.session = s; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* |
|
45 |
* Will override the current session |
|
46 |
* |
|
47 |
* @param hibernateCfgPath |
|
48 |
* The Hibernate configuration file path |
|
49 |
*/ |
|
50 |
public void setSession(String hibernateCfgPath) |
|
51 |
{ |
|
52 |
HibernateUtils.overrideSession(hibernateCfgPath); |
|
53 |
this.session = HibernateUtils.currentSession(); |
|
54 |
} |
|
55 |
|
|
56 |
protected Session getSession() throws Exception |
|
57 |
{ |
|
58 |
if (session == null || session.isOpen() == false) |
|
59 |
{ |
|
60 |
try |
|
61 |
{ |
|
62 |
session = HibernateUtils.currentSession(); |
|
63 |
} catch (Exception e) |
|
64 |
{ |
|
65 |
throw e; |
|
66 |
} |
|
67 |
} |
|
68 |
return session; |
|
69 |
} |
|
70 |
|
|
71 |
public Class getPersistentClass() |
|
72 |
{ |
|
73 |
return persistentClass; |
|
74 |
} |
|
75 |
|
|
76 |
public void clear() throws Exception |
|
77 |
{ |
|
78 |
getSession().clear(); |
|
79 |
} |
|
80 |
|
|
81 |
public List findAll() throws Exception |
|
82 |
{ |
|
83 |
return findByCriteria(null); |
|
84 |
} |
|
85 |
|
|
86 |
protected List findByCriteria(Criterion[] criterion) throws Exception |
|
87 |
{ |
|
88 |
Criteria crit = getSession().createCriteria(getPersistentClass()); |
|
89 |
if (criterion != null) |
|
90 |
{ |
|
91 |
for (int i = 0; i < criterion.length; i++) { |
|
92 |
crit.add(criterion[0]); |
|
93 |
} |
|
94 |
} |
|
95 |
return crit.list(); |
|
96 |
} |
|
97 |
|
|
98 |
public List findByExample(Object exampleInstance, String[] excludeProperty) throws Exception |
|
99 |
{ |
|
100 |
Criteria crit = getSession().createCriteria(getPersistentClass()); |
|
101 |
Example example = Example.create(exampleInstance); |
|
102 |
|
|
103 |
for (int i = 0; i < excludeProperty.length; i++) { |
|
104 |
example.excludeProperty(excludeProperty[0]); |
|
105 |
} |
|
106 |
|
|
107 |
crit.add(example); |
|
108 |
return crit.list(); |
|
109 |
} |
|
110 |
|
|
111 |
public Object findById(Serializable id, boolean lock) throws Exception |
|
112 |
{ |
|
113 |
Object entity; |
|
114 |
if (lock) |
|
115 |
{ |
|
116 |
entity = getSession().get(getPersistentClass(), id, LockMode.UPGRADE); |
|
117 |
} |
|
118 |
else |
|
119 |
{ |
|
120 |
entity = getSession().get(getPersistentClass(), id); |
|
121 |
} |
|
122 |
return entity; |
|
123 |
} |
|
124 |
|
|
125 |
public void flush() throws Exception |
|
126 |
{ |
|
127 |
getSession().flush(); |
|
128 |
} |
|
129 |
|
|
130 |
public Object makePersistent(Object entity) throws Exception |
|
131 |
{ |
|
132 |
getSession().saveOrUpdate(entity); |
|
133 |
return entity; |
|
134 |
} |
|
135 |
|
|
136 |
public void makeTransient(Object entity) throws Exception |
|
137 |
{ |
|
138 |
getSession().delete(entity); |
|
139 |
} |
|
140 |
|
|
141 |
public long getNextSequenceNumber(String sequenceName, Session txSession) throws Exception { |
|
142 |
BigDecimal nextValue = new BigDecimal(0); |
|
143 |
|
|
144 |
// TODO: Don't forget to remove the following line! |
|
145 |
System.out.println("########## Retrieving next value for" |
|
146 |
+ " sequence: " + sequenceName); |
|
147 |
|
|
148 |
Session session = null; |
|
149 |
Transaction tx = null; |
|
150 |
try { |
|
151 |
session = txSession != null ? txSession : getSession(); |
|
152 |
Connection conn = session.connection(); |
|
153 |
DatabaseMetaData metaData = conn.getMetaData(); |
|
154 |
String jdbcUrl = metaData.getURL(); |
|
155 |
if (jdbcUrl.startsWith("jdbc:oracle")) { |
|
156 |
nextValue = (BigDecimal) session.createSQLQuery( |
|
157 |
"select " + sequenceName + ".nextval from dual") |
|
158 |
.uniqueResult(); |
|
159 |
|
|
160 |
} else if (jdbcUrl.startsWith("jdbc:sqlserver")) { |
|
161 |
// TODO: Don't forget to remove the following line! |
|
162 |
System.out |
|
163 |
.println("########## Simulating sequences in SQL Server."); |
|
164 |
|
|
165 |
if (txSession == null) |
|
166 |
session.beginTransaction(); |
|
167 |
|
|
168 |
CallableStatement cstmt = conn.prepareCall(// |
|
169 |
"{call nextval_" + sequenceName + "(?)}"); |
|
170 |
cstmt.registerOutParameter(1, java.sql.Types.BIGINT); |
|
171 |
cstmt.execute(); |
|
172 |
nextValue = cstmt.getBigDecimal(1); |
|
173 |
|
|
174 |
if (txSession == null) |
|
175 |
tx.commit(); |
|
176 |
|
|
177 |
} else |
|
178 |
throw new RuntimeException( |
|
179 |
"The jdbc driver is not in supported."); |
|
180 |
|
|
181 |
} catch (SQLException e) { |
|
182 |
if (txSession == null) |
|
183 |
rollbackTransactionIfAny(session); |
|
184 |
throw new RuntimeException(e); |
|
185 |
|
|
186 |
} finally { |
|
187 |
if (txSession == null) |
|
188 |
closeSessionIfAny(session); |
|
189 |
} |
|
190 |
long longValue = nextValue.longValue(); |
|
191 |
// TODO: Don't forget to remove the following line! |
|
192 |
System.out.println("########## Last sequence value: " + longValue); |
|
193 |
return longValue; |
|
194 |
} |
|
195 |
|
|
196 |
public long getCurrentSequenceNumber(String sequenceName, Session txSession) throws Exception { |
|
197 |
BigDecimal currentValue = new BigDecimal(0); |
|
198 |
|
|
199 |
// TODO: Don't forget to remove the following line! |
|
200 |
System.out.println("########## Retrieving current value for" |
|
201 |
+ " sequence: " + sequenceName); |
|
202 |
Session session = null; |
|
203 |
try { |
|
204 |
session = txSession != null ? txSession : getSession(); |
|
205 |
Connection conn = session.connection(); |
|
206 |
DatabaseMetaData metaData = conn.getMetaData(); |
|
207 |
String jdbcUrl = metaData.getURL(); |
|
208 |
if (jdbcUrl.startsWith("jdbc:oracle")) { |
|
209 |
currentValue = (BigDecimal) getSession().createSQLQuery( |
|
210 |
"select " + sequenceName + ".currval from dual") |
|
211 |
.uniqueResult(); |
|
212 |
|
|
213 |
} else if (jdbcUrl.startsWith("jdbc:sqlserver")) { |
|
214 |
currentValue = (BigDecimal) getSession().createSQLQuery( |
|
215 |
"select seq_value from " + sequenceName).uniqueResult(); |
|
216 |
} else |
|
217 |
throw new RuntimeException( |
|
218 |
"The jdbc driver is not in supported."); |
|
219 |
|
|
220 |
} catch (SQLException e) { |
|
221 |
throw new RuntimeException(e); |
|
222 |
|
|
223 |
} finally { |
|
224 |
if (txSession == null) |
|
225 |
closeSessionIfAny(session); |
|
226 |
} |
|
227 |
long longValue = currentValue.longValue(); |
|
228 |
// TODO: Don't forget to remove the following line! |
|
229 |
System.out.println("########## Current sequence value: " + longValue); |
|
230 |
return longValue; |
|
231 |
} |
|
232 |
|
|
233 |
// Some Utility Methods |
|
234 |
|
|
235 |
public static void closeSessionIfAny(Session session) { |
|
236 |
if (session != null && session.isOpen()) |
|
237 |
session.close(); |
|
238 |
} |
|
239 |
|
|
240 |
public static void rollbackTransactionIfAny(Session session) { |
|
241 |
if (session != null && session.isOpen()) { |
|
242 |
Transaction tx = session.getTransaction(); |
|
243 |
if (tx != null && tx.isActive()) |
|
244 |
tx.rollback(); |
|
245 |
} |
|
246 |
} |
|
247 |
} |
src/main/java/net/penril/generic/hibernate/HibernateUtils.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2009 Penril Datability (SEA) 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 (SEA) Sdn Bhd or its assignees. This software is |
|
7 |
* provided under the terms of a license between Penril Datability (SEA) |
|
8 |
* Sdn Bhd and the recipient, and its use is subject to the terms of that |
|
9 |
* license. |
|
10 |
*/ |
|
11 |
|
|
12 |
package net.penril.generic.hibernate; |
|
13 |
|
|
14 |
import org.hibernate.HibernateException; |
|
15 |
import org.hibernate.Session; |
|
16 |
import org.hibernate.SessionFactory; |
|
17 |
import org.hibernate.cfg.Configuration; |
|
18 |
|
|
19 |
/** |
|
20 |
* Configures and provides access to Hibernate sessions, tied to the current |
|
21 |
* thread of execution. Follows the Thread Local Session pattern, see {@link http://hibernate.org/42.html}. |
|
22 |
* |
|
23 |
* <pre> |
|
24 |
* For this project, all the hibernate configuration file must be at the "/com/ib/ibss/hibernate/configuration/hibernate.cfg.xml". |
|
25 |
* It is hard coded. Just make sure out the hibernate configuration file at the mentioned path. |
|
26 |
* </pre> |
|
27 |
*/ |
|
28 |
public class HibernateUtils { |
Also available in: Unified diff