Revision 44:7a7fb8fcfd6e
src/my/com/upass/UPassControllerV2.java | ||
---|---|---|
15 | 15 |
import java.util.Date; |
16 | 16 |
import java.util.HashMap; |
17 | 17 |
|
18 |
import my.com.upass.MinimalUPassControllerV2.AccessCheckResult; |
|
18 | 19 |
import my.com.upass.factory.UPassFactory; |
19 | 20 |
import my.com.upass.pojo.ClientApp; |
20 | 21 |
import my.com.upass.services.ActivateUserService; |
... | ... | |
736 | 737 |
if (rc != Constants.ERR_SUCCESS) { |
737 | 738 |
return rc; |
738 | 739 |
} |
739 |
rc = deleteUserService.deleteUser(userAlias); |
|
740 |
rc = deleteUserService.deleteUser(userAlias, null);
|
|
740 | 741 |
logger.info("UA_DeleteUser - admin user alias: [" + userAlias + "] Return: " + rc); |
741 | 742 |
return rc; |
742 | 743 |
} |
... | ... | |
745 | 746 |
* Because of the ability to choose the target app, |
746 | 747 |
* this method is meant for USS only. |
747 | 748 |
* |
748 |
* @see #deleteUser(String, String, String, Session) |
|
749 |
* @see #deleteUserWithTheProfile(String, String, String, Session)
|
|
749 | 750 |
*/ |
750 |
public int deleteUser( |
|
751 |
public int deleteUserWithTheProfile(
|
|
751 | 752 |
String adminUsername, String adminPassword, |
752 |
String username, int targetAppId, Session txSession) { |
|
753 |
String username, int targetAppId, Session txSession) |
|
754 |
throws UPassException { |
|
753 | 755 |
|
754 | 756 |
int rc; |
755 | 757 |
try { |
... | ... | |
759 | 761 |
rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED; |
760 | 762 |
|
761 | 763 |
else { |
762 |
// rc = deleteUserService.deleteUser(username, targetAppId, txSession); |
|
763 |
throw new NotImplementedException(); |
|
764 |
boolean revoked = appAccessMgtService.revokeAppAccessForUser(username, targetAppId, txSession); |
|
765 |
rc = revoked ? |
|
766 |
deleteUserService.deleteUser(username, targetAppId, txSession) |
|
767 |
: MinimalConstants.ERR_SYSTEM_NOT_READY; |
|
764 | 768 |
} |
765 |
|
|
766 | 769 |
} catch (MultipleAppAccessesFound e) { |
767 | 770 |
rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED; |
768 | 771 |
e.printStackTrace(); |
769 |
|
|
770 |
} catch (UPassException e) { |
|
771 |
rc = e.getErrorCode(); |
|
772 |
e.printStackTrace(); |
|
773 | 772 |
} |
774 | 773 |
logger.info("deleteUser - user alias: [" + username + "] Return: " + rc); |
775 | 774 |
return rc; |
... | ... | |
779 | 778 |
* This methods identifies the target app using <code>appAccessId</code>, |
780 | 779 |
* hence meant for {@link ClientApp}s |
781 | 780 |
* |
782 |
* @see #deleteUser(String, String, String, int, Session) |
|
781 |
* @see #deleteUserWithTheProfile(String, String, String, int, Session)
|
|
783 | 782 |
*/ |
784 |
public int deleteUser( |
|
783 |
public int deleteUserWithTheProfile(
|
|
785 | 784 |
String appAccessId, String hashedSecretKey, |
786 |
String username, Session txSession) { |
|
785 |
String username, Session txSession) |
|
786 |
throws UPassException { |
|
787 | 787 |
|
788 |
throw new NotImplementedException(); |
|
788 |
int rc; |
|
789 |
try { |
|
790 |
AccessCheckResult checkResult = checkAppAccess(appAccessId, hashedSecretKey, txSession); |
|
791 |
|
|
792 |
final Integer targetAppId = checkResult.invokerAppId; |
|
793 |
if (targetAppId == null) { |
|
794 |
rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED; |
|
795 |
|
|
796 |
} else { |
|
797 |
boolean revoked = appAccessMgtService.revokeAppAccessForUser(username, targetAppId, txSession); |
|
798 |
rc = revoked ? |
|
799 |
deleteUserService.deleteUser(username, targetAppId, txSession) |
|
800 |
: MinimalConstants.ERR_SYSTEM_NOT_READY; |
|
801 |
} |
|
802 |
} catch (MultipleAppAccessesFound e) { |
|
803 |
rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED; |
|
804 |
e.printStackTrace(); |
|
805 |
} |
|
806 |
logger.info("deleteUser - user alias: [" + username + "] Return: " + rc); |
|
807 |
return rc; |
|
789 | 808 |
} |
790 | 809 |
|
791 | 810 |
// /////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1218 | 1237 |
* ERR_INVALID_USERALIAS - User alias does not match with defined pattern <br/> |
1219 | 1238 |
* ERR_PASSWORD_SAMEAS_USERALIAS - password is same is user name error <br/> |
1220 | 1239 |
*/ |
1221 |
public int AD_AddUser(String rootAlias, String rootPassword, String adminUserAlias, |
|
1222 |
String adminDesc, String adminUserPassword) { |
|
1240 |
public int AD_AddUser( |
|
1241 |
String rootAlias, String rootPassword, |
|
1242 |
String adminUserAlias, String adminDesc, String adminUserPassword) { |
|
1243 |
|
|
1223 | 1244 |
// check if password is similar to user alias |
1224 | 1245 |
if (rootAlias.equalsIgnoreCase(rootPassword)) { |
1225 | 1246 |
return MinimalConstants.ERR_PASSWORD_SAMEAS_USERALIAS; |
1226 | 1247 |
} |
1227 |
|
|
1228 | 1248 |
int rc = verifyStaticPasswordService.verifyStaticPassword( |
1229 | 1249 |
rootAlias, rootPassword, true, MinimalConstants.UTYPE_STATE_ROOT); |
1230 | 1250 |
|
1231 |
if (rc != MinimalConstants.ERR_SUCCESS) |
|
1232 |
{ |
|
1251 |
if (rc != MinimalConstants.ERR_SUCCESS) { |
|
1233 | 1252 |
return rc; |
1234 | 1253 |
} |
1235 |
|
|
1236 | 1254 |
rc = createUserService.addUser(adminUserAlias, |
1237 | 1255 |
MinimalConstants.UTYPE_STATE_ADMIN, adminDesc, adminUserPassword, |
1238 | 1256 |
MinimalConstants.UID_STATE_ACTIVE, MinimalConstants.SYSTEM_ID); |
1239 | 1257 |
|
1240 |
logger.info("AD_AddUser - admin user alias: [" + adminUserAlias |
|
1241 |
+ "] Return: " + rc); |
|
1258 |
logger.info("AD_AddUser - admin user alias: [" + adminUserAlias + "] Return: " + rc); |
|
1242 | 1259 |
|
1243 | 1260 |
return rc; |
1244 | 1261 |
} |
1245 |
|
|
1246 | 1262 |
} |
src/my/com/upass/maybank/MaybankFacadeImpl.java | ||
---|---|---|
204 | 204 |
session = HibernateUtils.currentSession(); |
205 | 205 |
session.beginTransaction(); |
206 | 206 |
|
207 |
rc = upcV2.deleteUser(appAccessId, hashedSecretKey, username, session); |
|
208 |
session.getTransaction().commit(); |
|
207 |
rc = upcV2.deleteUserWithTheProfile(appAccessId, hashedSecretKey, username, session); |
|
208 |
|
|
209 |
if (rc == MinimalConstants.ERR_SUCCESS) |
|
210 |
session.getTransaction().commit(); |
|
211 |
else |
|
212 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
213 |
|
|
214 |
} catch (UPassException e) { |
|
215 |
rc = e.getErrorCode(); |
|
216 |
e.printStackTrace(); |
|
217 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
209 | 218 |
|
210 | 219 |
} catch (Exception e) { |
211 | 220 |
LOGGER.error(e, e); |
... | ... | |
280 | 289 |
int rc = upcV2.updateProfileShallowly( |
281 | 290 |
appAccessId, hashedSecretKey, stockUser, session); |
282 | 291 |
|
283 |
session.getTransaction().commit(); |
|
292 |
if (rc == MinimalConstants.ERR_SUCCESS) |
|
293 |
session.getTransaction().commit(); |
|
294 |
else |
|
295 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
296 |
|
|
284 | 297 |
return rc; |
285 | 298 |
|
286 | 299 |
} else { |
... | ... | |
319 | 332 |
if (rc == MinimalConstants.ERR_SUCCESS) { |
320 | 333 |
rc = upcV2.updateProfileShallowly(appAccessId, hashedSecretKey, profile, session); |
321 | 334 |
|
322 |
session.getTransaction().commit(); |
|
335 |
if (rc == MinimalConstants.ERR_SUCCESS) |
|
336 |
session.getTransaction().commit(); |
|
337 |
else |
|
338 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
|
323 | 339 |
|
324 | 340 |
} else |
325 | 341 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
src/my/com/upass/services/DeleteUserService.java | ||
---|---|---|
3 | 3 |
import java.text.SimpleDateFormat; |
4 | 4 |
import java.util.Date; |
5 | 5 |
|
6 |
import org.hibernate.Session; |
|
7 |
|
|
6 | 8 |
import my.com.upass.Constants; |
9 |
import my.com.upass.MinimalConstants; |
|
7 | 10 |
import my.com.upass.dao.DAOFactoryProvider; |
8 | 11 |
import my.com.upass.dao.UserDAO; |
12 |
import my.com.upass.maybank.entities.UserProfile; |
|
9 | 13 |
import my.com.upass.pojo.MinimalUserBean; |
10 | 14 |
import my.com.upass.pojo.UserBeanBackup; |
11 | 15 |
import my.com.upass.pojo.UserMasterBeanBackup; |
... | ... | |
15 | 19 |
public DeleteUserService() { |
16 | 20 |
} |
17 | 21 |
|
18 |
public int deleteUser(String userAlias) { |
|
22 |
public int deleteUser(String userAlias, Session txSession) {
|
|
19 | 23 |
|
20 | 24 |
int rc = Constants.ERR_SYSTEM_NOT_READY; |
21 | 25 |
|
22 | 26 |
if (userAlias == null) { |
23 | 27 |
return Constants.ERR_INVALID_INPUT; |
24 | 28 |
} |
25 |
|
|
26 | 29 |
UserDAO userDao; |
27 |
|
|
28 | 30 |
try { |
29 | 31 |
userDao = DAOFactoryProvider.getDAOFactory().getUserDAO(); |
30 | 32 |
UserBeanBackup ubBackup = null; |
31 |
|
|
32 |
// UserBean ubClone = userDao.getUserFromStore (userAlias); |
|
33 |
|
|
34 |
MinimalUserBean ub = userDao.getUserFromStore(userAlias, null); |
|
33 |
MinimalUserBean ub = userDao.getUserFromStore(userAlias, txSession); |
|
35 | 34 |
|
36 | 35 |
if (ub == null) { |
37 | 36 |
return Constants.ERR_INVALID_INPUT; |
38 | 37 |
} |
39 |
|
|
40 | 38 |
String concatedUser = concatUser(userAlias); |
41 | 39 |
|
42 | 40 |
if (!userAlias.equalsIgnoreCase(concatedUser)) { |
43 |
|
|
44 | 41 |
ubBackup = new UserBeanBackup(); |
45 | 42 |
ubBackup.setUserID(ub.getUserID()); |
46 | 43 |
ubBackup.setUserAlias(concatedUser); |
... | ... | |
66 | 63 |
masterBackup.setUserID(ub.getUserID()); |
67 | 64 |
ubBackup.setUpassUserMasterBackup(masterBackup); |
68 | 65 |
} |
69 |
if (userDao.insertUserToBackupStore(ubBackup, null)) {
|
|
66 |
if (userDao.insertUserToBackupStore(ubBackup, txSession)) {
|
|
70 | 67 |
rc = Constants.ERR_SUCCESS; |
71 | 68 |
|
72 | 69 |
} else { |
... | ... | |
77 | 74 |
// master.setUserID(ub.getUserID()); |
78 | 75 |
// ub.setUpassUserMaster (master); |
79 | 76 |
|
80 |
if (userDao.deleteUser(ub, null)) {
|
|
77 |
if (userDao.deleteUser(ub, txSession)) {
|
|
81 | 78 |
rc = Constants.ERR_SUCCESS; |
82 | 79 |
|
83 | 80 |
} else { |
84 | 81 |
rc = Constants.ERR_SYSTEM_NOT_READY; |
85 | 82 |
} |
83 |
} catch (Exception e) { |
|
84 |
e.printStackTrace(); |
|
85 |
} |
|
86 |
return rc; |
|
87 |
} |
|
88 |
|
|
89 |
public int deleteUser( |
|
90 |
String username, Integer targetAppId, Session txSession) { |
|
91 |
|
|
92 |
int rc = Constants.ERR_SYSTEM_NOT_READY; |
|
93 |
|
|
94 |
if (username == null) { |
|
95 |
return Constants.ERR_INVALID_INPUT; |
|
96 |
} |
|
97 |
try { |
|
98 |
UserDAO userDao = DAOFactoryProvider.getDAOFactory().getUserDAO(); |
|
99 |
|
|
100 |
final Class<UserProfile> profileClass = (Class<UserProfile>) |
|
101 |
AppAccessMgtService.appToProfileMap.get(targetAppId); |
|
102 |
|
|
103 |
boolean profileDeleted = userDao.deleteProfile(username, profileClass, txSession); |
|
104 |
|
|
105 |
if (profileDeleted) |
|
106 |
rc = deleteUser(username, txSession); |
|
107 |
else |
|
108 |
rc = MinimalConstants.ERR_SYSTEM_NOT_READY; |
|
86 | 109 |
|
87 | 110 |
} catch (Exception e) { |
88 | 111 |
e.printStackTrace(); |
... | ... | |
94 | 117 |
SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyyHHmmss"); |
95 | 118 |
return userAlias.concat("-").concat(dateFormat.format(new Date())); |
96 | 119 |
} |
120 |
|
|
97 | 121 |
} |
Also available in: Unified diff