From cfc8207919a13d4aadd3d0c7e72b2e54a0f5475e Mon Sep 17 00:00:00 2001 From: johnniang Date: Mon, 6 May 2019 17:13:53 +0800 Subject: [PATCH] Add installation validation --- .../app/security/filter/ApiAuthenticationFilter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java b/src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java index 4e1fd1a5..898b57b5 100644 --- a/src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java +++ b/src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java @@ -8,7 +8,9 @@ import org.springframework.util.Assert; import run.halo.app.config.properties.HaloProperties; import run.halo.app.exception.AuthenticationException; import run.halo.app.exception.ForbiddenException; +import run.halo.app.exception.NotInstallException; import run.halo.app.model.properties.OtherProperties; +import run.halo.app.model.properties.PrimaryProperties; import run.halo.app.service.OptionService; import javax.servlet.FilterChain; @@ -40,6 +42,15 @@ public class ApiAuthenticationFilter extends AbstractAuthenticationFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + // Check whether the blog is installed or not + Boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false); + + if (!isInstalled) { + // If not installed + getFailureHandler().onFailure(request, response, new NotInstallException("The blog has not been initialized yet!")); + return; + } + // Get token String token = getTokenFromRequest(request); -- GitLab