Skip to content

Commit 63901c0

Browse files
committed
Projeto do curso
1 parent 6f655f1 commit 63901c0

File tree

2,278 files changed

+606701
-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.

2,278 files changed

+606701
-0
lines changed
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
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>war</packaging>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
15+
16+
<failOnMissingWebXml>false</failOnMissingWebXml>
17+
18+
<java.version>1.8</java.version>
19+
<maven-compiler-pluging.version>3.2</maven-compiler-pluging.version>
20+
<flyway-maven-plugin.version>4.0.2</flyway-maven-plugin.version>
21+
<mysql-connector-java.version>5.1.39</mysql-connector-java.version>
22+
23+
<!-- Spring MVC -->
24+
<spring-framework.version>4.3.0.RELEASE</spring-framework.version>
25+
26+
<!-- Servlet API -->
27+
<servlet.version>3.1.0</servlet.version>
28+
29+
<!-- Thymeleaf -->
30+
<thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
31+
32+
<!-- Bean Validation / Hibernate Validator -->
33+
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
34+
35+
<!-- Thymeleaf - Layout Dialect -->
36+
<thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version>
37+
38+
<!-- Logging -->
39+
<log4j.version>2.6</log4j.version>
40+
<jcl-over-slf4j.version>1.7.21</jcl-over-slf4j.version>
41+
42+
<!-- JPA / Hibernate -->
43+
<hibernate.version>5.1.0.Final</hibernate.version>
44+
45+
<!-- Spring Data JPA -->
46+
<spring-data-jpa.version>1.10.2.RELEASE</spring-data-jpa.version>
47+
48+
<!-- Jackson - JSON -->
49+
<jackson-core.version>2.7.5</jackson-core.version>
50+
51+
<!-- thumbnailator - Gerar Thumbnail -->
52+
<!-- https://github.com/coobird/thumbnailator -->
53+
<thumbnailator.version>0.4.8</thumbnailator.version>
54+
55+
<!-- Thymeleaf extras data attribute -->
56+
<thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-data-attribute.version>
57+
58+
<!-- Cache - Guava -->
59+
<guava.version>19.0</guava.version>
60+
61+
<!-- Apache Bean Utils -->
62+
<commons-beanutils.version>1.9.2</commons-beanutils.version>
63+
64+
<!-- Spring Security -->
65+
<spring-security.version>4.1.1.RELEASE</spring-security.version>
66+
</properties>
67+
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<artifactId>maven-compiler-plugin</artifactId>
72+
<version>${maven-compiler-pluging.version}</version>
73+
<configuration>
74+
<source>${java.version}</source>
75+
<target>${java.version}</target>
76+
</configuration>
77+
</plugin>
78+
79+
<plugin>
80+
<groupId>org.flywaydb</groupId>
81+
<artifactId>flyway-maven-plugin</artifactId>
82+
<version>${flyway-maven-plugin.version}</version>
83+
<configuration>
84+
<driver>com.mysql.jdbc.Driver</driver>
85+
</configuration>
86+
</plugin>
87+
</plugins>
88+
</build>
89+
90+
<dependencyManagement>
91+
<dependencies>
92+
<dependency>
93+
<groupId>org.springframework</groupId>
94+
<artifactId>spring-framework-bom</artifactId>
95+
<version>${spring-framework.version}</version>
96+
<type>pom</type>
97+
<scope>import</scope>
98+
</dependency>
99+
</dependencies>
100+
</dependencyManagement>
101+
102+
<dependencies>
103+
<!-- Spring MVC -->
104+
<dependency>
105+
<groupId>org.springframework</groupId>
106+
<artifactId>spring-webmvc</artifactId>
107+
<scope>compile</scope>
108+
<exclusions>
109+
<exclusion>
110+
<groupId>commons-logging</groupId>
111+
<artifactId>commons-logging</artifactId>
112+
</exclusion>
113+
</exclusions>
114+
</dependency>
115+
116+
<!-- Servlet API -->
117+
<dependency>
118+
<groupId>javax.servlet</groupId>
119+
<artifactId>javax.servlet-api</artifactId>
120+
<version>${servlet.version}</version>
121+
<scope>provided</scope>
122+
</dependency>
123+
124+
<!-- Thymeleaf -->
125+
<dependency>
126+
<groupId>org.thymeleaf</groupId>
127+
<artifactId>thymeleaf</artifactId>
128+
<version>${thymeleaf.version}</version>
129+
<scope>compile</scope>
130+
</dependency>
131+
132+
<dependency>
133+
<groupId>org.thymeleaf</groupId>
134+
<artifactId>thymeleaf-spring4</artifactId>
135+
<version>${thymeleaf.version}</version>
136+
<scope>compile</scope>
137+
</dependency>
138+
139+
<!-- Bean Validation / Hibernate Validator -->
140+
<dependency>
141+
<groupId>org.hibernate</groupId>
142+
<artifactId>hibernate-validator</artifactId>
143+
<version>${hibernate-validator.version}</version>
144+
<scope>compile</scope>
145+
</dependency>
146+
147+
<!-- Thymeleaf - Layout Dialect -->
148+
<dependency>
149+
<groupId>nz.net.ultraq.thymeleaf</groupId>
150+
<artifactId>thymeleaf-layout-dialect</artifactId>
151+
<version>${thymeleaf-layout-dialect.version}</version>
152+
</dependency>
153+
154+
<!-- Logging -->
155+
<dependency>
156+
<groupId>org.apache.logging.log4j</groupId>
157+
<artifactId>log4j-slf4j-impl</artifactId>
158+
<version>${log4j.version}</version>
159+
</dependency>
160+
<dependency>
161+
<groupId>org.apache.logging.log4j</groupId>
162+
<artifactId>log4j-api</artifactId>
163+
<version>${log4j.version}</version>
164+
</dependency>
165+
<dependency>
166+
<groupId>org.apache.logging.log4j</groupId>
167+
<artifactId>log4j-core</artifactId>
168+
<version>${log4j.version}</version>
169+
</dependency>
170+
<dependency>
171+
<groupId>org.slf4j</groupId>
172+
<artifactId>jcl-over-slf4j</artifactId>
173+
<version>${jcl-over-slf4j.version}</version>
174+
</dependency>
175+
176+
<!-- JPA / Hibernate -->
177+
<dependency>
178+
<groupId>org.hibernate</groupId>
179+
<artifactId>hibernate-entitymanager</artifactId>
180+
<version>${hibernate.version}</version>
181+
<scope>compile</scope>
182+
</dependency>
183+
184+
<!-- Hibernate - Java 8 support -->
185+
<dependency>
186+
<groupId>org.hibernate</groupId>
187+
<artifactId>hibernate-java8</artifactId>
188+
<version>${hibernate.version}</version>
189+
<scope>compile</scope>
190+
</dependency>
191+
192+
<!-- MySQL Driver -->
193+
<dependency>
194+
<groupId>mysql</groupId>
195+
<artifactId>mysql-connector-java</artifactId>
196+
<version>${mysql-connector-java.version}</version>
197+
<scope>provided</scope>
198+
</dependency>
199+
200+
<!-- Spring Data JPA -->
201+
<dependency>
202+
<groupId>org.springframework.data</groupId>
203+
<artifactId>spring-data-jpa</artifactId>
204+
<version>${spring-data-jpa.version}</version>
205+
<scope>compile</scope>
206+
</dependency>
207+
208+
<!-- Jackson - JSON -->
209+
<dependency>
210+
<groupId>com.fasterxml.jackson.core</groupId>
211+
<artifactId>jackson-databind</artifactId>
212+
<version>${jackson-core.version}</version>
213+
<scope>compile</scope>
214+
</dependency>
215+
216+
<!-- thumbnailator - Gerar Thumbnail -->
217+
<dependency>
218+
<groupId>net.coobird</groupId>
219+
<artifactId>thumbnailator</artifactId>
220+
<version>${thumbnailator.version}</version>
221+
<scope>compile</scope>
222+
</dependency>
223+
224+
<!-- Thymeleaf extras data attribute -->
225+
<dependency>
226+
<groupId>com.github.mxab.thymeleaf.extras</groupId>
227+
<artifactId>thymeleaf-extras-data-attribute</artifactId>
228+
<version>${thymeleaf-extras-data-attribute.version}</version>
229+
<scope>compile</scope>
230+
</dependency>
231+
232+
<!-- Cache - Guava -->
233+
<dependency>
234+
<groupId>com.google.guava</groupId>
235+
<artifactId>guava</artifactId>
236+
<version>${guava.version}</version>
237+
<scope>compile</scope>
238+
</dependency>
239+
240+
<!-- Spring Context Support -->
241+
<dependency>
242+
<groupId>org.springframework</groupId>
243+
<artifactId>spring-context-support</artifactId>
244+
<scope>compile</scope>
245+
</dependency>
246+
247+
<!-- Apache Bean Utils -->
248+
<dependency>
249+
<groupId>commons-beanutils</groupId>
250+
<artifactId>commons-beanutils</artifactId>
251+
<version>${commons-beanutils.version}</version>
252+
<scope>compile</scope>
253+
</dependency>
254+
255+
<!-- Spring Security -->
256+
<dependency>
257+
<groupId>org.springframework.security</groupId>
258+
<artifactId>spring-security-web</artifactId>
259+
<version>${spring-security.version}</version>
260+
<scope>compile</scope>
261+
</dependency>
262+
<dependency>
263+
<groupId>org.springframework.security</groupId>
264+
<artifactId>spring-security-config</artifactId>
265+
<version>${spring-security.version}</version>
266+
<scope>compile</scope>
267+
</dependency>
268+
269+
</dependencies>
270+
271+
</project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.algaworks.brewer.config;
2+
3+
import javax.persistence.EntityManagerFactory;
4+
import javax.sql.DataSource;
5+
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
10+
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
11+
import org.springframework.orm.jpa.JpaTransactionManager;
12+
import org.springframework.orm.jpa.JpaVendorAdapter;
13+
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
14+
import org.springframework.orm.jpa.vendor.Database;
15+
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
16+
import org.springframework.transaction.PlatformTransactionManager;
17+
import org.springframework.transaction.annotation.EnableTransactionManagement;
18+
19+
import com.algaworks.brewer.model.Cerveja;
20+
import com.algaworks.brewer.repository.Cervejas;
21+
22+
@Configuration
23+
@ComponentScan(basePackageClasses = Cervejas.class)
24+
@EnableJpaRepositories(basePackageClasses = Cervejas.class, enableDefaultTransactions = false)
25+
@EnableTransactionManagement
26+
@ComponentScan(basePackageClasses = Cervejas.class)
27+
public class JPAConfig {
28+
29+
@Bean
30+
public DataSource dataSource() {
31+
JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
32+
dataSourceLookup.setResourceRef(true);
33+
return dataSourceLookup.getDataSource("jdbc/brewerDB");
34+
}
35+
36+
@Bean
37+
public JpaVendorAdapter jpaVendorAdapter() {
38+
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
39+
adapter.setDatabase(Database.MYSQL);
40+
adapter.setShowSql(false);
41+
adapter.setGenerateDdl(false);
42+
adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
43+
return adapter;
44+
}
45+
46+
@Bean
47+
public EntityManagerFactory entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
48+
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
49+
factory.setDataSource(dataSource);
50+
factory.setJpaVendorAdapter(jpaVendorAdapter);
51+
factory.setPackagesToScan(Cerveja.class.getPackage().getName());
52+
factory.afterPropertiesSet();
53+
return factory.getObject();
54+
}
55+
56+
@Bean
57+
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
58+
JpaTransactionManager transactionManager = new JpaTransactionManager();
59+
transactionManager.setEntityManagerFactory(entityManagerFactory);
60+
return transactionManager;
61+
}
62+
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.web.builders.HttpSecurity;
8+
import org.springframework.security.config.annotation.web.builders.WebSecurity;
9+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
10+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11+
import org.springframework.security.core.userdetails.UserDetailsService;
12+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
13+
import org.springframework.security.crypto.password.PasswordEncoder;
14+
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
15+
16+
import com.algaworks.brewer.security.AppUserDetailsService;
17+
18+
@EnableWebSecurity
19+
@ComponentScan(basePackageClasses = AppUserDetailsService.class)
20+
public class SecurityConfig extends WebSecurityConfigurerAdapter {
21+
22+
@Autowired
23+
private UserDetailsService userDetailsService;
24+
25+
@Override
26+
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
27+
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
28+
}
29+
30+
@Override
31+
public void configure(WebSecurity web) throws Exception {
32+
web.ignoring()
33+
.antMatchers("/layout/**")
34+
.antMatchers("/images/**");
35+
}
36+
37+
@Override
38+
protected void configure(HttpSecurity http) throws Exception {
39+
http
40+
.authorizeRequests()
41+
.antMatchers("/cidades/nova").hasRole("CADASTRAR_CIDADE")
42+
.antMatchers("/usuarios/**").hasRole("CADASTRAR_USUARIO")
43+
.anyRequest().authenticated()
44+
.and()
45+
.formLogin()
46+
.loginPage("/login")
47+
.permitAll()
48+
.and()
49+
.logout()
50+
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
51+
.and()
52+
.exceptionHandling()
53+
.accessDeniedPage("/403");
54+
}
55+
56+
@Bean
57+
public PasswordEncoder passwordEncoder() {
58+
return new BCryptPasswordEncoder();
59+
}
60+
61+
}

0 commit comments

Comments
 (0)