inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 시큐리티

3) Form Login 인증

WebSecurityConfigurerAdapter 클래스 사용 불가

926

bomifja

작성한 질문수 1

0

2~3강의중 WebSecurityConfigurerAdapter 클래스를가 사용하는 버전이 업데이트 되면서 더이상 사용할 수 없는데 혹시 다른 클래스를 상속받아 설정하여 사용하는 방법 알려주실 수 있나요?

 

 

java spring-boot Spring Security

답변 1

2

정수원

해당 내용과 관련해서는 조만간 자료를 정리해서 공지해 드릴 예정입니다.

일단 아래와 같이 구성을 하시면 됩니다.

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    // image, js, css 등의 정적 파일을 시큐리티가 필터하지 않도록 설정 
    @Bean
    public WebSecurityCustomizer webSecurityCustomizer() {
        return web -> web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations());
    }

    // AuthenticationManager 빈 참조 및 사용자정의 AuthenticationProvider 객체를 설정해야 할 경우
    @Bean
    public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
        ProviderManager authenticationManager = (ProviderManager) authenticationConfiguration.getAuthenticationManager();
        authenticationManager.getProviders().add(customAuthenticationProvider());
        return authenticationManager;
    }
    @Bean
    public CustomAuthenticationProvider customAuthenticationProvider() {
        return new CustomAuthenticationProvider();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return PasswordEncoderFactories.createDelegatingPasswordEncoder();
    }

    // WebSecurityConfigurerAdapter 를 상속하지 않고 SecurityFilterChain 빈을 생성해서 사용함
    // 여러개 빈을 설정할 수 있음
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        return http

                .authorizeRequests()
                .antMatchers("/mypage").hasRole("USER")
                .antMatchers("/messages").hasRole("MANAGER")
                .antMatchers("/config").hasRole("ADMIN")
                .antMatchers("/**").permitAll()
                .and()
                .formLogin()
                .loginPage("/login")
                .loginProcessingUrl("/login_proc")
                .permitAll()
                .and()
                .build();
    }
}

 

일단 위와 같이 해서 사용하시고 궁금하신 점은 문의 해 주세요

0

bomifja

빠른 답변 감사합니다. 그런데 적용 시켜보니 아래의 코드에서

CustomAuthenticationProvider 클래스를 따로 생성하지 않으면 실행이 불가합니다.

주석처리하고 진행하니 authenticationManager 값이 null이라 진행이 불가하고, 아래의 코드를 모두 주석처리하니 Whitelabel Error page가 발생합니다.

해당부분을 넘어가면 다음 강의에서 해결할 수 있나요?

  @Bean
    public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
        ProviderManager authenticationManager = (ProviderManager) authenticationConfiguration.getAuthenticationManager();
        authenticationManager.getProviders().add(customAuthenticationProvider());
        return authenticationManager;
    }
    @Bean
    public CustomAuthenticationProvider customAuthenticationProvider() {
        return new CustomAuthenticationProvider();
    }

0

정수원

깃헙 소스를 공유 해 주시면 확인해 보도록 하겠습니다.

0

포근포근한 수달

선생님, 사후지원 해주셔서 감사합니다.

그런데 1월 8일 현재 시점에

.authorizeRequests()

이 메서드 또한 deprecated가 되었습니다..ㅠㅠ

한 번 더 확인해주시면 감사하겠습니다..!

시큐리티 공부 버전 질문

0

177

1

[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈

0

187

1

AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우

0

179

1

강의 코드가 왜이렇게 뒤죽박죽인가요...

0

254

1

메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..

0

238

1

파라미터값이 넘어가지 않습니다 ....

0

376

1

security filterChain 설정 질문이 있습니다.

0

332

1

소스 부분 질문 드립니다.

0

210

2

섹션4 7번 강의 문제가 있는거 같네요.

0

345

2

파일이 수시로 이름이 바껴있네요 ㄷㄷ

0

306

1

HttpSessionSecurityContextRepository를 사용안하는 문제

0

557

2

error , exception 이 잘 안됩니다.

0

284

2

thymeleaf tag 질문합니다.

0

198

2

버전업하면서 deprecated된 것들이 너무많아요

0

478

1

spring security 패치 관련

0

438

1

모바일을 사용할때 토큰말고 세션

0

852

2

DB 연동한 인가 부분에 대한 질문입니다!

0

265

1

Ajax방식도 똑같이 Session방식을 사용하는건가요?

0

308

1

Config 파일 생성 시 질문이 있습니다.

0

228

1

강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..

1

433

2

403 에러 뜹니다.

0

813

2

login_proc의 존재에 대한 간략한 설명입니다

0

277

1

top.html에 로그인 링크를 만들어서 로그인을 해봤습니다

0

288

2

안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!

0

191

1