UI initial implementation.
[validation.git] / ui / src / main / java / org / akraino / validation / ui / config / AppConfig.java
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.akraino.validation.ui.config;
17
18 import javax.sql.DataSource;
19
20 import org.akraino.validation.ui.common.PropertyUtil;
21 import org.akraino.validation.ui.common.SessionManagerFilter;
22 import org.apache.commons.dbcp.BasicDataSource;
23 import org.springframework.context.annotation.Bean;
24 import org.springframework.context.annotation.ComponentScan;
25 import org.springframework.context.annotation.Configuration;
26 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
27 import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
28 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
29 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
30 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
31
32 @Configuration
33 @EnableWebMvc
34 @ComponentScan(basePackages = "org.akraino.validation.ui")
35 public class AppConfig extends WebMvcConfigurerAdapter {
36
37     @Bean
38     SessionManagerFilter getSessionManager() {
39         return new SessionManagerFilter();
40     }
41
42     @Override
43     public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
44         configurer.enable();
45     }
46
47     @Override
48     public void addInterceptors(InterceptorRegistry registry) {
49         registry.addInterceptor(getSessionManager()).addPathPatterns("/**").excludePathPatterns("/login", "/logout");
50
51     }
52
53     @Bean
54     public CommonsMultipartResolver multipartResolver() {
55
56         CommonsMultipartResolver cmr = new CommonsMultipartResolver();
57         cmr.setMaxUploadSize(1000000 * 2);
58         cmr.setMaxUploadSizePerFile(2000000); // bytes
59         return cmr;
60
61     }
62
63     @Bean(name = "dataSource")
64     public DataSource getDataSource() {
65         BasicDataSource dataSource = new BasicDataSource();
66         dataSource.setDriverClassName("org.postgresql.Driver");
67         dataSource.setUrl(PropertyUtil.getInstance().getProperty("postgres.db.url"));
68         dataSource.setUsername(PropertyUtil.getInstance().getProperty("postgres.db.user.name"));
69         dataSource.setPassword(System.getenv("postgres_db_user_pwd"));
70
71         return dataSource;
72     }
73
74 }