-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dcb6ab
commit 48e1109
Showing
6 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
backend/src/main/java/com/devsuperior/dsdeliver/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.devsuperior.dsdeliver.config; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.env.Environment; | ||
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.config.http.SessionCreationPolicy; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
|
||
@Autowired | ||
private Environment env; | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
if (Arrays.asList(env.getActiveProfiles()).contains("test")) { | ||
http.headers().frameOptions().disable(); | ||
} | ||
|
||
http.cors().and().csrf().disable(); | ||
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); | ||
http.authorizeRequests().anyRequest().permitAll(); | ||
} | ||
|
||
@Bean | ||
CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration configuration = new CorsConfiguration().applyPermitDefaultValues(); | ||
configuration.setAllowedMethods(Arrays.asList("POST", "GET", "PUT", "DELETE", "OPTIONS")); | ||
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", configuration); | ||
return source; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata | ||
#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create | ||
#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql | ||
#spring.jpa.properties.hibernate.hbm2ddl.delimiter=; | ||
|
||
spring.datasource.url=jdbc:postgresql://localhost:5432/dsdeliver | ||
spring.datasource.username=postgres | ||
spring.datasource.password=123 | ||
|
||
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true | ||
spring.jpa.hibernate.ddl-auto=none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.datasource.url=${DATABASE_URL} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
spring.datasource.url=jdbc:h2:mem:testdb | ||
spring.datasource.username=sa | ||
spring.datasource.password= | ||
|
||
spring.h2.console.enabled=true | ||
spring.h2.console.path=/h2-console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
|
||
spring.profiles.active=test | ||
|
||
spring.jpa.open-in-view=false |