Skip to content
Permalink
Browse files

Improved: Use Optional for ‘getWebappInfo’ (OFBIZ-10606)

Adapt ‘LoginWorker#autoLoginSet’ which is its unique caller.



git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1854433 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Feb 26, 2019
1 parent 9d209d9 commit 9b5340fd3a66e957d190637b1061c376313e441e
@@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Optional;
import java.util.TreeMap;
import java.util.function.Supplier;

@@ -128,11 +129,10 @@ public WebAppCache(Supplier<Collection<ComponentConfig>>supplier) {
* @return the corresponding web application information
* @throws NullPointerException when {@code serverName} is {@code null}
*/
public WebappInfo getWebappInfo(String serverName, String webAppName) {
public Optional<WebappInfo> getWebappInfo(String serverName, String webAppName) {
return getAppBarWebInfos(serverName).stream()
.filter(app -> app.getMountPoint().replaceAll("[/*]", "").equals(webAppName))
.findFirst()
.orElse(null);
.findFirst();
}

// Instance of the cache shared by the loginWorker and Freemarker appbar rendering.
@@ -30,6 +30,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -926,11 +927,11 @@ public static String autoLoginSet(HttpServletRequest request, HttpServletRespons
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
String serverId = (String) request.getServletContext().getAttribute("_serverId");
String applicationName = UtilHttp.getApplicationName(request);
WebappInfo webappInfo = webapps.getWebappInfo(serverId, applicationName);
Optional<WebappInfo> webappInfo = webapps.getWebappInfo(serverId, applicationName);

if (userLogin != null &&
((webappInfo != null && webappInfo.isAutologinCookieUsed())
|| webappInfo == null)) { // When using an empty mountpoint, ie using root as mountpoint. Beware: works only for 1 webapp!
// When using an empty mountpoint, ie using root as mountpoint. Beware: works only for 1 webapp!
webappInfo.map(WebappInfo::isAutologinCookieUsed).orElse(!webappInfo.isPresent())) {
Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId"));
autoLoginCookie.setMaxAge(60 * 60 * 24 * 365);
autoLoginCookie.setDomain(EntityUtilProperties.getPropertyValue("url", "cookie.domain", delegator));

0 comments on commit 9b5340f

Please sign in to comment.
You can’t perform that action at this time.