[Start Spring Boot] Spring Security DSL

·2024년 4월 21일
0

Start Spring Boot!

목록 보기
47/53
post-thumbnail

DSL

기존 코드의 문제점

  • DSL이 적용하지 않은 기존 코드는 추후 지원을 중단한다.

What is?

  • Domain-Specific Languages
  • 도메인 특화 언어
  • DSL을 사용하면 간결하고 가독성이 높은 코드를 사용가능하다.
  • lambdas을 이용하는 것

before

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/blog/**").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .rememberMe();
    }
}

after

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests(authorizeRequests ->
                authorizeRequests
                    .antMatchers("/blog/**").permitAll()
                    .anyRequest().authenticated()
            )
            .formLogin(formLogin ->
                formLogin
                    .loginPage("/login")
                    .permitAll()
            )
            .rememberMe(withDefaults());
    }
}
  • 다음과 같이 적용해서 사용해야한다.
profile
백엔드 개발자가 꿈인 컴공과

0개의 댓글

관련 채용 정보