Skip to content

Commit be1ff9c

Browse files
committed
Migrando para Spring Boot 2 (cap. 32) gravado.
1 parent 89db5f6 commit be1ff9c

File tree

4,579 files changed

+962152
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,579 files changed

+962152
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: java $JAVA_OPTS -Dspring.profiles.active=prod -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.algaworks</groupId>
7+
<artifactId>brewer</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
10+
<packaging>jar</packaging>
11+
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>2.0.0.M7</version>
16+
<relativePath/> <!-- lookup parent from repository -->
17+
</parent>
18+
19+
<properties>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
22+
<java.version>1.8</java.version>
23+
24+
<!-- Thymeleaf -->
25+
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
26+
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
27+
<thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-data-attribute.version>
28+
<thymeleaf-extras-springsecurity4.version>3.0.2.RELEASE</thymeleaf-extras-springsecurity4.version>
29+
30+
<!-- thumbnailator - Gerar Thumbnail -->
31+
<!-- https://github.com/coobird/thumbnailator -->
32+
<thumbnailator.version>0.4.8</thumbnailator.version>
33+
34+
<!-- AWS SDK - S3 -->
35+
<aws-java-sdk-s3.version>1.10.77</aws-java-sdk-s3.version>
36+
37+
<!-- JasperReports -->
38+
<jasperreports.version>6.3.0</jasperreports.version>
39+
<jasperreports-fonts.version>6.0.0</jasperreports-fonts.version>
40+
</properties>
41+
42+
<dependencies>
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-web</artifactId>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>nz.net.ultraq.thymeleaf</groupId>
55+
<artifactId>thymeleaf-layout-dialect</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>com.github.mxab.thymeleaf.extras</groupId>
60+
<artifactId>thymeleaf-extras-data-attribute</artifactId>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter-data-jpa</artifactId>
66+
</dependency>
67+
68+
<dependency>
69+
<groupId>org.springframework.boot</groupId>
70+
<artifactId>spring-boot-starter-mail</artifactId>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-devtools</artifactId>
76+
<scope>runtime</scope>
77+
</dependency>
78+
79+
<!-- MySQL -->
80+
<dependency>
81+
<groupId>mysql</groupId>
82+
<artifactId>mysql-connector-java</artifactId>
83+
<scope>runtime</scope>
84+
</dependency>
85+
86+
<!-- Migracoes - Flyway -->
87+
<dependency>
88+
<groupId>org.flywaydb</groupId>
89+
<artifactId>flyway-core</artifactId>
90+
</dependency>
91+
92+
<!-- thumbnailator - Gerar Thumbnail -->
93+
<dependency>
94+
<groupId>net.coobird</groupId>
95+
<artifactId>thumbnailator</artifactId>
96+
<version>${thumbnailator.version}</version>
97+
<scope>compile</scope>
98+
</dependency>
99+
100+
<dependency>
101+
<groupId>org.springframework.boot</groupId>
102+
<artifactId>spring-boot-starter-security</artifactId>
103+
</dependency>
104+
105+
<dependency>
106+
<groupId>org.thymeleaf.extras</groupId>
107+
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
108+
</dependency>
109+
110+
<!-- AWS SDK - S3 -->
111+
<dependency>
112+
<groupId>com.amazonaws</groupId>
113+
<artifactId>aws-java-sdk-s3</artifactId>
114+
<version>${aws-java-sdk-s3.version}</version>
115+
</dependency>
116+
117+
<!-- JasperReports -->
118+
<dependency>
119+
<groupId>net.sf.jasperreports</groupId>
120+
<artifactId>jasperreports</artifactId>
121+
<version>${jasperreports.version}</version>
122+
<scope>compile</scope>
123+
</dependency>
124+
<dependency>
125+
<groupId>net.sf.jasperreports</groupId>
126+
<artifactId>jasperreports-fonts</artifactId>
127+
<version>${jasperreports-fonts.version}</version>
128+
<scope>compile</scope>
129+
</dependency>
130+
131+
<!-- EhCache -->
132+
<dependency>
133+
<groupId>org.ehcache</groupId>
134+
<artifactId>ehcache</artifactId>
135+
</dependency>
136+
137+
<!-- JCache -->
138+
<dependency>
139+
<groupId>javax.cache</groupId>
140+
<artifactId>cache-api</artifactId>
141+
</dependency>
142+
143+
<!-- JUnit -->
144+
<dependency>
145+
<groupId>junit</groupId>
146+
<artifactId>junit</artifactId>
147+
<scope>test</scope>
148+
</dependency>
149+
</dependencies>
150+
151+
<build>
152+
<plugins>
153+
<plugin>
154+
<groupId>org.springframework.boot</groupId>
155+
<artifactId>spring-boot-maven-plugin</artifactId>
156+
</plugin>
157+
</plugins>
158+
</build>
159+
160+
<repositories>
161+
<repository>
162+
<id>spring-snapshots</id>
163+
<name>Spring Snapshots</name>
164+
<url>https://repo.spring.io/snapshot</url>
165+
<snapshots>
166+
<enabled>true</enabled>
167+
</snapshots>
168+
</repository>
169+
<repository>
170+
<id>spring-milestones</id>
171+
<name>Spring Milestones</name>
172+
<url>https://repo.spring.io/milestone</url>
173+
<snapshots>
174+
<enabled>false</enabled>
175+
</snapshots>
176+
</repository>
177+
</repositories>
178+
179+
<pluginRepositories>
180+
<pluginRepository>
181+
<id>spring-snapshots</id>
182+
<name>Spring Snapshots</name>
183+
<url>https://repo.spring.io/snapshot</url>
184+
<snapshots>
185+
<enabled>true</enabled>
186+
</snapshots>
187+
</pluginRepository>
188+
<pluginRepository>
189+
<id>spring-milestones</id>
190+
<name>Spring Milestones</name>
191+
<url>https://repo.spring.io/milestone</url>
192+
<snapshots>
193+
<enabled>false</enabled>
194+
</snapshots>
195+
</pluginRepository>
196+
</pluginRepositories>
197+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.algaworks.brewer;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class BrewerApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(BrewerApplication.class, args);
11+
}
12+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.algaworks.brewer.config;
2+
3+
import java.util.Properties;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.context.annotation.PropertySource;
9+
import org.springframework.core.env.Environment;
10+
import org.springframework.mail.javamail.JavaMailSender;
11+
import org.springframework.mail.javamail.JavaMailSenderImpl;
12+
13+
@Configuration
14+
@PropertySource(value = { "file://${HOME}/.brewer-mail.properties" }, ignoreResourceNotFound = true)
15+
public class MailConfig {
16+
17+
@Autowired
18+
private Environment env;
19+
20+
@Bean
21+
public JavaMailSender mailSender() {
22+
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
23+
mailSender.setHost("smtp.sendgrid.net");
24+
mailSender.setPort(587);
25+
mailSender.setUsername(env.getProperty("brewer.mail.username"));
26+
mailSender.setPassword(env.getProperty("SENDGRID_PASSWORD"));
27+
28+
Properties props = new Properties();
29+
props.put("mail.transport.protocol", "smtp");
30+
props.put("mail.smtp.auth", true);
31+
props.put("mail.smtp.starttls.enable", true);
32+
props.put("mail.debug", false);
33+
props.put("mail.smtp.connectiontimeout", 10000); // miliseconds
34+
35+
mailSender.setJavaMailProperties(props);
36+
37+
return mailSender;
38+
}
39+
40+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.algaworks.brewer.config;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Profile;
7+
import org.springframework.context.annotation.PropertySource;
8+
import org.springframework.core.env.Environment;
9+
10+
import com.amazonaws.ClientConfiguration;
11+
import com.amazonaws.auth.AWSCredentials;
12+
import com.amazonaws.auth.BasicAWSCredentials;
13+
import com.amazonaws.regions.Region;
14+
import com.amazonaws.regions.Regions;
15+
import com.amazonaws.services.s3.AmazonS3;
16+
import com.amazonaws.services.s3.AmazonS3Client;
17+
18+
@Profile("prod")
19+
@Configuration
20+
@PropertySource(value = { "file://${HOME}/.brewer-s3.properties" }, ignoreResourceNotFound = true)
21+
public class S3Config {
22+
23+
@Autowired
24+
private Environment env;
25+
26+
@Bean
27+
public AmazonS3 amazonS3() {
28+
AWSCredentials credenciais = new BasicAWSCredentials(
29+
env.getProperty("AWS_ACCESS_KEY_ID"), env.getProperty("AWS_SECRET_ACCESS_KEY"));
30+
AmazonS3 amazonS3 = new AmazonS3Client(credenciais, new ClientConfiguration());
31+
Region regiao = Region.getRegion(Regions.US_EAST_1);
32+
amazonS3.setRegion(regiao);
33+
return amazonS3;
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.algaworks.brewer.config;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.ComponentScan;
6+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7+
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
8+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9+
import org.springframework.security.config.annotation.web.builders.WebSecurity;
10+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
11+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
12+
import org.springframework.security.core.userdetails.UserDetailsService;
13+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
14+
import org.springframework.security.crypto.password.PasswordEncoder;
15+
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
16+
17+
import com.algaworks.brewer.security.AppUserDetailsService;
18+
19+
@EnableWebSecurity
20+
@ComponentScan(basePackageClasses = AppUserDetailsService.class)
21+
@EnableGlobalMethodSecurity(prePostEnabled = true)
22+
public class SecurityConfig extends WebSecurityConfigurerAdapter {
23+
24+
@Autowired
25+
private UserDetailsService userDetailsService;
26+
27+
@Override
28+
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
29+
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
30+
}
31+
32+
@Override
33+
public void configure(WebSecurity web) throws Exception {
34+
web.ignoring()
35+
.antMatchers("/layout/**")
36+
.antMatchers("/images/**");
37+
}
38+
39+
@Override
40+
protected void configure(HttpSecurity http) throws Exception {
41+
http
42+
.authorizeRequests()
43+
.antMatchers("/cidades/nova").hasRole("CADASTRAR_CIDADE")
44+
.antMatchers("/usuarios/**").hasRole("CADASTRAR_USUARIO")
45+
.anyRequest().authenticated()
46+
.and()
47+
.formLogin()
48+
.loginPage("/login")
49+
.permitAll()
50+
.and()
51+
.logout()
52+
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
53+
.and()
54+
.exceptionHandling()
55+
.accessDeniedPage("/403")
56+
.and()
57+
.sessionManagement()
58+
.invalidSessionUrl("/login");
59+
}
60+
61+
@Bean
62+
public PasswordEncoder passwordEncoder() {
63+
return new BCryptPasswordEncoder();
64+
}
65+
66+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.algaworks.brewer.config;
2+
3+
import javax.cache.Caching;
4+
5+
import org.springframework.cache.CacheManager;
6+
import org.springframework.cache.annotation.EnableCaching;
7+
import org.springframework.cache.jcache.JCacheCacheManager;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.scheduling.annotation.EnableAsync;
11+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
12+
13+
@Configuration
14+
@EnableCaching
15+
@EnableAsync
16+
public class WebConfig implements WebMvcConfigurer {
17+
18+
@Bean
19+
public CacheManager cacheManager() throws Exception {
20+
return new JCacheCacheManager(Caching.getCachingProvider().getCacheManager(
21+
getClass().getResource("/env/ehcache.xml").toURI(),
22+
getClass().getClassLoader()));
23+
}
24+
}

0 commit comments

Comments
 (0)