Change halo properties boxed bool type to primitive bool type

pull/146/head
johnniang 2019-04-20 22:52:20 +08:00
parent 287250358e
commit fe391c93e7
8 changed files with 23 additions and 17 deletions

View File

@ -95,7 +95,7 @@ public class HaloConfiguration {
ApiAuthenticationFilter apiFilter = new ApiAuthenticationFilter(haloProperties); ApiAuthenticationFilter apiFilter = new ApiAuthenticationFilter(haloProperties);
DefaultAuthenticationFailureHandler failureHandler = new DefaultAuthenticationFailureHandler(); DefaultAuthenticationFailureHandler failureHandler = new DefaultAuthenticationFailureHandler();
failureHandler.setProductionEnv(haloProperties.getProductionEnv()); failureHandler.setProductionEnv(haloProperties.isProductionEnv());
failureHandler.setObjectMapper(objectMapper); failureHandler.setObjectMapper(objectMapper);
// Set failure handler // Set failure handler
@ -117,7 +117,7 @@ public class HaloConfiguration {
AdminAuthenticationFilter adminAuthenticationFilter = new AdminAuthenticationFilter(cacheStore, userService, haloProperties); AdminAuthenticationFilter adminAuthenticationFilter = new AdminAuthenticationFilter(cacheStore, userService, haloProperties);
AdminAuthenticationFailureHandler failureHandler = new AdminAuthenticationFailureHandler(); AdminAuthenticationFailureHandler failureHandler = new AdminAuthenticationFailureHandler();
failureHandler.setProductionEnv(haloProperties.getProductionEnv()); failureHandler.setProductionEnv(haloProperties.isProductionEnv());
failureHandler.setObjectMapper(objectMapper); failureHandler.setObjectMapper(objectMapper);
// Config the admin filter // Config the admin filter

View File

@ -61,22 +61,22 @@ public class SwaggerConfiguration {
@Bean @Bean
public Docket haloDefaultApi() { public Docket haloDefaultApi() {
log.debug("Doc disabled: [{}]", haloProperties.getDocDisabled()); log.debug("Doc disabled: [{}]", haloProperties.isDocDisabled());
// TODO Build with different security configuration // TODO Build with different security configuration
return buildApiDocket("run.halo.app.portal.api", return buildApiDocket("run.halo.app.portal.api",
"run.halo.app.web.controller.portal.api", "run.halo.app.web.controller.portal.api",
"/api/**") "/api/**")
.enable(!haloProperties.getDocDisabled()); .enable(!haloProperties.isDocDisabled());
} }
@Bean @Bean
public Docket haloAdminApi() { public Docket haloAdminApi() {
log.debug("Doc disabled: [{}]", haloProperties.getDocDisabled()); log.debug("Doc disabled: [{}]", haloProperties.isDocDisabled());
// TODO Build with different security configuration // TODO Build with different security configuration
return buildApiDocket("run.halo.app.admin", return buildApiDocket("run.halo.app.admin",
"run.halo.app.web.controller.admin", "run.halo.app.web.controller.admin",
"/api/admin/**") "/api/admin/**")
.enable(!haloProperties.getDocDisabled()); .enable(!haloProperties.isDocDisabled());
} }
@Bean @Bean

View File

@ -1,6 +1,7 @@
package run.halo.app.config; package run.halo.app.config;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import freemarker.template.TemplateExceptionHandler;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.jackson.JsonComponentModule; import org.springframework.boot.jackson.JsonComponentModule;
@ -86,7 +87,7 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
registry.addResourceHandler("/admin/**") registry.addResourceHandler("/admin/**")
.addResourceLocations("classpath:/static/admin/"); .addResourceLocations("classpath:/static/admin/");
if (!haloProperties.getDocDisabled()) { if (!haloProperties.isDocDisabled()) {
// If doc is enable // If doc is enable
registry.addResourceHandler("swagger-ui.html") registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/"); .addResourceLocations("classpath:/META-INF/resources/");
@ -106,10 +107,13 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
* @return new FreeMarkerConfigurer * @return new FreeMarkerConfigurer
*/ */
@Bean @Bean
public FreeMarkerConfigurer freemarkerConfig() { public FreeMarkerConfigurer freemarkerConfig(HaloProperties haloProperties) {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer(); FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPaths(FILE_PROTOCOL + haloProperties.getWorkDir() + "templates/", "classpath:/templates/"); configurer.setTemplateLoaderPaths(FILE_PROTOCOL + haloProperties.getWorkDir() + "templates/", "classpath:/templates/");
configurer.setDefaultEncoding("UTF-8"); configurer.setDefaultEncoding("UTF-8");
if (haloProperties.isProductionEnv()) {
configurer.getConfiguration().setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
}
return configurer; return configurer;
} }

View File

@ -16,17 +16,17 @@ public class HaloProperties {
/** /**
* Doc api disabled. (Default is true) * Doc api disabled. (Default is true)
*/ */
private Boolean docDisabled = true; private boolean docDisabled = true;
/** /**
* Production env. (Default is true) * Production env. (Default is true)
*/ */
private Boolean productionEnv = true; private boolean productionEnv = true;
/** /**
* Authentication enabled * Authentication enabled
*/ */
private Boolean authEnabled = true; private boolean authEnabled = true;
/** /**
* Work directory. * Work directory.

View File

@ -57,7 +57,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
this.initThemes(); this.initThemes();
// Init user in development environment // Init user in development environment
if (!haloProperties.getProductionEnv()) { if (!haloProperties.isProductionEnv()) {
initAnTestUserIfAbsent(); initAnTestUserIfAbsent();
} }
} }
@ -89,7 +89,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
log.info("Halo started at {}", blogUrl); log.info("Halo started at {}", blogUrl);
// TODO admin may be changeable // TODO admin may be changeable
log.info("Halo admin started at {}/admin", blogUrl); log.info("Halo admin started at {}/admin", blogUrl);
if (!haloProperties.getDocDisabled()) { if (!haloProperties.isDocDisabled()) {
log.debug("Halo doc was enable at {}/swagger-ui.html", blogUrl); log.debug("Halo doc was enable at {}/swagger-ui.html", blogUrl);
} }
} }
@ -140,7 +140,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
// Create theme folder // Create theme folder
Path themePath = themeService.getBasePath(); Path themePath = themeService.getBasePath();
if (!haloProperties.getProductionEnv() || Files.notExists(themePath)) { if (!haloProperties.isProductionEnv() || Files.notExists(themePath)) {
log.info("Copying theme folder from [{}] to [{}]", source, themePath); log.info("Copying theme folder from [{}] to [{}]", source, themePath);
FileUtils.copyFolder(source, themePath); FileUtils.copyFolder(source, themePath);

View File

@ -125,7 +125,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
if (failureHandler == null) { if (failureHandler == null) {
// Create default authentication failure handler // Create default authentication failure handler
DefaultAuthenticationFailureHandler failureHandler = new DefaultAuthenticationFailureHandler(); DefaultAuthenticationFailureHandler failureHandler = new DefaultAuthenticationFailureHandler();
failureHandler.setProductionEnv(haloProperties.getProductionEnv()); failureHandler.setProductionEnv(haloProperties.isProductionEnv());
this.failureHandler = failureHandler; this.failureHandler = failureHandler;
} }

View File

@ -66,7 +66,7 @@ public class AdminAuthenticationFilter extends AbstractAuthenticationFilter {
@Override @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
if (!haloProperties.getAuthEnabled()) { if (!haloProperties.isProductionEnv()) {
List<User> users = userService.listAll(); List<User> users = userService.listAll();
if (!users.isEmpty()) { if (!users.isEmpty()) {
// Set security context // Set security context

View File

@ -83,8 +83,10 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
@Override @Override
public Map<String, Object> listAsMapBy(String themeId) { public Map<String, Object> listAsMapBy(String themeId) {
List<ThemeSetting> themeSettings = listBy(themeId);
// TODO Convert to corresponding data type // TODO Convert to corresponding data type
return ServiceUtils.convertToMap(listBy(themeId), ThemeSetting::getKey, ThemeSetting::getValue); return ServiceUtils.convertToMap(themeSettings, ThemeSetting::getKey, ThemeSetting::getValue);
} }
/** /**