diff --git a/applications/accounting/webapp/accounting/WEB-INF/controller.xml b/applications/accounting/webapp/accounting/WEB-INF/controller.xml
index b9cc9a40cb..25ea46386c 100644
--- a/applications/accounting/webapp/accounting/WEB-INF/controller.xml
+++ b/applications/accounting/webapp/accounting/WEB-INF/controller.xml
@@ -40,7 +40,7 @@ under the License.
-
+
@@ -51,21 +51,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/applications/content/webapp/content/WEB-INF/controller.xml b/applications/content/webapp/content/WEB-INF/controller.xml
index 4eab309a05..340584be88 100644
--- a/applications/content/webapp/content/WEB-INF/controller.xml
+++ b/applications/content/webapp/content/WEB-INF/controller.xml
@@ -36,7 +36,7 @@ under the License.
-
+
@@ -47,21 +47,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml b/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
index 55367870d6..1e55bb83bd 100644
--- a/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
+++ b/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
@@ -388,8 +388,8 @@ under the License.
-
+
@@ -43,7 +43,7 @@ under the License.
-
+
@@ -83,13 +83,13 @@ under the License.
-
+
-
+
diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml b/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml
index 30fdd2842e..05507f18fc 100644
--- a/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml
+++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/controller.xml
@@ -42,7 +42,7 @@ under the License.
-
+
@@ -53,21 +53,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/applications/marketing/webapp/marketing/WEB-INF/controller.xml b/applications/marketing/webapp/marketing/WEB-INF/controller.xml
index 4057e5ca9c..2dd4c9ec90 100644
--- a/applications/marketing/webapp/marketing/WEB-INF/controller.xml
+++ b/applications/marketing/webapp/marketing/WEB-INF/controller.xml
@@ -37,7 +37,7 @@ under the License.
-
+
@@ -48,7 +48,7 @@ under the License.
Verify a user is logged in.
-
+
@@ -60,14 +60,14 @@ under the License.
-
+
-
+
diff --git a/applications/order/webapp/ordermgr/WEB-INF/controller.xml b/applications/order/webapp/ordermgr/WEB-INF/controller.xml
index b409298a26..d1383fc456 100644
--- a/applications/order/webapp/ordermgr/WEB-INF/controller.xml
+++ b/applications/order/webapp/ordermgr/WEB-INF/controller.xml
@@ -43,7 +43,7 @@
-
+
@@ -54,21 +54,21 @@
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/applications/party/webapp/partymgr/WEB-INF/controller.xml b/applications/party/webapp/partymgr/WEB-INF/controller.xml
index 5cb7b50336..f30f06eb26 100644
--- a/applications/party/webapp/partymgr/WEB-INF/controller.xml
+++ b/applications/party/webapp/partymgr/WEB-INF/controller.xml
@@ -36,7 +36,7 @@ under the License.
-
+
@@ -47,21 +47,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/applications/product/webapp/catalog/WEB-INF/controller.xml b/applications/product/webapp/catalog/WEB-INF/controller.xml
index 429a2d53bc..bd26986930 100644
--- a/applications/product/webapp/catalog/WEB-INF/controller.xml
+++ b/applications/product/webapp/catalog/WEB-INF/controller.xml
@@ -41,7 +41,7 @@ under the License.
-
+
@@ -52,21 +52,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/applications/product/webapp/facility/WEB-INF/controller.xml b/applications/product/webapp/facility/WEB-INF/controller.xml
index bf83751aab..a661de9e35 100644
--- a/applications/product/webapp/facility/WEB-INF/controller.xml
+++ b/applications/product/webapp/facility/WEB-INF/controller.xml
@@ -39,7 +39,7 @@ under the License.
-
+
@@ -50,21 +50,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/applications/securityext/config/SecurityextUiLabels.properties b/applications/securityext/config/SecurityextUiLabels.properties
index bec704ef54..be2ac7c085 100644
--- a/applications/securityext/config/SecurityextUiLabels.properties
+++ b/applications/securityext/config/SecurityextUiLabels.properties
@@ -1,5 +1,4 @@
#####################################################################
-#
# Copyright 2001-2006 The Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -48,11 +47,6 @@ CommonWelcome=Welcome
loginevents.user_already_logged_in=This user is already logged in.
-# ${errorMessage} = Error Description
-loginevents.following_error_occurred_during_login=The following error occurred during login: ${errorMessage}
-loginevents.unable_to_login_this_application=Login for this application couldn't be completed (required permissions missing).
-loginevents.username_was_empty_reenter=The Username was empty, please re-enter.
-loginevents.password_was_empty_reenter=The Password was empty, please re-enter.
loginevents.username_not_found_reenter=The Username was not found, please re-enter.
loginevents.no_password_hint_specified_try_password_emailed=No password hint was specified, try having the password emailed instead.
# ${passwordHint} = Hint for specifying given password
diff --git a/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java b/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java
index ec18b0a699..ac179a5644 100644
--- a/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java
+++ b/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java
@@ -17,19 +17,14 @@
package org.ofbiz.securityext.login;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import javax.servlet.ServletContext;
-import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import javolution.util.FastList;
import javolution.util.FastMap;
-import org.ofbiz.base.component.ComponentConfig;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilHttp;
@@ -42,23 +37,13 @@ import org.ofbiz.entity.GenericValue;
import org.ofbiz.party.contact.ContactHelper;
import org.ofbiz.product.product.ProductEvents;
import org.ofbiz.product.store.ProductStoreWorker;
-import org.ofbiz.security.Security;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
import org.ofbiz.webapp.control.LoginWorker;
-import org.ofbiz.webapp.control.RequestHandler;
-import org.ofbiz.webapp.stats.VisitHandler;
/**
* LoginEvents - Events for UserLogin and Security handling.
- *
- * @author Andy Zeneski
- * @author David E. Jones
- * @author Dustin Caldwell
- * @author Tom Herrick
- * @version $Rev$
- * @since 2.0
*/
public class LoginEvents {
@@ -102,240 +87,6 @@ public class LoginEvents {
return "success";
}
- /**
- * An HTTP WebEvent handler that checks to see is a userLogin is logged in.
- * If not, the user is forwarded to the login page.
- *
- * @param request The HTTP request object for the current JSP or Servlet request.
- * @param response The HTTP response object for the current JSP or Servlet request.
- * @return String
- */
- public static String checkLogin(HttpServletRequest request, HttpServletResponse response) {
- GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
- HttpSession session = request.getSession();
-
- // anonymous shoppers are not logged in
- if (userLogin != null && "anonymous".equals(userLogin.getString("userLoginId"))) {
- userLogin = null;
- }
-
- // user is logged in; check to see if they have globally logged out if not
- // check if they have permission for this login attempt; if not log them out
- if (userLogin != null) {
- if (!hasBasePermission(userLogin, request) || isFlaggedLoggedOut(userLogin)) {
- Debug.logInfo("User does not have permission or is flagged as logged out", module);
- doBasicLogout(userLogin, request);
- userLogin = null;
-
- // have to reget this because the old session object will be invalid
- session = request.getSession();
- }
- }
-
- String username = null;
- String password = null;
-
- if (userLogin == null) {
- // check parameters
- if (username == null) username = request.getParameter("USERNAME");
- if (password == null) password = request.getParameter("PASSWORD");
- // check session attributes
- if (username == null) username = (String) session.getAttribute("USERNAME");
- if (password == null) password = (String) session.getAttribute("PASSWORD");
-
- if ((username != null) && ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "username.lowercase")))) {
- username = username.toLowerCase();
- }
- if ((password != null) && ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "password.lowercase")))) {
- password = password.toLowerCase();
- }
-
- // in this condition log them in if not already; if not logged in or can't log in, save parameters and return error
- if ((username == null) || (password == null) || ("error".equals(login(request, response)))) {
- Map reqParams = UtilHttp.getParameterMap(request);
- String queryString = UtilHttp.urlEncodeArgs(reqParams);
- Debug.logInfo("reqParams Map: " + reqParams, module);
- Debug.logInfo("queryString: " + queryString, module);
-
- session.setAttribute("_PREVIOUS_REQUEST_", request.getPathInfo());
- if (queryString != null && queryString.length() > 0) {
- session.setAttribute("_PREVIOUS_PARAMS_", queryString);
- }
-
- if (Debug.infoOn()) Debug.logInfo("checkLogin: queryString=" + queryString, module);
- if (Debug.infoOn()) Debug.logInfo("checkLogin: PathInfo=" + request.getPathInfo(), module);
-
- return "error";
- }
- }
-
- return "success";
- }
-
- /**
- * An HTTP WebEvent handler that logs in a userLogin. This should run before the security check.
- *
- * @param request The HTTP request object for the current JSP or Servlet request.
- * @param response The HTTP response object for the current JSP or Servlet request.
- * @return Return a boolean which specifies whether or not the calling Servlet or
- * JSP should generate its own content. This allows an event to override the default content.
- */
- public static String login(HttpServletRequest request, HttpServletResponse response) {
- HttpSession session = request.getSession();
-
- String username = request.getParameter("USERNAME");
- String password = request.getParameter("PASSWORD");
-
- if (username == null) username = (String) session.getAttribute("USERNAME");
- if (password == null) password = (String) session.getAttribute("PASSWORD");
-
- // allow a username and/or password in a request attribute to override the request parameter or the session attribute; this way a preprocessor can play with these a bit...
- if (UtilValidate.isNotEmpty((String) request.getAttribute("USERNAME"))) {
- username = (String) request.getAttribute("USERNAME");
- }
- if (UtilValidate.isNotEmpty((String) request.getAttribute("PASSWORD"))) {
- password = (String) request.getAttribute("PASSWORD");
- }
-
- List unpwErrMsgList = FastList.newInstance();
- if (UtilValidate.isEmpty(username)) {
- unpwErrMsgList.add(UtilProperties.getMessage(resource, "loginevents.username_was_empty_reenter", UtilHttp.getLocale(request)));
- }
- if (UtilValidate.isEmpty(password)) {
- unpwErrMsgList.add(UtilProperties.getMessage(resource, "loginevents.password_was_empty_reenter", UtilHttp.getLocale(request)));
- }
- if (!unpwErrMsgList.isEmpty()) {
- request.setAttribute("_ERROR_MESSAGE_LIST_", unpwErrMsgList);
- return "error";
- }
-
-
- if ((username != null) && ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "username.lowercase")))) {
- username = username.toLowerCase();
- }
- if ((password != null) && ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "password.lowercase")))) {
- password = password.toLowerCase();
- }
-
- // get the visit id to pass to the userLogin for history
- String visitId = VisitHandler.getVisitId(session);
-
- LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
- Map result = null;
-
- try {
- result = dispatcher.runSync("userLogin", UtilMisc.toMap("login.username", username, "login.password", password, "visitId", visitId, "locale", UtilHttp.getLocale(request)));
- } catch (GenericServiceException e) {
- Debug.logError(e, "Error calling userLogin service", module);
- Map messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
- String errMsg = UtilProperties.getMessage(resource, "loginevents.following_error_occurred_during_login", messageMap, UtilHttp.getLocale(request));
- request.setAttribute("_ERROR_MESSAGE_", errMsg);
- return "error";
- }
-
- if (ModelService.RESPOND_SUCCESS.equals(result.get(ModelService.RESPONSE_MESSAGE))) {
- GenericValue userLogin = (GenericValue) result.get("userLogin");
- Map userLoginSession = (Map) result.get("userLoginSession");
-
- if (userLogin != null && hasBasePermission(userLogin, request)) {
- doBasicLogin(userLogin, request);
- } else {
- String errMsg = UtilProperties.getMessage(resource, "loginevents.unable_to_login_this_application", UtilHttp.getLocale(request));
- request.setAttribute("_ERROR_MESSAGE_", errMsg);
- return "error";
- }
-
- if (userLoginSession != null) {
- session.setAttribute("userLoginSession", userLoginSession);
- }
- } else {
- Map messageMap = UtilMisc.toMap("errorMessage", (String) result.get(ModelService.ERROR_MESSAGE));
- String errMsg = UtilProperties.getMessage(resource, "loginevents.following_error_occurred_during_login", messageMap, UtilHttp.getLocale(request));
- request.setAttribute("_ERROR_MESSAGE_", errMsg);
- return "error";
- }
-
- request.setAttribute("_LOGIN_PASSED_", "TRUE");
-
- // run the after-login events
- RequestHandler rh = RequestHandler.getRequestHandler(request.getSession().getServletContext());
- rh.runAfterLoginEvents(request, response);
-
- // make sure the autoUserLogin is set to the same and that the client cookie has the correct userLoginId
- return autoLoginSet(request, response);
- }
-
- public static void doBasicLogin(GenericValue userLogin, HttpServletRequest request) {
- HttpSession session = request.getSession();
- session.setAttribute("userLogin", userLogin);
-
- try {
- GenericValue person = userLogin.getRelatedOne("Person");
- GenericValue partyGroup = userLogin.getRelatedOne("PartyGroup");
- if (person != null) session.setAttribute("person", person);
- if (partyGroup != null) session.setAttribute("partyGroup", partyGroup);
- } catch (GenericEntityException e) {
- Debug.logError(e, "Error getting person/partyGroup info for session, ignoring...", module);
- }
-
- // let the visit know who the user is
- VisitHandler.setUserLogin(session, userLogin, false);
- }
-
- /**
- * An HTTP WebEvent handler that logs out a userLogin by clearing the session.
- *
- * @param request The HTTP request object for the current request.
- * @param response The HTTP response object for the current request.
- * @return Return a boolean which specifies whether or not the calling request
- * should generate its own content. This allows an event to override the default content.
- */
- public static String logout(HttpServletRequest request, HttpServletResponse response) {
- // run the before-logout events
- RequestHandler rh = RequestHandler.getRequestHandler(request.getSession().getServletContext());
- rh.runBeforeLogoutEvents(request, response);
-
-
- // invalidate the security group list cache
- GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
-
- doBasicLogout(userLogin, request);
-
- if (request.getAttribute("_AUTO_LOGIN_LOGOUT_") == null) {
- return autoLoginCheck(request, response);
- }
- return "success";
- }
-
- public static void doBasicLogout(GenericValue userLogin, HttpServletRequest request) {
- HttpSession session = request.getSession();
-
- GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
- Security security = (Security) request.getAttribute("security");
-
- if (security != null && userLogin != null) {
- Security.userLoginSecurityGroupByUserLoginId.remove(userLogin.getString("userLoginId"));
- }
-
- // set the logged out flag
- LoginWorker.setLoggedOut(userLogin.getString("userLoginId"), delegator);
-
- // this is a setting we don't want to lose, although it would be good to have a more general solution here...
- String currCatalog = (String) session.getAttribute("CURRENT_CATALOG_ID");
- // also make sure the delegatorName is preserved, especially so that a new Visit can be created
- String delegatorName = (String) session.getAttribute("delegatorName");
- // also save the shopping cart if we have one
- // DON'T save the cart, causes too many problems: security issues with things done in cart to easy to miss, especially bad on public systems; was put in here because of the "not me" link for auto-login stuff, but that is a small problem compared to what it causes
- //ShoppingCart shoppingCart = (ShoppingCart) session.getAttribute("shoppingCart");
-
- session.invalidate();
- session = request.getSession(true);
-
- if (currCatalog != null) session.setAttribute("CURRENT_CATALOG_ID", currCatalog);
- if (delegatorName != null) session.setAttribute("delegatorName", delegatorName);
- // DON'T save the cart, causes too many problems: if (shoppingCart != null) session.setAttribute("shoppingCart", new WebShoppingCart(shoppingCart, session));
- }
-
/**
* The user forgot his/her password. This will either call showPasswordHint or emailPassword.
*
@@ -573,169 +324,8 @@ public class LoginEvents {
return "success";
}
- protected static String getAutoLoginCookieName(HttpServletRequest request) {
- return UtilHttp.getApplicationName(request) + ".autoUserLoginId";
- }
-
- public static String getAutoUserLoginId(HttpServletRequest request) {
- String autoUserLoginId = null;
- Cookie[] cookies = request.getCookies();
- if (Debug.verboseOn()) Debug.logVerbose("Cookies:" + cookies, module);
- if (cookies != null) {
- for (int i = 0; i < cookies.length; i++) {
- if (cookies[i].getName().equals(getAutoLoginCookieName(request))) {
- autoUserLoginId = cookies[i].getValue();
- break;
- }
- }
- }
- return autoUserLoginId;
- }
-
- public static String autoLoginCheck(HttpServletRequest request, HttpServletResponse response) {
- GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
- HttpSession session = request.getSession();
-
- return autoLoginCheck(delegator, session, getAutoUserLoginId(request));
- }
-
- private static String autoLoginCheck(GenericDelegator delegator, HttpSession session, String autoUserLoginId) {
- if (autoUserLoginId != null) {
- Debug.logInfo("Running autoLogin check.", module);
- try {
- GenericValue autoUserLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", autoUserLoginId));
- GenericValue person = null;
- GenericValue group = null;
- if (autoUserLogin != null) {
- person = delegator.findByPrimaryKey("Person", UtilMisc.toMap("partyId", autoUserLogin.getString("partyId")));
- group = delegator.findByPrimaryKey("PartyGroup", UtilMisc.toMap("partyId", autoUserLogin.getString("partyId")));
- session.setAttribute("autoUserLogin", autoUserLogin);
- }
- if (person != null) {
- session.setAttribute("autoName", person.getString("firstName") + " " + person.getString("lastName"));
- } else if (group != null) {
- session.setAttribute("autoName", group.getString("groupName"));
- }
- } catch (GenericEntityException e) {
- Debug.logError(e, "Cannot get autoUserLogin information: " + e.getMessage(), module);
- }
- }
- return "success";
- }
-
- public static String autoLoginSet(HttpServletRequest request, HttpServletResponse response) {
- GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
- HttpSession session = request.getSession();
- GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
- if (userLogin != null) {
- Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId"));
- autoLoginCookie.setMaxAge(60 * 60 * 24 * 365);
- autoLoginCookie.setPath("/");
- response.addCookie(autoLoginCookie);
- return autoLoginCheck(delegator, session, userLogin.getString("userLoginId"));
- } else {
- return "success";
- }
- }
-
- public static String autoLoginRemove(HttpServletRequest request, HttpServletResponse response) {
- HttpSession session = request.getSession();
- GenericValue userLogin = (GenericValue) session.getAttribute("autoUserLogin");
-
- // remove the cookie
- if (userLogin != null) {
- Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId"));
- autoLoginCookie.setMaxAge(0);
- autoLoginCookie.setPath("/");
- response.addCookie(autoLoginCookie);
- }
- // remove the session attributes
- session.removeAttribute("autoUserLogin");
- session.removeAttribute("autoName");
- // logout the user if logged in.
- if (session.getAttribute("userLogin") != null) {
- request.setAttribute("_AUTO_LOGIN_LOGOUT_", new Boolean(true));
- return logout(request, response);
- }
- return "success";
- }
-
- public static String checkExternalLoginKey(HttpServletRequest request, HttpServletResponse response) {
- HttpSession session = request.getSession();
-
- String externalKey = request.getParameter(LoginWorker.EXTERNAL_LOGIN_KEY_ATTR);
- if (externalKey == null) return "success";
-
- GenericValue userLogin = (GenericValue) LoginWorker.externalLoginKeys.get(externalKey);
- if (userLogin != null) {
- // found userLogin, do the external login...
-
- // if the user is already logged in and the login is different, logout the other user
- GenericValue currentUserLogin = (GenericValue) session.getAttribute("userLogin");
- if (currentUserLogin != null) {
- if (currentUserLogin.getString("userLoginId").equals(userLogin.getString("userLoginId"))) {
- // is the same user, just carry on...
- return "success";
- }
-
- // logout the current user and login the new user...
- logout(request, response);
- // ignore the return value; even if the operation failed we want to set the new UserLogin
- }
-
- doBasicLogin(userLogin, request);
- } else {
- Debug.logWarning("Could not find userLogin for external login key: " + externalKey, module);
- }
-
- return "success";
- }
-
- public static boolean isFlaggedLoggedOut(GenericValue userLogin) {
- if ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "login.disable.global.logout"))) {
- return false;
- }
- if (userLogin == null || userLogin.get("userLoginId") == null) {
- return true;
- }
- // refresh the login object -- maybe cache this?
- try {
- userLogin.refreshFromCache();
- } catch (GenericEntityException e) {
- Debug.logWarning(e, "Unable to refresh UserLogin", module);
- }
- return (userLogin.get("hasLoggedOut") != null ?
- "Y".equalsIgnoreCase(userLogin.getString("hasLoggedOut")) : false);
- }
-
- protected static boolean hasBasePermission(GenericValue userLogin, HttpServletRequest request) {
- ServletContext context = (ServletContext) request.getAttribute("servletContext");
- Security security = (Security) request.getAttribute("security");
-
- String serverId = (String) context.getAttribute("_serverId");
- String contextPath = request.getContextPath();
-
- ComponentConfig.WebappInfo info = ComponentConfig.getWebAppInfo(serverId, contextPath);
- if (security != null) {
- if (info != null) {
- String[] permissions = info.getBasePermission();
- for (int i = 0; i < permissions.length; i++) {
- if (!"NONE".equals(permissions[i]) && !security.hasEntityPermission(permissions[i], "_VIEW", userLogin)) {
- return false;
- }
- }
- } else {
- Debug.logInfo("No webapp configuration found for : " + serverId + " / " + contextPath, module);
- }
- } else {
- Debug.logWarning("Received a null Security object from HttpServletRequest", module);
- }
-
- return true;
- }
-
public static String storeCheckLogin(HttpServletRequest request, HttpServletResponse response) {
- String responseString = LoginEvents.checkLogin(request, response);
+ String responseString = LoginWorker.checkLogin(request, response);
if ("error".equals(responseString)) {
return responseString;
}
@@ -744,7 +334,7 @@ public class LoginEvents {
}
public static String storeLogin(HttpServletRequest request, HttpServletResponse response) {
- String responseString = LoginEvents.login(request, response);
+ String responseString = LoginWorker.login(request, response);
if ("error".equals(responseString)) {
return responseString;
}
diff --git a/applications/workeffort/webapp/workeffort/WEB-INF/controller.xml b/applications/workeffort/webapp/workeffort/WEB-INF/controller.xml
index f4432d40de..30f7b158c0 100644
--- a/applications/workeffort/webapp/workeffort/WEB-INF/controller.xml
+++ b/applications/workeffort/webapp/workeffort/WEB-INF/controller.xml
@@ -36,7 +36,7 @@ under the License.
-
+
@@ -47,21 +47,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/framework/example/webapp/example/WEB-INF/controller.xml b/framework/example/webapp/example/WEB-INF/controller.xml
index 117b17850a..08750b77d6 100644
--- a/framework/example/webapp/example/WEB-INF/controller.xml
+++ b/framework/example/webapp/example/WEB-INF/controller.xml
@@ -44,7 +44,7 @@ under the License.
-
+
@@ -55,19 +55,19 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/framework/shark/webapp/shark/WEB-INF/controller.xml b/framework/shark/webapp/shark/WEB-INF/controller.xml
index c2118de54e..f4410af77d 100644
--- a/framework/shark/webapp/shark/WEB-INF/controller.xml
+++ b/framework/shark/webapp/shark/WEB-INF/controller.xml
@@ -40,7 +40,7 @@ under the License.
-
+
@@ -51,21 +51,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+
diff --git a/framework/webapp/config/WebappUiLabels.properties b/framework/webapp/config/WebappUiLabels.properties
index e8a0ae3071..334e32a0ae 100644
--- a/framework/webapp/config/WebappUiLabels.properties
+++ b/framework/webapp/config/WebappUiLabels.properties
@@ -51,3 +51,10 @@ requestHandler.error_call_event=Error calling event
# SimpleEventHandler
##################################################################
simpleEventHandler.event_not_completed=Could not complete event
+
+
+loginevents.username_was_empty_reenter=The Username was empty, please re-enter.
+loginevents.password_was_empty_reenter=The Password was empty, please re-enter.
+# ${errorMessage} = Error Description
+loginevents.following_error_occurred_during_login=The following error occurred during login: ${errorMessage}
+loginevents.unable_to_login_this_application=Login for this application couldn't be completed (required permissions missing).
diff --git a/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java b/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
index febf42e887..c54932ae53 100644
--- a/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
+++ b/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
@@ -17,33 +17,45 @@ package org.ofbiz.webapp.control;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;
import javax.transaction.Transaction;
+import javolution.util.FastList;
+
+import org.ofbiz.base.component.ComponentConfig;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.transaction.GenericTransactionException;
import org.ofbiz.entity.transaction.TransactionUtil;
+import org.ofbiz.security.Security;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.webapp.stats.VisitHandler;
/**
* Common Workers
- *
- * @author David E. Jones
- * @version $Rev$
- * @since 2.0
*/
public class LoginWorker {
public final static String module = LoginWorker.class.getName();
+ public static final String resourceWebapp = "WebappUiLabels";
public static final String EXTERNAL_LOGIN_KEY_ATTR = "externalLoginKey";
@@ -166,4 +178,399 @@ public class LoginWorker {
}
}
}
+
+ /**
+ * An HTTP WebEvent handler that checks to see is a userLogin is logged in.
+ * If not, the user is forwarded to the login page.
+ *
+ * @param request The HTTP request object for the current JSP or Servlet request.
+ * @param response The HTTP response object for the current JSP or Servlet request.
+ * @return String
+ */
+ public static String checkLogin(HttpServletRequest request, HttpServletResponse response) {
+ GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
+ HttpSession session = request.getSession();
+
+ // anonymous shoppers are not logged in
+ if (userLogin != null && "anonymous".equals(userLogin.getString("userLoginId"))) {
+ userLogin = null;
+ }
+
+ // user is logged in; check to see if they have globally logged out if not
+ // check if they have permission for this login attempt; if not log them out
+ if (userLogin != null) {
+ if (!hasBasePermission(userLogin, request) || isFlaggedLoggedOut(userLogin)) {
+ Debug.logInfo("User does not have permission or is flagged as logged out", module);
+ doBasicLogout(userLogin, request);
+ userLogin = null;
+
+ // have to reget this because the old session object will be invalid
+ session = request.getSession();
+ }
+ }
+
+ String username = null;
+ String password = null;
+
+ if (userLogin == null) {
+ // check parameters
+ if (username == null) username = request.getParameter("USERNAME");
+ if (password == null) password = request.getParameter("PASSWORD");
+ // check session attributes
+ if (username == null) username = (String) session.getAttribute("USERNAME");
+ if (password == null) password = (String) session.getAttribute("PASSWORD");
+
+ if ((username != null) && ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "username.lowercase")))) {
+ username = username.toLowerCase();
+ }
+ if ((password != null) && ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "password.lowercase")))) {
+ password = password.toLowerCase();
+ }
+
+ // in this condition log them in if not already; if not logged in or can't log in, save parameters and return error
+ if ((username == null) || (password == null) || ("error".equals(login(request, response)))) {
+ Map reqParams = UtilHttp.getParameterMap(request);
+ String queryString = UtilHttp.urlEncodeArgs(reqParams);
+ Debug.logInfo("reqParams Map: " + reqParams, module);
+ Debug.logInfo("queryString: " + queryString, module);
+
+ session.setAttribute("_PREVIOUS_REQUEST_", request.getPathInfo());
+ if (queryString != null && queryString.length() > 0) {
+ session.setAttribute("_PREVIOUS_PARAMS_", queryString);
+ }
+
+ if (Debug.infoOn()) Debug.logInfo("checkLogin: queryString=" + queryString, module);
+ if (Debug.infoOn()) Debug.logInfo("checkLogin: PathInfo=" + request.getPathInfo(), module);
+
+ return "error";
+ }
+ }
+
+ return "success";
+ }
+
+ /**
+ * An HTTP WebEvent handler that logs in a userLogin. This should run before the security check.
+ *
+ * @param request The HTTP request object for the current JSP or Servlet request.
+ * @param response The HTTP response object for the current JSP or Servlet request.
+ * @return Return a boolean which specifies whether or not the calling Servlet or
+ * JSP should generate its own content. This allows an event to override the default content.
+ */
+ public static String login(HttpServletRequest request, HttpServletResponse response) {
+ HttpSession session = request.getSession();
+
+ String username = request.getParameter("USERNAME");
+ String password = request.getParameter("PASSWORD");
+
+ if (username == null) username = (String) session.getAttribute("USERNAME");
+ if (password == null) password = (String) session.getAttribute("PASSWORD");
+
+ // allow a username and/or password in a request attribute to override the request parameter or the session attribute; this way a preprocessor can play with these a bit...
+ if (UtilValidate.isNotEmpty((String) request.getAttribute("USERNAME"))) {
+ username = (String) request.getAttribute("USERNAME");
+ }
+ if (UtilValidate.isNotEmpty((String) request.getAttribute("PASSWORD"))) {
+ password = (String) request.getAttribute("PASSWORD");
+ }
+
+ List unpwErrMsgList = FastList.newInstance();
+ if (UtilValidate.isEmpty(username)) {
+ unpwErrMsgList.add(UtilProperties.getMessage(resourceWebapp, "loginevents.username_was_empty_reenter", UtilHttp.getLocale(request)));
+ }
+ if (UtilValidate.isEmpty(password)) {
+ unpwErrMsgList.add(UtilProperties.getMessage(resourceWebapp, "loginevents.password_was_empty_reenter", UtilHttp.getLocale(request)));
+ }
+ if (!unpwErrMsgList.isEmpty()) {
+ request.setAttribute("_ERROR_MESSAGE_LIST_", unpwErrMsgList);
+ return "error";
+ }
+
+
+ if ((username != null) && ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "username.lowercase")))) {
+ username = username.toLowerCase();
+ }
+ if ((password != null) && ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "password.lowercase")))) {
+ password = password.toLowerCase();
+ }
+
+ // get the visit id to pass to the userLogin for history
+ String visitId = VisitHandler.getVisitId(session);
+
+ LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+ Map result = null;
+
+ try {
+ result = dispatcher.runSync("userLogin", UtilMisc.toMap("login.username", username, "login.password", password, "visitId", visitId, "locale", UtilHttp.getLocale(request)));
+ } catch (GenericServiceException e) {
+ Debug.logError(e, "Error calling userLogin service", module);
+ Map messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
+ String errMsg = UtilProperties.getMessage(resourceWebapp, "loginevents.following_error_occurred_during_login", messageMap, UtilHttp.getLocale(request));
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+
+ if (ModelService.RESPOND_SUCCESS.equals(result.get(ModelService.RESPONSE_MESSAGE))) {
+ GenericValue userLogin = (GenericValue) result.get("userLogin");
+ Map userLoginSession = (Map) result.get("userLoginSession");
+
+ if (userLogin != null && hasBasePermission(userLogin, request)) {
+ doBasicLogin(userLogin, request);
+ } else {
+ String errMsg = UtilProperties.getMessage(resourceWebapp, "loginevents.unable_to_login_this_application", UtilHttp.getLocale(request));
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+
+ if (userLoginSession != null) {
+ session.setAttribute("userLoginSession", userLoginSession);
+ }
+ } else {
+ Map messageMap = UtilMisc.toMap("errorMessage", (String) result.get(ModelService.ERROR_MESSAGE));
+ String errMsg = UtilProperties.getMessage(resourceWebapp, "loginevents.following_error_occurred_during_login", messageMap, UtilHttp.getLocale(request));
+ request.setAttribute("_ERROR_MESSAGE_", errMsg);
+ return "error";
+ }
+
+ request.setAttribute("_LOGIN_PASSED_", "TRUE");
+
+ // run the after-login events
+ RequestHandler rh = RequestHandler.getRequestHandler(request.getSession().getServletContext());
+ rh.runAfterLoginEvents(request, response);
+
+ // make sure the autoUserLogin is set to the same and that the client cookie has the correct userLoginId
+ return autoLoginSet(request, response);
+ }
+
+ public static void doBasicLogin(GenericValue userLogin, HttpServletRequest request) {
+ HttpSession session = request.getSession();
+ session.setAttribute("userLogin", userLogin);
+
+ try {
+ GenericValue person = userLogin.getRelatedOne("Person");
+ GenericValue partyGroup = userLogin.getRelatedOne("PartyGroup");
+ if (person != null) session.setAttribute("person", person);
+ if (partyGroup != null) session.setAttribute("partyGroup", partyGroup);
+ } catch (GenericEntityException e) {
+ Debug.logError(e, "Error getting person/partyGroup info for session, ignoring...", module);
+ }
+
+ // let the visit know who the user is
+ VisitHandler.setUserLogin(session, userLogin, false);
+ }
+
+ /**
+ * An HTTP WebEvent handler that logs out a userLogin by clearing the session.
+ *
+ * @param request The HTTP request object for the current request.
+ * @param response The HTTP response object for the current request.
+ * @return Return a boolean which specifies whether or not the calling request
+ * should generate its own content. This allows an event to override the default content.
+ */
+ public static String logout(HttpServletRequest request, HttpServletResponse response) {
+ // run the before-logout events
+ RequestHandler rh = RequestHandler.getRequestHandler(request.getSession().getServletContext());
+ rh.runBeforeLogoutEvents(request, response);
+
+
+ // invalidate the security group list cache
+ GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
+
+ doBasicLogout(userLogin, request);
+
+ if (request.getAttribute("_AUTO_LOGIN_LOGOUT_") == null) {
+ return autoLoginCheck(request, response);
+ }
+ return "success";
+ }
+
+ public static void doBasicLogout(GenericValue userLogin, HttpServletRequest request) {
+ HttpSession session = request.getSession();
+
+ GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
+ Security security = (Security) request.getAttribute("security");
+
+ if (security != null && userLogin != null) {
+ Security.userLoginSecurityGroupByUserLoginId.remove(userLogin.getString("userLoginId"));
+ }
+
+ // set the logged out flag
+ LoginWorker.setLoggedOut(userLogin.getString("userLoginId"), delegator);
+
+ // this is a setting we don't want to lose, although it would be good to have a more general solution here...
+ String currCatalog = (String) session.getAttribute("CURRENT_CATALOG_ID");
+ // also make sure the delegatorName is preserved, especially so that a new Visit can be created
+ String delegatorName = (String) session.getAttribute("delegatorName");
+ // also save the shopping cart if we have one
+ // DON'T save the cart, causes too many problems: security issues with things done in cart to easy to miss, especially bad on public systems; was put in here because of the "not me" link for auto-login stuff, but that is a small problem compared to what it causes
+ //ShoppingCart shoppingCart = (ShoppingCart) session.getAttribute("shoppingCart");
+
+ session.invalidate();
+ session = request.getSession(true);
+
+ if (currCatalog != null) session.setAttribute("CURRENT_CATALOG_ID", currCatalog);
+ if (delegatorName != null) session.setAttribute("delegatorName", delegatorName);
+ // DON'T save the cart, causes too many problems: if (shoppingCart != null) session.setAttribute("shoppingCart", new WebShoppingCart(shoppingCart, session));
+ }
+
+ public static String autoLoginSet(HttpServletRequest request, HttpServletResponse response) {
+ GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
+ HttpSession session = request.getSession();
+ GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
+ if (userLogin != null) {
+ Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId"));
+ autoLoginCookie.setMaxAge(60 * 60 * 24 * 365);
+ autoLoginCookie.setPath("/");
+ response.addCookie(autoLoginCookie);
+ return autoLoginCheck(delegator, session, userLogin.getString("userLoginId"));
+ } else {
+ return "success";
+ }
+ }
+
+ protected static String getAutoLoginCookieName(HttpServletRequest request) {
+ return UtilHttp.getApplicationName(request) + ".autoUserLoginId";
+ }
+
+ public static String getAutoUserLoginId(HttpServletRequest request) {
+ String autoUserLoginId = null;
+ Cookie[] cookies = request.getCookies();
+ if (Debug.verboseOn()) Debug.logVerbose("Cookies:" + cookies, module);
+ if (cookies != null) {
+ for (int i = 0; i < cookies.length; i++) {
+ if (cookies[i].getName().equals(getAutoLoginCookieName(request))) {
+ autoUserLoginId = cookies[i].getValue();
+ break;
+ }
+ }
+ }
+ return autoUserLoginId;
+ }
+
+ public static String autoLoginCheck(HttpServletRequest request, HttpServletResponse response) {
+ GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
+ HttpSession session = request.getSession();
+
+ return autoLoginCheck(delegator, session, getAutoUserLoginId(request));
+ }
+
+ private static String autoLoginCheck(GenericDelegator delegator, HttpSession session, String autoUserLoginId) {
+ if (autoUserLoginId != null) {
+ Debug.logInfo("Running autoLogin check.", module);
+ try {
+ GenericValue autoUserLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", autoUserLoginId));
+ GenericValue person = null;
+ GenericValue group = null;
+ if (autoUserLogin != null) {
+ person = delegator.findByPrimaryKey("Person", UtilMisc.toMap("partyId", autoUserLogin.getString("partyId")));
+ group = delegator.findByPrimaryKey("PartyGroup", UtilMisc.toMap("partyId", autoUserLogin.getString("partyId")));
+ session.setAttribute("autoUserLogin", autoUserLogin);
+ }
+ if (person != null) {
+ session.setAttribute("autoName", person.getString("firstName") + " " + person.getString("lastName"));
+ } else if (group != null) {
+ session.setAttribute("autoName", group.getString("groupName"));
+ }
+ } catch (GenericEntityException e) {
+ Debug.logError(e, "Cannot get autoUserLogin information: " + e.getMessage(), module);
+ }
+ }
+ return "success";
+ }
+
+ public static String autoLoginRemove(HttpServletRequest request, HttpServletResponse response) {
+ HttpSession session = request.getSession();
+ GenericValue userLogin = (GenericValue) session.getAttribute("autoUserLogin");
+
+ // remove the cookie
+ if (userLogin != null) {
+ Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId"));
+ autoLoginCookie.setMaxAge(0);
+ autoLoginCookie.setPath("/");
+ response.addCookie(autoLoginCookie);
+ }
+ // remove the session attributes
+ session.removeAttribute("autoUserLogin");
+ session.removeAttribute("autoName");
+ // logout the user if logged in.
+ if (session.getAttribute("userLogin") != null) {
+ request.setAttribute("_AUTO_LOGIN_LOGOUT_", new Boolean(true));
+ return logout(request, response);
+ }
+ return "success";
+ }
+
+ public static String checkExternalLoginKey(HttpServletRequest request, HttpServletResponse response) {
+ HttpSession session = request.getSession();
+
+ String externalKey = request.getParameter(LoginWorker.EXTERNAL_LOGIN_KEY_ATTR);
+ if (externalKey == null) return "success";
+
+ GenericValue userLogin = (GenericValue) LoginWorker.externalLoginKeys.get(externalKey);
+ if (userLogin != null) {
+ // found userLogin, do the external login...
+
+ // if the user is already logged in and the login is different, logout the other user
+ GenericValue currentUserLogin = (GenericValue) session.getAttribute("userLogin");
+ if (currentUserLogin != null) {
+ if (currentUserLogin.getString("userLoginId").equals(userLogin.getString("userLoginId"))) {
+ // is the same user, just carry on...
+ return "success";
+ }
+
+ // logout the current user and login the new user...
+ logout(request, response);
+ // ignore the return value; even if the operation failed we want to set the new UserLogin
+ }
+
+ doBasicLogin(userLogin, request);
+ } else {
+ Debug.logWarning("Could not find userLogin for external login key: " + externalKey, module);
+ }
+
+ return "success";
+ }
+
+ public static boolean isFlaggedLoggedOut(GenericValue userLogin) {
+ if ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "login.disable.global.logout"))) {
+ return false;
+ }
+ if (userLogin == null || userLogin.get("userLoginId") == null) {
+ return true;
+ }
+ // refresh the login object -- maybe cache this?
+ try {
+ userLogin.refreshFromCache();
+ } catch (GenericEntityException e) {
+ Debug.logWarning(e, "Unable to refresh UserLogin", module);
+ }
+ return (userLogin.get("hasLoggedOut") != null ?
+ "Y".equalsIgnoreCase(userLogin.getString("hasLoggedOut")) : false);
+ }
+
+ protected static boolean hasBasePermission(GenericValue userLogin, HttpServletRequest request) {
+ ServletContext context = (ServletContext) request.getAttribute("servletContext");
+ Security security = (Security) request.getAttribute("security");
+
+ String serverId = (String) context.getAttribute("_serverId");
+ String contextPath = request.getContextPath();
+
+ ComponentConfig.WebappInfo info = ComponentConfig.getWebAppInfo(serverId, contextPath);
+ if (security != null) {
+ if (info != null) {
+ String[] permissions = info.getBasePermission();
+ for (int i = 0; i < permissions.length; i++) {
+ if (!"NONE".equals(permissions[i]) && !security.hasEntityPermission(permissions[i], "_VIEW", userLogin)) {
+ return false;
+ }
+ }
+ } else {
+ Debug.logInfo("No webapp configuration found for : " + serverId + " / " + contextPath, module);
+ }
+ } else {
+ Debug.logWarning("Received a null Security object from HttpServletRequest", module);
+ }
+
+ return true;
+ }
}
diff --git a/framework/webtools/webapp/webtools/WEB-INF/controller.xml b/framework/webtools/webapp/webtools/WEB-INF/controller.xml
index 9fc1f68ae8..c5ff4f629a 100644
--- a/framework/webtools/webapp/webtools/WEB-INF/controller.xml
+++ b/framework/webtools/webapp/webtools/WEB-INF/controller.xml
@@ -41,7 +41,7 @@ under the License.
-
+
@@ -52,21 +52,21 @@ under the License.
Verify a user is logged in.
-
+
-
+
-
+