Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

2.9K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda