HttpBasicConfigurer etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
HttpBasicConfigurer etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

17 Mayıs 2019 Cuma

SpringSecurity HttpBasicConfigurer Sınıfı

Giriş
Basic Authentication kullanılacağını belirtir. Bu yöntemde Http isteğine şuna benzer bir alan yerleştirilir.
Accept: application/json, text/plain, */*
Authorization: Basic aW4yOG1pbnV0ZXM6ZHVtbXk=
HTTP Basic Authentication Nedir? yazısına bakabilirsiniz.

FormAuthentication İle Farkı
FormAuthentication yöntemi BasicAuthentication yöntemine göre daha çok kullanılıyor. FormAuthentication için FormLoginConfigurer kullanılır

Kullanım
Şöyle yaparız. Burada root "/" yolundan itibaren security uygulanmak istenmiyor. Belirtilen parametreden itibaren HttpBasic Authentication uygulanmak isteniyor. Çünkü örnekte multiple realm authentication yapılıyor. Bu yüzden de WebSecurityConfigurerAdapter sınıfına @Order verilmiş. Ayrıca parametrede çoklu yol kullanabilmek için virgül ayraç olarak kullanılmış.

Detay için RequestMatcherConfigurer yazısına bakabilirsiniz.
@Configuration
@EnableWebSecurity
@Order(1)
public class BasicAuthSecurityConfiguration extends WebSecurityConfigurerAdapter {

  @Value("${spring.security.basic.matcher:/actuator/**}")
  String endpointMatcher;

  @Override
  protected void configure(HttpSecurity http) throws Exception {

    http.cors().and().csrf().disable();
    http.requestMatchers().antMatchers(endpointMatcher.split(","))
      .and()
        .authorizeRequests()
          .anyRequest().authenticated()
      .and()
         .httpBasic();
    }
}
authenticationEntryPoint metodu
Şöyle yaparız.
http.authorizeRequests()
            .antMatchers("/#/logout").permitAll()
            .antMatchers("/loginFailed.jsp").permitAll()
            .antMatchers("/saml/**").permitAll()
        .anyRequest()
                .authenticated()
                .and().httpBasic().authenticationEntryPoint(samlEntryPoint())
                .and().requiresChannel().anyRequest().requiresInsecure();
realmName metodu
Açıklaması şöyle
 ... this is also the string that will be shown when the browser pops up the login window, e.g.

Please enter your username and password for <realm name>:
Örnek
Şöyle yaparız.
http.httpBasic().realmName ("MY_REALM");