2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.akraino.validation.ui.config;
18 import javax.sql.DataSource;
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;
34 @ComponentScan(basePackages = "org.akraino.validation.ui")
35 public class AppConfig extends WebMvcConfigurerAdapter {
38 SessionManagerFilter getSessionManager() {
39 return new SessionManagerFilter();
43 public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
48 public void addInterceptors(InterceptorRegistry registry) {
49 registry.addInterceptor(getSessionManager()).addPathPatterns("/**").excludePathPatterns("/login", "/logout");
54 public CommonsMultipartResolver multipartResolver() {
56 CommonsMultipartResolver cmr = new CommonsMultipartResolver();
57 cmr.setMaxUploadSize(1000000 * 2);
58 cmr.setMaxUploadSizePerFile(2000000); // bytes
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"));