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
This commit is contained in:
@@ -42,6 +42,7 @@ under the License.
|
||||
<preprocessor>
|
||||
<!-- Events to run on every request before security (chains exempt) -->
|
||||
<event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="check509CertLogin"/>
|
||||
<event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="checkRequestHeaderLogin"/>
|
||||
<event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="checkExternalLoginKey"/>
|
||||
</preprocessor>
|
||||
<postprocessor>
|
||||
|
||||
@@ -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*.*$
|
||||
|
||||
|
||||
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user