image

Access unlimited bootcamps and 650+ courses forever

60
%OFF
Article image
Geraldo Júnior
Geraldo Júnior25/06/2022 17:58
Share

Adicionando Segurança a uma API Rest com Spring Security

  • #Spring Framework

Na aula sobre Autenticação SImples, o WebSecurityConfigurerAdapter, que o professor mostra na, está depreciado desde a versão 5.7.0 do Spring.

Conforme a página oficial, o que era assim:

@Configuration

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

  @Override

  protected void configure(HttpSecurity http) throws Exception {

    http

      .authorizeHttpRequests((authz) -> authz

        .anyRequest().authenticated()

      )

      .httpBasic(withDefaults());

  }

}

agora é assim:

@Configuration

public class SecurityConfiguration {

  @Bean

  public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

    http

      .authorizeHttpRequests((authz) -> authz

        .anyRequest().authenticated()

      )

      .httpBasic(withDefaults());

    return http.build();

  }

}

A página abaixo mostra todas as mudanças em segurança desde então:

https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter

Share
Comments (3)

AF

Alan Freitas - 06/07/2022 19:19

Opa, brigadão :)! Tava tentando encontrar

Dionatan Andrade
Dionatan Andrade - 25/06/2022 19:16

Top, exatamente o que eu estava procurando

Leandro Carvalho
Leandro Carvalho - 25/06/2022 18:16

Obrigado por te compartilhado