This repository has been archived by the owner on Jan 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLF-8185 : fix critical Sonar issues (#343)
All of critical Sonar issues found in the Platform project are of type "Synchronize this lazy initialization of ...". A lot of static field are used in the trial/account setup/register setup, which are initialized lazily (not at the declaration time). This fix refactors this process to remove most of these static fields and methods, and use services instead. It also adds some unit tests.
- Loading branch information
Thomas Delhoménie
authored
Oct 31, 2018
1 parent
6afe671
commit 85d035f
Showing
24 changed files
with
1,120 additions
and
829 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 29 additions & 49 deletions
78
...n/src/main/java/org/exoplatform/platform/common/account/setup/web/AccountSetupFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,42 @@ | ||
package org.exoplatform.platform.common.account.setup.web; | ||
|
||
import org.exoplatform.commons.api.settings.SettingService; | ||
import org.exoplatform.commons.api.settings.SettingValue; | ||
import org.exoplatform.commons.api.settings.data.Context; | ||
import org.exoplatform.commons.api.settings.data.Scope; | ||
import org.exoplatform.commons.utils.PropertyManager; | ||
import org.exoplatform.container.ExoContainerContext; | ||
import org.exoplatform.container.PortalContainer; | ||
import org.exoplatform.services.log.ExoLogger; | ||
import org.exoplatform.services.log.Log; | ||
import org.exoplatform.web.filter.Filter; | ||
import java.io.IOException; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
import org.exoplatform.container.ExoContainer; | ||
import org.exoplatform.container.PortalContainer; | ||
import org.exoplatform.web.filter.Filter; | ||
|
||
/** | ||
* @author <a href="[email protected]">Fbradai</a> | ||
*/ | ||
public class AccountSetupFilter implements Filter { | ||
private static final String PLF_PLATFORM_EXTENSION_SERVLET_CTX = "/platform-extension"; | ||
private static final String ACCOUNT_SETUP_SERVLET = "/accountSetup"; | ||
private static final String ACCOUNT_SETUP_SKIP_PROPERTY = "accountsetup.skip"; | ||
|
||
private static final Log LOG = ExoLogger.getLogger(AccountSetupFilter.class); | ||
SettingService settingService ; | ||
private static String REST_URI; | ||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
HttpServletRequest httpServletRequest = (HttpServletRequest)request; | ||
HttpServletResponse httpServletResponse = (HttpServletResponse)response; | ||
REST_URI = ExoContainerContext.getCurrentContainer().getContext().getRestContextName(); | ||
boolean isDevMod = PropertyManager.isDevelopping(); | ||
Boolean isSetupSkip = AccountSetup.SETUP_SKIP; | ||
String propertySetupSkip = PropertyManager.getProperty(ACCOUNT_SETUP_SKIP_PROPERTY); | ||
if(propertySetupSkip == null){ | ||
LOG.debug("Property accountsetup.skip not found in configuration.properties "); | ||
propertySetupSkip = "false"; | ||
} | ||
settingService = (SettingService) PortalContainer.getInstance().getComponentInstanceOfType(SettingService.class); | ||
|
||
boolean setupDone = false; | ||
SettingValue accountSetupNode = settingService.get(Context.GLOBAL, Scope.GLOBAL, AccountSetup.ACCOUNT_SETUP_NODE); | ||
if(accountSetupNode != null) { | ||
setupDone = true; | ||
} else if (isSetupSkip || propertySetupSkip.equals("true")) { | ||
settingService.set(Context.GLOBAL, Scope.GLOBAL, AccountSetup.ACCOUNT_SETUP_NODE, SettingValue.create("setup over:" + "true")); | ||
setupDone = true; | ||
} | ||
String requestUri = httpServletRequest.getRequestURI(); | ||
boolean isRestUri = (requestUri.contains(REST_URI)); | ||
if((!setupDone)&&(!isDevMod)&&(!isRestUri)) { | ||
|
||
ServletContext platformExtensionContext = httpServletRequest.getSession().getServletContext().getContext(PLF_PLATFORM_EXTENSION_SERVLET_CTX); | ||
platformExtensionContext.getRequestDispatcher(ACCOUNT_SETUP_SERVLET).forward(httpServletRequest, httpServletResponse); | ||
return; | ||
} | ||
chain.doFilter(request, response); | ||
private static final String PLF_PLATFORM_EXTENSION_SERVLET_CTX = "/platform-extension"; | ||
|
||
private static final String ACCOUNT_SETUP_SERVLET = "/accountSetup"; | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
HttpServletRequest httpServletRequest = (HttpServletRequest) request; | ||
HttpServletResponse httpServletResponse = (HttpServletResponse) response; | ||
|
||
ExoContainer container = PortalContainer.getInstance(); | ||
AccountSetupService accountSetupService = container.getComponentInstanceOfType(AccountSetupService.class); | ||
|
||
boolean setupDone = accountSetupService.mustSkipAccountSetup(); | ||
|
||
String requestUri = httpServletRequest.getRequestURI(); | ||
boolean isRestUri = requestUri.contains(container.getContext().getRestContextName()); | ||
if (!setupDone && !isRestUri) { | ||
ServletContext platformExtensionContext = httpServletRequest.getSession() | ||
.getServletContext() | ||
.getContext(PLF_PLATFORM_EXTENSION_SERVLET_CTX); | ||
platformExtensionContext.getRequestDispatcher(ACCOUNT_SETUP_SERVLET).forward(httpServletRequest, httpServletResponse); | ||
return; | ||
} | ||
chain.doFilter(request, response); | ||
} | ||
} |
Oops, something went wrong.