Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.DS_Store

### STS ###
.apt_generated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package br.com.caelum.carangobom.config.seguranca;

import org.apache.tomcat.util.http.Rfc6265CookieProcessor;
import org.apache.tomcat.util.http.SameSiteCookies;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfiguracao implements WebMvcConfigurer {

@Bean
public TomcatContextCustomizer sameSiteCookiesConfig() {
return context -> {
final var cookieProcessor = new Rfc6265CookieProcessor();
cookieProcessor.setSameSiteCookies(SameSiteCookies.NONE.getValue());
context.setCookieProcessor(cookieProcessor);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
Expand Down Expand Up @@ -59,7 +60,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.POST, "/usuarios").permitAll()
.antMatchers(HttpMethod.GET, "/veiculos").permitAll()
.anyRequest().authenticated().and()
.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.csrf().csrfTokenRepository(getCsrfTokenRepository()).and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.addFilterBefore(new AutenticacaoTokenFiltro(tokenService, usuarioRepository), UsernamePasswordAuthenticationFilter.class);
}

Expand All @@ -71,8 +72,7 @@ public void configure(WebSecurity web) throws Exception {
}

@Bean
CorsConfigurationSource corsConfigurationSource()
{
CorsConfigurationSource corsConfigurationSource() {
var configuration = new CorsConfiguration();
configuration.addAllowedOrigin("https://carango-bom-withfliters-ui.herokuapp.com");
configuration.addAllowedHeader("*");
Expand All @@ -82,4 +82,10 @@ CorsConfigurationSource corsConfigurationSource()
source.registerCorsConfiguration("/**", configuration);
return source;
}

private CsrfTokenRepository getCsrfTokenRepository() {
var tokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse();
tokenRepository.setCookieDomain("https://carango-bom-withfliters-ui.herokuapp.com/");
return tokenRepository;
}
}