Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

2.9K
Visualizações
Swagger POST return 403 Prohibido Spring boot Spring seguridad

Obtengo el estado 403 Prohibido en Swagger solo para la solicitud del método POST. Probé todos los cfg de seguridad de primavera para resolver esto, pero solo funciona en los métodos GET. Estoy usando Spring Boot, Spring Security y Swagger. Podría alguien ayudarme, por favor ? Aquí está swagger cfg:

 @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } }

Y aquí está el cfg de seguridad de primavera:

 @Configuration @EnableWebSecurity public class SecurityCFG extends WebSecurityConfigurerAdapter{ @Bean public PasswordEncoder encoder() { return new BCryptPasswordEncoder(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { PasswordEncoder encoder = encoder(); auth .inMemoryAuthentication() .withUser("carlos") .password(encoder.encode("admin123")) .roles("USER") .and() .withUser("carlos2") .password(encoder.encode("admin123")) .roles("USER", "ADMIN"); } @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers( "/v2/api-docs", "/swagger-resources/**", "/swagger-ui.html", "/webjars/**" , /*Probably not needed*/ "/swagger.json") .permitAll() .anyRequest() .authenticated() .and() .httpBasic(); } @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/v2/api-docs/**"); web.ignoring().antMatchers("/swagger.json"); web.ignoring().antMatchers("/swagger-ui.html"); web.ignoring().antMatchers("/swagger-resources/**"); web.ignoring().antMatchers("/webjars/**"); } }

¡Gracias por leer!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Tuve un problema similar la otra semana, así es como conseguí que el mío funcionara, necesitaba agregar un montón más de emparejadores de lo que pensaba y agregar la desactivación de csrf, pero parece funcionar bien.

 @Bean(name="configure") @Conditional(DevConditional.class) public SecurityWebFilterChain configureDev(ServerHttpSecurity http) throws Exception { return http .csrf().disable() .authorizeExchange() .pathMatchers("/v2/api-docs").permitAll() .pathMatchers("/configuration/ui").permitAll() .pathMatchers("/swagger-resources/**").permitAll() .pathMatchers("/configuration/security").permitAll() .pathMatchers("/swagger-ui.html").permitAll() .pathMatchers("/swagger-ui/*").permitAll() .pathMatchers("/webjars/**").permitAll() .pathMatchers("/v2/**").permitAll() .and().cors() .and().oauth2ResourceServer() .jwt().and().and().build(); }

Obtuve esta respuesta ".csrf (). Disable ()" de: Spring boot con WebFlux siempre lanza el estado 403 en las pruebas

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda