From 5095e4e09fa1ee492db2e6eeefbb8eb0d3c951c3 Mon Sep 17 00:00:00 2001 From: Andrew Zeneski Date: Tue, 13 May 2008 20:59:03 +0000 Subject: [PATCH] added support for third party policy servicers; setting the userLoginId in a request header, ofbiz will assume the user has already been authenticated and log the user in. This is DISABLED by default (see security.properties) be sure your policy server is running in front of ofbiz to avoid security issues (spoofing). Jira: OFBIZ-1781 git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@656008 13f79535-47bb-0310-9956-ffa450edef68 --- .../webcommon/WEB-INF/common-controller.xml | 1 + framework/security/config/security.properties | 3 ++ .../org/ofbiz/webapp/control/LoginWorker.java | 47 +++++++++++++++++++ 3 files changed, 51 insertions(+) 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"));