복붙노트

[SPRING] HttpSecurity, WebSecurity 및 AuthenticationManagerBuilder

SPRING

HttpSecurity, WebSecurity 및 AuthenticationManagerBuilder

누구든지 구성 (HttpSecurity), 구성 (WebSecurity) 및 구성 (AuthenticationManagerBuilder)을 무시할 때 설명 할 수 있습니까?

해결법

  1. ==============================

    1.configure (AuthenticationManagerBuilder)는 AuthenticationProviders를 쉽게 추가 할 수있게하여 인증 메커니즘을 설정하는 데 사용됩니다. 다음은 내장 된 'user'및 'admin'로그인을 사용하여 메모리 내 인증을 정의합니다.

    configure (AuthenticationManagerBuilder)는 AuthenticationProviders를 쉽게 추가 할 수있게하여 인증 메커니즘을 설정하는 데 사용됩니다. 다음은 내장 된 'user'및 'admin'로그인을 사용하여 메모리 내 인증을 정의합니다.

    public void configure(AuthenticationManagerBuilder auth) {
        auth
            .inMemoryAuthentication()
            .withUser("user")
            .password("password")
            .roles("USER")
        .and()
            .withUser("admin")
            .password("password")
            .roles("ADMIN","USER");
    }
    

    configure (HttpSecurity)는 선택 일치를 기반으로 리소스 수준에서 웹 기반 보안을 구성 할 수 있습니다. 아래 예제에서는 / admin /으로 시작하는 URL을 ADMIN 역할이있는 사용자로 제한하고 다른 URL을 성공적으로 인증해야한다고 선언합니다.

    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .antMatchers("/admin/**").hasRole("ADMIN")
            .anyRequest().authenticated()
    }
    

    configure (WebSecurity)는 전역 보안 (리소스 무시, 디버그 모드 설정, 사용자 지정 방화벽 정의 구현을 통한 요청 거부)에 영향을주는 구성 설정에 사용됩니다. 예를 들어, 다음 방법을 사용하면 인증을 위해 / resources /로 시작하는 모든 요청이 무시됩니다.

    public void configure(WebSecurity web) throws Exception {
        web
            .ignoring()
            .antMatchers("/resources/**");
    }
    

    자세한 정보는 다음 링크를 참조하십시오. 스프링 보안 Java Config Preview : 웹 보안

  2. from https://stackoverflow.com/questions/22998731/httpsecurity-websecurity-and-authenticationmanagerbuilder by cc-by-sa and MIT license