📄 loginservices.java
字号:
if (doStore) { userLogin.store(); } if ("true".equals(UtilProperties.getPropertyValue("security.properties", "store.login.history"))) { boolean createHistory = true; // only save info on service auth if option set to true to do so if (isServiceAuth && !"true".equals(UtilProperties.getPropertyValue("security.properties", "store.login.history.on.service.auth"))) { createHistory = false; } if (createHistory) { Map ulhCreateMap = UtilMisc.toMap("userLoginId", username, "visitId", visitId, "fromDate", UtilDateTime.nowTimestamp(), "partyId", userLogin.get("partyId"), "successfulLogin", successfulLogin); // ONLY save the password if it was incorrect if ("N".equals(successfulLogin) && !"false".equals(UtilProperties.getPropertyValue("security.properties", "store.login.history.incorrect.password"))) { ulhCreateMap.put("passwordUsed", password); } delegator.create("UserLoginHistory", ulhCreateMap); } } } catch (GenericEntityException e) { try { TransactionUtil.rollback(beganTransaction, "Error saving UserLoginHistory", e); } catch (GenericTransactionException e2) { Debug.logError(e2, "Could not rollback nested transaction: " + e2.getMessage(), module); } } finally { try { TransactionUtil.commit(beganTransaction); } catch (GenericTransactionException e) { Debug.logError(e, "Could not commit nested transaction: " + e.getMessage(), module); } } } finally { // resume/restore parent transaction if (parentTx != null) { try { TransactionUtil.resume(parentTx); Debug.logVerbose("Resumed the parent transaction.", module); } catch (GenericTransactionException e) { Debug.logError(e, "Could not resume parent nested transaction: " + e.getMessage(), module); } } } } else { // account is disabled, but this may be the result of a stale cache entry, // so lets clear the cache and try again if this is the first pass if (isServiceAuth && passNumber <= 1) { delegator.clearCacheLine("UserLogin", UtilMisc.toMap("userLoginId", username)); repeat = true; continue; } Map messageMap = UtilMisc.toMap("username", username); errMsg = UtilProperties.getMessage(resource,"loginservices.account_for_user_login_id_disabled",messageMap ,locale); if (disabledDateTime != null) { messageMap = UtilMisc.toMap("disabledDateTime", disabledDateTime); errMsg += UtilProperties.getMessage(resource,"loginservices.since_datetime",messageMap ,locale); } else { errMsg += "."; } if (loginDisableMinutes > 0 && reEnableTime != null) { messageMap = UtilMisc.toMap("reEnableTime", reEnableTime); errMsg += UtilProperties.getMessage(resource,"loginservices.will_be_reenabled",messageMap ,locale); } else { errMsg += UtilProperties.getMessage(resource,"loginservices.not_scheduled_to_be_reenabled",locale); } } } else { // userLogin record not found, user does not exist errMsg = UtilProperties.getMessage(resource, "loginservices.user_not_found", locale); Debug.logInfo("[LoginServices.userLogin] : Invalid User : " + errMsg, module); } } } if (errMsg.length() > 0) { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); } return result; } /** Creates a UserLogin *@param ctx The DispatchContext that this service is operating in *@param context Map containing the input parameters *@return Map with the result of the service, the output parameters */ public static Map createUserLogin(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); Security security = ctx.getSecurity(); GenericValue loggedInUserLogin = (GenericValue) context.get("userLogin"); List errorMessageList = new LinkedList(); Locale locale = (Locale) context.get("locale"); boolean useEncryption = "true".equals(UtilProperties.getPropertyValue("security.properties", "password.encrypt")); String userLoginId = (String) context.get("userLoginId"); String partyId = (String) context.get("partyId"); String currentPassword = (String) context.get("currentPassword"); String currentPasswordVerify = (String) context.get("currentPasswordVerify"); String passwordHint = (String) context.get("passwordHint"); String errMsg = null; // security: don't create a user login if the specified partyId (if not empty) already exists // unless the logged in user has permission to do so (same partyId or PARTYMGR_CREATE) if (partyId != null && partyId.length() > 0) { GenericValue party = null; try { party = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", partyId)); } catch (GenericEntityException e) { Debug.logWarning(e, "", module); } if (party != null) { if (loggedInUserLogin != null) { // <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_CREATE permission if (!partyId.equals(loggedInUserLogin.getString("partyId"))) { if (!security.hasEntityPermission("PARTYMGR", "_CREATE", loggedInUserLogin)) { errMsg = UtilProperties.getMessage(resource,"loginservices.party_with_specified_party_ID_exists_not_have_permission", locale); errorMessageList.add(errMsg); } } } else { errMsg = UtilProperties.getMessage(resource,"loginservices.must_be_logged_in_and_permission_create_login_party_ID_exists", locale); errorMessageList.add(errMsg); } } } checkNewPassword(null, null, currentPassword, currentPasswordVerify, passwordHint, errorMessageList, true, locale); GenericValue userLoginToCreate = delegator.makeValue("UserLogin", UtilMisc.toMap("userLoginId", userLoginId)); userLoginToCreate.set("passwordHint", passwordHint); userLoginToCreate.set("partyId", partyId); userLoginToCreate.set("currentPassword", useEncryption ? getPasswordHash(currentPassword) : currentPassword); try { if (delegator.findByPrimaryKey(userLoginToCreate.getPrimaryKey()) != null) { Map messageMap = UtilMisc.toMap("userLoginId", userLoginId); errMsg = UtilProperties.getMessage(resource,"loginservices.could_not_create_login_user_with_ID_exists", messageMap, locale); errorMessageList.add(errMsg); } } catch (GenericEntityException e) { Debug.logWarning(e, "", module); Map messageMap = UtilMisc.toMap("errorMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"loginservices.could_not_create_login_user_read_failure", messageMap, locale); errorMessageList.add(errMsg); } if (errorMessageList.size() > 0) { return ServiceUtil.returnError(errorMessageList); } try { userLoginToCreate.create(); } catch (GenericEntityException e) { Debug.logWarning(e, "", module); Map messageMap = UtilMisc.toMap("errorMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"loginservices.could_not_create_login_user_write_failure", messageMap, locale); return ServiceUtil.returnError(errMsg); } result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); return result; } /** Updates UserLogin Password info *@param ctx The DispatchContext that this service is operating in *@param context Map containing the input parameters *@return Map with the result of the service, the output parameters */ public static Map updatePassword(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); Security security = ctx.getSecurity(); GenericValue loggedInUserLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); boolean useEncryption = "true".equals(UtilProperties.getPropertyValue("security.properties", "password.encrypt")); boolean adminUser = false; String userLoginId = (String) context.get("userLoginId"); String errMsg = null; if (userLoginId == null || userLoginId.length() == 0) { userLoginId = loggedInUserLogin.getString("userLoginId"); } // <b>security check</b>: userLogin userLoginId must equal userLoginId, or must have PARTYMGR_UPDATE permission // NOTE: must check permission first so that admin users can set own password without specifying old password if (!security.hasEntityPermission("PARTYMGR", "_UPDATE", loggedInUserLogin)) { if (!userLoginId.equals(loggedInUserLogin.getString("userLoginId"))) { errMsg = UtilProperties.getMessage(resource,"loginservices.not_have_permission_update_password_for_user_login", locale); return ServiceUtil.returnError(errMsg); } } else { adminUser = true; } GenericValue userLoginToUpdate = null; try { userLoginToUpdate = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", userLoginId)); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errorMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"loginservices.could_not_change_password_read_failure", messageMap, locale); return ServiceUtil.returnError(errMsg); } if (userLoginToUpdate == null) { Map messageMap = UtilMisc.toMap("userLoginId", userLoginId); errMsg = UtilProperties.getMessage(resource,"loginservices.could_not_change_password_userlogin_with_id_not_exist", messageMap, locale); return ServiceUtil.returnError(errMsg); } String currentPassword = (String) context.get("currentPassword"); String newPassword = (String) context.get("newPassword"); String newPasswordVerify = (String) context.get("newPasswordVerify"); String passwordHint = (String) context.get("passwordHint"); if ("true".equals(UtilProperties.getPropertyValue("security.properties", "password.lowercase"))) { currentPassword = currentPassword.toLowerCase(); newPassword = newPassword.toLowerCase(); newPasswordVerify = newPasswordVerify.toLowerCase(); } List errorMessageList = new LinkedList(); if (newPassword != null && newPassword.length() > 0) { checkNewPassword(userLoginToUpdate, currentPassword, newPassword, newPasswordVerify, passwordHint, errorMessageList, adminUser, locale); } if (errorMessageList.size() > 0) { return ServiceUtil.returnError(errorMessageList); } userLoginToUpdate.set("currentPassword", useEncryption ? getPasswordHash(newPassword) : newPassword, false); userLoginToUpdate.set("passwordHint", passwordHint, false); try { userLoginToUpdate.store(); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errorMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"loginservices.could_not_change_password_write_failure", messageMap, locale); return ServiceUtil.returnError(errMsg); } result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -