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

View File

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

View File

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

View File

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

View File

@ -57,7 +57,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
this.initThemes();
// Init user in development environment
if (!haloProperties.getProductionEnv()) {
if (!haloProperties.isProductionEnv()) {
initAnTestUserIfAbsent();
}
}
@ -89,7 +89,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
log.info("Halo started at {}", blogUrl);
// TODO admin may be changeable
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);
}
}
@ -140,7 +140,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
// Create theme folder
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);
FileUtils.copyFolder(source, themePath);

View File

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

View File

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

View File

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