기본 인증 (Basic Authentication)

HTTP Basic 인증은 가장 간단한 형태의 HTTP 인증입니다. 사용자 이름과 비밀번호는 Base64 인코딩된 형태로 헤더에 포함되어 전송됩니다.

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
            .withUser("user").password("{noop}password").roles("USER");
    }
}

폼 인증 (Form-Based Authentication)

폼을 통해 사용자 이름과 비밀번호를 입력 받아 인증을 진행합니다. Spring Security는 이를 위한 로그인 폼을 기본적으로 제공하지만 커스텀 폼도 쉽게 적용할 수 있습니다.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .anyRequest().authenticated()
            .and()
        .formLogin();
}

OAuth2

OAuth2는 외부 서비스(예: Google, Facebook 등)를 통해 인증을 진행하는 프로토콜입니다. Spring Security는 이를 쉽게 적용할 수 있도록 여러 확장을 제공합니다.

@Configuration
@EnableOAuth2Sso
public class OAuth2Config extends WebSecurityConfigurerAdapter {
    // OAuth2 설정
}

JWT (Json Web Token)

JWT는 자체적으로 정보를 담은 토큰을 사용해 인증을 진행합니다. 이 방식은 Stateless한 구조로 API를 구성할 때 유용하게 사용됩니다.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
}

인증 관련 주요 클래스와 인터페이스

인증 흐름