OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2021-10-14 d680ff9fa4298ad3c0cd12f5f9d87f6c51110480
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package kr.wisestone.owl.config;
 
import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import kr.wisestone.owl.util.PageUtil;
import kr.wisestone.owl.util.WebAppUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.security.SpringSessionBackedSessionRegistry;
 
import java.util.Properties;
 
/**
 * Created by jeong on 2017-08-14.
 */
@Configuration
public class CommonConfiguration {
 
    private static final String FILE_ENCODING = "UTF-8";
    private static final String MAIL_DEBUG = "mail.debug";
    private static final String MAIL_SMTP_STARTTLS_ENABLE = "mail.smtp.starttls.enable";
    private static final String MAIL_SMTP_AUTH = "mail.smtp.auth";
    private static final String MAIL_SMTP_SSL_TRUST = "mail.smtp.ssl.trust";
 
    @Value("${aws.access.key}")
    private String accessKey;
 
    @Value("${aws.access.password}")
    private String accessPassword;
 
    @Autowired
    private FindByIndexNameSessionRepository findByIndexNameSessionRepository;
 
    @Value("${email.host}")
    private String emailHost;
    @Value("${email.port}")
    private String emailPort;
    @Value("${email.userName}")
    private String emailUserName;
    @Value("${email.password}")
    private String emailPassword;
    @Value("${email.transport.protocol}")
    private String emailTransportProtocol;
    @Value("${email.smtp.auth}")
    private String emailSmtpAuth;
    @Value("${email.smtp.starttle.enable}")
    private String emailSmtpStarttleEnable;
    @Value("${email.debug}")
    private String emailDebug;
    @Value("${email.sendUrl}")
    private String emailSendUrl;
 
    @Bean
    public WebAppUtil webAppUtil() {
        return new WebAppUtil();
    }
 
    @Bean
    public PageUtil pageUtil() {
        return new PageUtil();
    }
 
    @Profile("prod")
    @Bean
    public static PropertySourcesPlaceholderConfigurer prodProperties() {
        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
        configurer.setLocations(new ClassPathResource("system_prod.properties"));
        configurer.setFileEncoding(FILE_ENCODING);
 
        return configurer;
    }
 
    @Profile("dev")
    @Bean
    public static PropertySourcesPlaceholderConfigurer devProperties() {
        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
        configurer.setLocations(new ClassPathResource("system_dev.properties"));
        configurer.setFileEncoding(FILE_ENCODING);
 
        return configurer;
    }
 
    @Profile("test")
    @Bean
    public static PropertySourcesPlaceholderConfigurer testProperties() {
        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
        configurer.setLocations(new ClassPathResource("system_test.properties"));
        configurer.setFileEncoding(FILE_ENCODING);
 
        return configurer;
    }
 
    @Profile("design")
    @Bean
    public static PropertySourcesPlaceholderConfigurer designProperties() {
        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
        configurer.setLocations(new ClassPathResource("system_design.properties"));
        configurer.setFileEncoding(FILE_ENCODING);
 
        return configurer;
    }
 
    @Bean
    public String getEmailSendUrl() { return this.emailSendUrl; }
 
    @Bean
    public MessageSourceAccessor messageSourceAccessor(ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource) {
        return new MessageSourceAccessor(reloadableResourceBundleMessageSource);
    }
 
    @Bean
    public ReloadableResourceBundleMessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setCacheSeconds(10);
        messageSource.setDefaultEncoding(FILE_ENCODING);
        messageSource.setBasenames("/WEB-INF/i18n/messages", "/WEB-INF/i18n/mail", "/WEB-INF/i18n/code");
        messageSource.setUseCodeAsDefaultMessage(true);
 
        return messageSource;
    }
 
    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        javaMailSender.setHost(this.emailHost);
        javaMailSender.setPort(Integer.valueOf(this.emailPort));
        javaMailSender.setUsername(this.emailUserName);
        javaMailSender.setPassword(this.emailPassword);
 
        Properties javaMailProperties = new Properties();
        javaMailProperties.setProperty(MAIL_SMTP_SSL_TRUST, this.emailHost);
        javaMailProperties.setProperty(MAIL_SMTP_AUTH, this.emailSmtpAuth);
        javaMailProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, this.emailSmtpStarttleEnable);
        javaMailProperties.setProperty(MAIL_DEBUG, this.emailDebug);
        javaMailSender.setJavaMailProperties(javaMailProperties);
 
        return javaMailSender;
    }
 
    @Bean
    public AmazonS3 amazonS3() {
        BasicAWSCredentials credentials = new BasicAWSCredentials(this.accessKey, this.accessPassword);
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProtocol(Protocol.HTTP);
 
        return AmazonS3ClientBuilder
                .standard()
                .withRegion(Regions.AP_NORTHEAST_2)
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withClientConfiguration(clientConfiguration).build();
    }
 
    @Bean
    @SuppressWarnings("unchecked")
    public SpringSessionBackedSessionRegistry sessionRegistry() {
        return new SpringSessionBackedSessionRegistry(this.findByIndexNameSessionRepository);
    }
 
}