Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/produtos/apirest/models/Produto.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/
@Entity
@Table(name="TB_PRODUTO")
@Table(name="PRODUTO")
public class Produto implements Serializable{

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
*/
@RestController
@RequestMapping(value="/api")
@RequestMapping(value="/api/admin")
public class ProdutoResource {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.produtos.apirest.repository;
package com.produtos.apirest.resources;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/produtos/apirest/security/WebSecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.produtos.apirest.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
Expand All @@ -14,8 +17,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable().authorizeRequests()
httpSecurity.csrf().disable()
.authorizeRequests()
.antMatchers("/home").permitAll()
.antMatchers("/api").authenticated()
.antMatchers("/api/admin/**").hasRole("ADMIN")
.antMatchers(HttpMethod.POST, "/login").permitAll()
.anyRequest().authenticated()
.and()
Expand All @@ -28,13 +34,19 @@ protected void configure(HttpSecurity httpSecurity) throws Exception {
.addFilterBefore(new JWTAuthenticationFilter(),
UsernamePasswordAuthenticationFilter.class);
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
protected void configure (AuthenticationManagerBuilder auth) throws Exception {
// cria uma conta default
auth.inMemoryAuthentication()
.withUser("admin")
.password("{noop}password")
.roles("ADMIN");
.withUser("admin").password(encoder().encode("password")).roles("ADMIN")
.and()
.withUser("user").password(encoder().encode("password")).roles("USER");
}

@Bean
public PasswordEncoder encoder () {
return new BCryptPasswordEncoder();
}

}
7 changes: 0 additions & 7 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
#Banco local - localhost
spring.datasource.url= jdbc:postgresql://localhost:5432/produtos-apirest
spring.datasource.username=postgres
<<<<<<< Updated upstream
spring.datasource.password=postgres
#spring.datasource.password=123
spring.jpa.hibernate.ddl-auto=update
=======
#spring.datasource.password=postgres
spring.datasource.password=123
spring.jpa.hibernate.ddl-auto=update

>>>>>>> Stashed changes
Binary file modified target/classes/com/produtos/apirest/models/Produto.class
Binary file not shown.
Binary file not shown.