View Javadoc
1   /*
2    * Copyright 2018-2022 Medical Information Systems Research Group (https://medical.zcu.cz),
3    * Department of Computer Science and Engineering, University of West Bohemia.
4    * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5    *
6    * Author Petr Vcelak (vcelak@kiv.zcu.cz).
7    *
8    * This file is part of MRECore project.
9    *
10   * MRECore is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation, either version 3 of the License.
13   *
14   * MRECore is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with MRECore. If not, see <http://www.gnu.org/licenses/>.
21   */
22  package cz.zcu.mre.config;
23  
24  import org.springframework.web.filter.CharacterEncodingFilter;
25  import org.springframework.web.filter.DelegatingFilterProxy;
26  import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
27  import jakarta.servlet.*;
28  import org.springframework.core.Ordered;
29  import org.springframework.core.annotation.Order;
30  
31  /**
32   * 
33   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
34   */
35  @Order(value = Ordered.LOWEST_PRECEDENCE)
36  public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
37  
38      @Override
39      protected String[] getServletMappings() {
40          return new String[]{"/"};
41      }
42  
43      @Override
44      protected Class<?>[] getRootConfigClasses() {
45          return new Class<?>[]{ApplicationConfiguration.class};
46      }
47  
48      @Override
49      protected Class<?>[] getServletConfigClasses() {
50          return null;
51      }
52  
53      @Override
54      protected Filter[] getServletFilters() {
55          CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
56          characterEncodingFilter.setEncoding("UTF-8");
57          characterEncodingFilter.setForceEncoding(true);
58  
59          DelegatingFilterProxy securityFilterChain = new DelegatingFilterProxy("springSecurityFilterChain");
60  
61          return new Filter[]{characterEncodingFilter, securityFilterChain};
62      }
63  
64      @Override
65      protected void customizeRegistration(ServletRegistration.Dynamic registration) {
66          registration.setInitParameter("defaultHtmlEscape", "true");
67          registration.setInitParameter("spring.profiles.active", "default");
68      }
69  }