Implemented: Navigate from a domain to another with automated signed in

authentication
(OFBIZ-10307)

This uses a JWT Token authentication to get from one domain, where you are 
signed in, to another domain where you get signed in automatically. 
Something like ExternalLoginKey or Tomcat SSO, but not on the same domain.

In the example component, the FormWidgetExamples screen contains 2 new fields 
in the LinksExampleForm which demonstrate the use from a local instance to the
trunk demo instance.

A simple documentation is available in 
  framework\webapp\src\docs\asciidoc\_include\wa-cross-domains-SSO.adoc

Thanks: Taher for review

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1844880 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2018-10-26 09:32:46 +00:00
parent a9c4eb3427
commit fbfa0daa5a
8 changed files with 269 additions and 22 deletions
@@ -51,6 +51,8 @@ import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.util.EntityUtilProperties;
import org.apache.ofbiz.webapp.control.JWTManager;
import org.apache.ofbiz.webapp.control.LoginWorker;
import org.apache.ofbiz.widget.model.ThemeFactory;
import org.apache.ofbiz.widget.renderer.VisualTheme;
@@ -379,4 +381,20 @@ public class CommonEvents {
return "success";
}
public static String loadJWT(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
Delegator delegator = (Delegator) request.getAttribute("delegator");
Map<String, String> types = new HashMap<>();
String webAppName = UtilHttp.getApplicationName(request);
String securedUserLoginId = LoginWorker.getSecuredUserLoginId(request, webAppName);
if (securedUserLoginId != null) {
types.put("userLoginId", securedUserLoginId);
int ttlSeconds = (int) Long.parseLong(EntityUtilProperties.getPropertyValue("security", "security.jwt.token.expireTime", "10", delegator));
String token = JWTManager.createJwt(delegator, types, ttlSeconds);
writeJSONtoResponse(JSON.from(token), request, response);
} else {
Debug.logWarning("No securedUserLoginId cookie was found for this application", module);
}
return "success";
}
}