Author: mthl
Date: Tue Feb 26 22:58:53 2019 New Revision: 1854433 URL: http://svn.apache.org/viewvc?rev=1854433&view=rev Log: Improved: Use Optional for ‘getWebappInfo’ (OFBIZ-10606) Adapt ‘LoginWorker#autoLoginSet’ which is its unique caller. Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java?rev=1854433&r1=1854432&r2=1854433&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java Tue Feb 26 22:58:53 2019 @@ -23,6 +23,7 @@ import java.util.Collection; 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 class WebAppCache { * @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. Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java?rev=1854433&r1=1854432&r2=1854433&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java Tue Feb 26 22:58:53 2019 @@ -30,6 +30,7 @@ import java.util.HashMap; 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 class LoginWorker { 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)); |
Free forum by Nabble | Edit this page |