스프링 프레임워크 기반의 애플리케이션에서 보안 기능을 제공하는 강력하고 포괄적인 보안 프레임워크입니다. 인증(authentication)과 인가(authorization)를 포함하여 다양한 보안 관련 기능을 제공합니다.
인증 (Authentication)
사용자가 누구인지 확인하는 과정입니다. 일반적으로 사용자 이름(username)과 비밀번호(password)를 통해 이루어지며, 인증이 성공하면 사용자는 애플리케이션에 액세스할 수 있게 됩니다.
AuthenticationManager와 AuthenticationProvider가 주요 컴포넌트입니다.인가 (Authorization)
인증된 사용자가 어떤 자원에 접근할 수 있는지 결정하는 과정입니다. 특정 URL, 메서드, 또는 도메인 객체에 대한 접근 권한을 제어합니다.
AccessDecisionManager와 AccessDecisionVoter가 주요 컴포넌트입니다.
SecurityContext 및 SecurityContextHolder
SecurityContext는 현재 인증된 사용자에 대한 세부 정보를 포함합니다.
SecurityContextHolder는 SecurityContext를 저장하고 접근하는 역할을 합니다.AuthenticationManager 및 AuthenticationProvider
AuthenticationManager는 인증 프로세스를 관리하며, 하나 이상의 AuthenticationProvider를 사용하여 실제 인증을 처리합니다.
다양한 AuthenticationProvider 구현체가 있으며, 커스텀 구현도 가능합니다.UserDetailsService
UserDetailsService는 사용자 정보를 로드하는 데 사용됩니다. 주로 데이터베이스에서 사용자 정보를 가져오는 역할을 합니다.
UserDetails 인터페이스를 구현한 객체를 반환합니다.GrantedAuthority
사용자의 권한을 나타내는 인터페이스입니다. 사용자가 가지고 있는 권한을 나타내며, 이를 통해 인가를 처리합니다.
필터 체인 (Filter Chain)
Spring Security는 다양한 필터들을 통해 보안 기능을 제공합니다. 예를 들어, UsernamePasswordAuthenticationFilter, BasicAuthenticationFilter, CsrfFilter 등이 있습니다.
이러한 필터들은 특정 순서에 따라 실행됩니다.
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user")
.password("{noop}password") // {noop}은 패스워드 인코딩을 사용하지 않음을 의미
.roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
}
1차 과제를 제출했고 해설 기반 영상을 보니 다른 부분들이 많았다. 2차 과제 제출을 위해 더욱 열심히 해야겠다.