diff --git a/framework/common/webcommon/WEB-INF/common-controller.xml b/framework/common/webcommon/WEB-INF/common-controller.xml index 1bcbff55bd..767e072074 100644 --- a/framework/common/webcommon/WEB-INF/common-controller.xml +++ b/framework/common/webcommon/WEB-INF/common-controller.xml @@ -42,6 +42,7 @@ under the License. + diff --git a/framework/security/config/security.properties b/framework/security/config/security.properties index 66d1674b7d..c7c664b1b1 100644 --- a/framework/security/config/security.properties +++ b/framework/security/config/security.properties @@ -63,6 +63,9 @@ password.lowercase=false # -- should we allow x509 certificate login security.login.cert.allow=true +# -- HTTP header based ID (for integrations; uncomment to enable) +#security.login.http.header=REMOTE_USER + # -- pattern for the userlogin id in CN section of certificate security.login.cert.pattern=^(\\w*\\s?\\w*)\\W*.*$ diff --git a/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java b/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java index 0c44345f42..7d29770ac1 100644 --- a/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java +++ b/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java @@ -603,6 +603,53 @@ public class LoginWorker { return "success"; } + // preprocessor method to login a user from a HTTP request header (configured in security.properties) + public static String checkRequestHeaderLogin(HttpServletRequest request, HttpServletResponse response) { + String httpHeader = UtilProperties.getPropertyValue("security.properties", "security.login.http.header", null); + + // make sure the header field is set in security.properties; if not, then this is disabled and just return + if (UtilValidate.isNotEmpty(httpHeader)) { + + // make sure the user isn't already logged in + HttpSession session = request.getSession(); + GenericValue currentUserLogin = (GenericValue) session.getAttribute("userLogin"); + if (currentUserLogin != null) { + String hasLoggedOut = currentUserLogin.getString("hasLoggedOut"); + if (hasLoggedOut != null && "Y".equals(hasLoggedOut)) { + currentUserLogin = null; + } + } + + // user is not logged in; check the header field + if (currentUserLogin == null) { + String headerValue = request.getHeader(httpHeader); + if (UtilValidate.isNotEmpty(headerValue)) { + GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); + + // header field found; log the user in + try { + GenericValue userLogin = delegator.findOne("UserLogin", false, "userLoginId", headerValue); + if (userLogin != null) { + String enabled = userLogin.getString("enabled"); + if (enabled == null || "Y".equals(enabled)) { + userLogin.set("hasLoggedOut", "N"); + userLogin.store(); + + // login the user + Map ulSessionMap = LoginServices.getUserLoginSession(userLogin); + return doMainLogin(request, response, userLogin, ulSessionMap); // doing the main login + } + } + } catch (GeneralException e) { + Debug.logError(e, module); + } + } + } + } + + return "success"; + } + // preprocessor method to login a user w/ client certificate see security.properties to configure the pattern of CN public static String check509CertLogin(HttpServletRequest request, HttpServletResponse response) { boolean doCheck = "true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "security.login.cert.allow", "true"));