본문 바로가기

TIL

[TIL] 항해99 Day 22

728x90

항해 22일차

두번째 스프링 개인 과제를 하고있다... 스프링 봐도봐도 어렵다..
이번 과제에 회원가입 / 로그인 기능을 추가해야 하기에 스프링 시큐리티를 찾아보았다.

1. 스프링 시큐리티

'스프링 시큐리티' 프레임워크는 스프링 서버에 필요한 인증 및 인가를 위해 많은 기능을 제공해 줌으로써 개발의 수고를 덜어 준다.

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.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity // 스프링 Security 지원을 가능하게 함
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests()
                // 어떤 요청이든 '인증'
                .anyRequest().authenticated()
                .and()
                    // 로그인 기능 허용
                    .formLogin()
                    .defaultSuccessUrl("/")
                    .permitAll()
                .and()
                    // 로그아웃 기능 허용
                    .logout()
                    .permitAll();
    }
}

'TIL' 카테고리의 다른 글

[TIL] 항해99 Day 24  (0) 2024.04.12
[TIL] 항해99 Day 23  (1) 2024.04.12
[TIL] 항해99 Day 20  (0) 2024.04.12
[TIL] 항해99 Day 19  (0) 2024.04.12
[TIL] 항해99 Day 18  (0) 2024.04.11