-
Notifications
You must be signed in to change notification settings - Fork 1
LPD-72782 Create a configuration to remove client's IP from Liferay object #5209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: (c) 2025 Liferay, Inc. https://liferay.com | ||
| * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 | ||
| */ | ||
|
|
||
| package com.liferay.frontend.js.web.internal.configuration; | ||
|
|
||
| import aQute.bnd.annotation.metatype.Meta; | ||
|
|
||
| import com.liferay.portal.configuration.metatype.annotations.ExtendedObjectClassDefinition; | ||
|
|
||
| /** | ||
| * @author Iván Zaera Avellón | ||
| */ | ||
| @ExtendedObjectClassDefinition( | ||
| category = "infrastructure", | ||
| scope = ExtendedObjectClassDefinition.Scope.COMPANY, strictScope = true | ||
| ) | ||
| @Meta.OCD( | ||
| id = "com.liferay.frontend.js.web.internal.configuration.LiferayGlobalObjectConfiguration", | ||
| localization = "content/Language", | ||
| name = "liferay-global-object-configuration-name" | ||
| ) | ||
| public interface LiferayGlobalObjectConfiguration { | ||
|
|
||
| @Meta.AD( | ||
| deflt = "false", description = "disable-get-remote-methods-help", | ||
| name = "disable-get-remote-methods", required = false | ||
| ) | ||
| public boolean disableGetRemoteMethods(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,14 @@ | |
| package com.liferay.frontend.js.web.internal.servlet.taglib; | ||
|
|
||
| import com.liferay.exportimport.kernel.staging.Staging; | ||
| import com.liferay.frontend.js.web.internal.configuration.LiferayGlobalObjectConfiguration; | ||
| import com.liferay.layout.seo.kernel.LayoutSEOLink; | ||
| import com.liferay.layout.seo.kernel.LayoutSEOLinkManager; | ||
| import com.liferay.petra.string.CharPool; | ||
| import com.liferay.petra.string.StringBundler; | ||
| import com.liferay.petra.string.StringPool; | ||
| import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil; | ||
| import com.liferay.portal.configuration.module.configuration.ConfigurationProvider; | ||
| import com.liferay.portal.kernel.content.security.policy.ContentSecurityPolicyNonceProviderUtil; | ||
| import com.liferay.portal.kernel.exception.PortalException; | ||
| import com.liferay.portal.kernel.feature.flag.FeatureFlag; | ||
|
|
@@ -23,6 +26,7 @@ | |
| import com.liferay.portal.kernel.model.LayoutTypePortlet; | ||
| import com.liferay.portal.kernel.model.User; | ||
| import com.liferay.portal.kernel.model.impl.VirtualLayout; | ||
| import com.liferay.portal.kernel.module.configuration.ConfigurationException; | ||
| import com.liferay.portal.kernel.security.auth.AuthToken; | ||
| import com.liferay.portal.kernel.security.permission.ActionKeys; | ||
| import com.liferay.portal.kernel.service.permission.LayoutPermission; | ||
|
|
@@ -63,6 +67,7 @@ | |
| import java.text.Format; | ||
| import java.text.SimpleDateFormat; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.TimeZone; | ||
|
|
@@ -87,6 +92,9 @@ public void include( | |
| HttpServletResponse httpServletResponse, String key) | ||
| throws IOException { | ||
|
|
||
| LiferayGlobalObjectConfiguration liferayGlobalObjectConfiguration = | ||
| _getLiferayGlobalObjectConfiguration(httpServletRequest); | ||
|
|
||
| PrintWriter printWriter = httpServletResponse.getWriter(); | ||
|
|
||
| printWriter.print("<script"); | ||
|
|
@@ -107,7 +115,8 @@ public void include( | |
| _renderLiferayPortlet(sb); | ||
| _renderLiferayPortletKeys(sb); | ||
| _renderLiferayPropsValues(httpServletRequest, sb); | ||
| _renderLiferayThemeDisplay(httpServletRequest, sb); | ||
| _renderLiferayThemeDisplay( | ||
| httpServletRequest, liferayGlobalObjectConfiguration, sb); | ||
| _renderLiferayUtil(sb); | ||
|
|
||
| _renderValue( | ||
|
|
@@ -210,6 +219,35 @@ else if (dayIndex < monthIndex) { | |
| return dateFormatPattern; | ||
| } | ||
|
|
||
| private LiferayGlobalObjectConfiguration | ||
| _getLiferayGlobalObjectConfiguration( | ||
| HttpServletRequest httpServletRequest) { | ||
|
|
||
| LiferayGlobalObjectConfiguration liferayGlobalObjectConfiguration; | ||
|
|
||
| long companyId = _portal.getCompanyId(httpServletRequest); | ||
|
|
||
| try { | ||
| liferayGlobalObjectConfiguration = | ||
| _configurationProvider.getCompanyConfiguration( | ||
| LiferayGlobalObjectConfiguration.class, companyId); | ||
| } | ||
| catch (ConfigurationException configurationException) { | ||
| if (_log.isWarnEnabled()) { | ||
| _log.warn( | ||
| "Using default configuration for company " + companyId, | ||
| configurationException); | ||
| } | ||
|
|
||
| liferayGlobalObjectConfiguration = | ||
| ConfigurableUtil.createConfigurable( | ||
| LiferayGlobalObjectConfiguration.class, | ||
| Collections.emptyMap()); | ||
| } | ||
|
|
||
| return liferayGlobalObjectConfiguration; | ||
| } | ||
|
|
||
| private void _renderLiferayAUI( | ||
| HttpServletRequest httpServletRequest, StringBundler sb) { | ||
|
|
||
|
|
@@ -499,7 +537,9 @@ private void _renderLiferayPropsValues( | |
| } | ||
|
|
||
| private void _renderLiferayThemeDisplay( | ||
| HttpServletRequest httpServletRequest, StringBundler sb) | ||
| HttpServletRequest httpServletRequest, | ||
| LiferayGlobalObjectConfiguration liferayGlobalObjectConfiguration, | ||
| StringBundler sb) | ||
| throws PortalException { | ||
|
|
||
| sb.append("ThemeDisplay: {\n"); | ||
|
|
@@ -581,8 +621,11 @@ private void _renderLiferayThemeDisplay( | |
| _renderMethod("getPlid", sb, themeDisplay.getPlid()); | ||
| _renderMethod("getPortalURL", sb, themeDisplay.getPortalURL()); | ||
| _renderMethod("getRealUserId", sb, themeDisplay.getRealUserId()); | ||
| _renderMethod("getRemoteAddr", sb, themeDisplay.getRemoteAddr()); | ||
| _renderMethod("getRemoteHost", sb, themeDisplay.getRemoteHost()); | ||
|
|
||
| if (!liferayGlobalObjectConfiguration.disableGetRemoteMethods()) { | ||
| _renderMethod("getRemoteAddr", sb, themeDisplay.getRemoteAddr()); | ||
| _renderMethod("getRemoteHost", sb, themeDisplay.getRemoteHost()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to omit the function or add one that returns Subtle difference but important from the caller perspective. Is there a "preferred" way to make client code better prepared to handle this scenario?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove or at least return However, since in the end we will be removing/deprecating as much as we can from the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we just agreed on emitting the method but with code that throws an exception so that caller knows what to do to enable it back |
||
| } | ||
|
|
||
| Group scopeGroup = themeDisplay.getScopeGroup(); | ||
|
|
||
|
|
@@ -751,6 +794,9 @@ else if (value instanceof String) { | |
| @Reference | ||
| private AuthToken _authToken; | ||
|
|
||
| @Reference | ||
| private ConfigurationProvider _configurationProvider; | ||
|
|
||
| private final Map<Locale, String> _displayNames = new ConcurrentHashMap<>(); | ||
|
|
||
| @Reference | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ | |
|
|
||
| merge(target[key], source[key]); | ||
| } | ||
| else { | ||
| else { | ||
| Object.assign(target, { [key]: source[key] }); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.