Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testando o fluxo Authorization Code com um client JavaScript #340

Merged
merged 3 commits into from
Dec 19, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.server.resource.introspection.NimbusOpaqueTokenIntrospector;
import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector;
import org.springframework.security.web.SecurityFilterChain;

@Profile("production")
@Configuration
@EnableWebSecurity
@Profile("developer")
public class WebSecurityConfig {


@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests()
.anyRequest().authenticated()
.and()
.cors()
.and()
.oauth2ResourceServer().opaqueToken();

return http.build();
}


// @Bean
// public OpaqueTokenIntrospector introspector() {
// return new NimbusOpaqueTokenIntrospector();
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -47,11 +46,12 @@
import java.util.Arrays;
import java.util.List;

@Profile("developer")
@Configuration
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class OpenApiConfig implements WebMvcConfigurer {
public static final String ERRO_INTERNO_DO_SERVIDOR = "Erro interno do servidor";
public static final String PROBLEM = "Problem";
TypeResolver typeResolver = new TypeResolver();

@Bean
Expand Down Expand Up @@ -156,8 +156,8 @@ private List<ResponseMessage> globalGetResponseMessages() {
return Arrays.asList(
new ResponseMessageBuilder()
.code(HttpStatus.INTERNAL_SERVER_ERROR.value())
.message("Erro interno do servidor")
.responseModel(new ModelRef("Problem"))
.message(ERRO_INTERNO_DO_SERVIDOR)
.responseModel(new ModelRef(PROBLEM))
.build(),
new ResponseMessageBuilder()
.code(HttpStatus.NOT_ACCEPTABLE.value())
Expand All @@ -166,7 +166,7 @@ private List<ResponseMessage> globalGetResponseMessages() {
new ResponseMessageBuilder()
.code(HttpStatus.NOT_FOUND.value())
.message("Recurso não encontrado")
.responseModel(new ModelRef("Problem"))
.responseModel(new ModelRef(PROBLEM))
.build()
);
}
Expand All @@ -176,12 +176,12 @@ private List<ResponseMessage> globalPostPutResponseMessages() {
new ResponseMessageBuilder()
.code(HttpStatus.BAD_REQUEST.value())
.message("Requisição inválida (erro do cliente)")
.responseModel(new ModelRef("Problem"))
.responseModel(new ModelRef(PROBLEM))
.build(),
new ResponseMessageBuilder()
.code(HttpStatus.INTERNAL_SERVER_ERROR.value())
.message("Erro interno do servidor")
.responseModel(new ModelRef("Problem"))
.message(ERRO_INTERNO_DO_SERVIDOR)
.responseModel(new ModelRef(PROBLEM))
.build(),
new ResponseMessageBuilder()
.code(HttpStatus.NOT_ACCEPTABLE.value())
Expand All @@ -200,12 +200,12 @@ private List<ResponseMessage> globalDeleteResponseMessages() {
new ResponseMessageBuilder()
.code(HttpStatus.BAD_REQUEST.value())
.message("Recurso não encontrado")
.responseModel(new ModelRef("Problem"))
.responseModel(new ModelRef(PROBLEM))
.build(),
new ResponseMessageBuilder()
.code(HttpStatus.INTERNAL_SERVER_ERROR.value())
.message("Erro interno do servidor")
.responseModel(new ModelRef("Problem"))
.message(ERRO_INTERNO_DO_SERVIDOR)
.responseModel(new ModelRef(PROBLEM))
.build()
);

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/tallyto/algafood/core/web/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("*");
.allowedMethods("*")
.allowedOrigins("*")
.allowedHeaders("*");
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/tallyto/algafood/CadastroCozinhaApiIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.restassured.http.ContentType;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -19,6 +20,7 @@

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource("/application-test.properties")
@Disabled("Verificar como testar com authorization")
public class CadastroCozinhaApiIT extends BaseTest {

public static final int COZINHA_ID_INEXISTENTE = 100;
Expand Down