본문 바로가기

Proj/webClass

Hello Spring Security

1. build.gradle 설정

 

  설정 후 localhost:8080을 접속하면 다음과 같이 뜬다

 

초기 로그인 화면

 

이는 스프링 시큐리티를 사용하기로 한 순간부터 모든 페이지에 접근 시 인증이 필요하도록 설정되기 때문이다.

일단 기초 설정이 목표이므로 이 기능을 꺼보자

package sideproject.webClass.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Configuration
@EnableWebSecurity
public class SecurityConfig {



    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

        http
                .authorizeHttpRequests((authorizeHttpRequests) -> authorizeHttpRequests
                        .requestMatchers(new AntPathRequestMatcher("/**")).permitAll());
        return http.build();

    }

}

 

@EnableWebSecurity: 스프링 시큐리티의 웹 보안을 활성화하는 어노테이션이다.

 

filterChain 함수를 빈으로 등록하여 보안에 대한 설정을 할 수 있다. 여기서는 "/**"(모든 경로)에 대하여 요청을 허가하는 설정이다.

 

더 자세한 구현은 다음에 하도록 하자

'Proj > webClass' 카테고리의 다른 글

고객센터 Q&A crud 구현  (0) 2024.04.10
로그인 구현  (0) 2024.04.02
회원가입 개발 및 간단한 리팩토링  (0) 2024.03.28