diff options
Diffstat (limited to 'src/main/java/com/juick/config/WebConfig.java')
-rw-r--r-- | src/main/java/com/juick/config/WebConfig.java | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/src/main/java/com/juick/config/WebConfig.java b/src/main/java/com/juick/config/WebConfig.java index 0c816712..c15f4c18 100644 --- a/src/main/java/com/juick/config/WebConfig.java +++ b/src/main/java/com/juick/config/WebConfig.java @@ -39,6 +39,8 @@ import org.commonmark.node.Link; import org.commonmark.parser.Parser; import org.commonmark.renderer.html.HtmlRenderer; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.boot.web.servlet.support.ErrorPageFilter; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -73,22 +75,24 @@ public class WebConfig implements WebMvcConfigurer { private String tmpDir; @Value("${storage_path:#{systemProperties['java.io.tmpdir']}}") private String baseDir; + @Bean - public StorageService storageService() { + StorageService storageService() { return new FileSystemStorageService(baseDir, tmpDir); } @Bean - public HelpService helpService() { + HelpService helpService() { return new HelpService("help"); } @Bean - public Parser cmParser() { + Parser cmParser() { return Parser.builder().extensions(Collections.singletonList(AutolinkExtension.create())).build(); } + @Bean - public HtmlRenderer helpRenderer() { + HtmlRenderer helpRenderer() { return HtmlRenderer.builder() .attributeProviderFactory(context -> (node, tagName, attributes) -> { if (node instanceof Link) { @@ -102,18 +106,19 @@ public class WebConfig implements WebMvcConfigurer { }) .build(); } + @Bean - public Loader<?> templateLoader() { + Loader<?> templateLoader() { return new ClasspathLoader(); } @Bean - public SpringExtension springExtension() { + SpringExtension springExtension() { return new SpringExtension(null); } @Bean - public PebbleEngine pebbleEngine() { + PebbleEngine pebbleEngine() { boolean devToolsArePresent = false; try { Class.forName("org.springframework.boot.devtools.livereload.Connection"); @@ -135,39 +140,46 @@ public class WebConfig implements WebMvcConfigurer { private Resource keystore; @Value("${keystore_password:secret}") private String keystorePassword; + @Bean - public ResourceUrlEncodingFilter resourceUrlEncodingFilter() { + ResourceUrlEncodingFilter resourceUrlEncodingFilter() { return new ResourceUrlEncodingFilter(); } + @Bean - public KeystoreManager keystoreManager() { + KeystoreManager keystoreManager() { return new KeystoreManager(keystore, keystorePassword); } + @Bean - public Remark remarkConverter() { + Remark remarkConverter() { Options options = new Options(); options.inlineLinks = true; return new Remark(options); } + @Bean - public CommandsManager commandsManager() { + CommandsManager commandsManager() { return new CommandsManager(); } + @Bean - public ServerManager serverManager() { + ServerManager serverManager() { return new ServerManager(); } + @Bean - public SignatureManager signatureManager() { + SignatureManager signatureManager() { return new SignatureManager(); } + @Bean - public TopManager topManager() { + TopManager topManager() { return new TopManager(); } @Bean - public ViewResolver viewResolver() { + ViewResolver viewResolver() { PebbleViewResolver viewResolver = new PebbleViewResolver(pebbleEngine()); viewResolver.setPrefix("templates"); viewResolver.setSuffix(".html"); @@ -197,15 +209,30 @@ public class WebConfig implements WebMvcConfigurer { private String archiveUsername; @Bean - public User serviceUser() { + User serviceUser() { return userService.getUserByName(serviceUsername); } + @Bean - public User archiveUser() { + User archiveUser() { return userService.getUserByName(archiveUsername); } + @Bean - public RequestRejectedHandler requestRejectedHandler() { + RequestRejectedHandler requestRejectedHandler() { return new HttpStatusRequestRejectedHandler(); } + + @Bean + ErrorPageFilter errorPageFilter() { + return new ErrorPageFilter(); + } + + @Bean + FilterRegistrationBean disableSpringBootErrorFilter(ErrorPageFilter filter) { + FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); + filterRegistrationBean.setFilter(filter); + filterRegistrationBean.setEnabled(false); + return filterRegistrationBean; + } } |