인증(Authentication)과 인과(Authorization)


Screen Shot 2021-03-11 at 7 26 53 AM

  • 어플리케이션 보안은 두가지의 독립적인 문제로 나뉜다.
  • 바로 인증(authentication)과 인가(authorization)이다.
  • 인증은 (who are you?) 이고, 인가는 (what are you allowed to do?)
  • 스프링 시큐리티는 인증과 인과를 분리하도록 설계된 아키텍처를 가지고 있으며, 두 가지 모두에 대한 전략과 확장 할 수 있는 포인트가 존재한다.

인증 (Authentication)


public interface AuthenticationManager {

  Authentication authenticate(Authentication authentication)
    throws AuthenticationException;
}
  • 인증을 위한, AuthenticationManager 라는 인터페이스를 제공한다.

  • AuthenticationManagerauthenticate 라는 메서드를 제공하는데, 다음과 같은 3가지 일을 한다.

    • 입력이 유효한 주체를 나타내는지 확인할 수 있는 경우, Authentication(authentication=true)를 반환합니다.

    • 입력이 잘못된 주체를 나타내는 것으로 판단되는 경우에는, 예외를 던집니다.

    • 만약, 결정할 수 없는 경우에는, null을 반환합니다.

  • AuthenticationException 예외는 런타임 예외이다.

  • 일반적으로 응용 프로그램의 스타일이나 목적에 따라 응용 프로그램에서 일반적인 방식으로 처리됩니다.

  • 따라서 프로그래머가 이러한 예외를 처리하지 않습니다.

Screen Shot 2021-03-11 at 7 48 00 AM

  • Authentication Manager의 가장 일반적으로 사용되는 구현은 ProviderManager로, AuthenticationProvider 인스턴스 체인을 지정합니다.

  • AuthenticationProviderAuthenticationManager와 비슷하지만, 함수를 호출하는 사람에게, Authentication 타입을 질의할 수 있는 메서드를 추가적으로 지원합니다.

  • ProviderManager는 선택적인 부모 요소를 가질 수 있으며, 모든 ProviderManagernull을 반환하는 경우에 이를 확인할 수 있다.

  • 상위의 ProviderManager를 사용할 수 없는 경우에, AuthenticationException 예외가 발생한다.

  • 경우에 따라서, 애플리케이션은 접근 권한을 그룹으로 만들어야할 때가 있는데, 그룹 별 권한을 AuthenticationManager에 위임한다.

  • 때때로, 각가의 ProviderManager는, 상위 요소를 공유한다. 상위 요소는 글로벌 리소스의 일종으로 모든 프로바이더의 예외나 상황을 처리한다.

AuthenticationManager 커스터마이징

  • 스프링 시큐리티는 응용 프로그램에 설정된 인증과 관련된 관리자 기능을 빠르게 구성할 수 있도록 몇가지 기능을 제공합니다.

  • 일반적으로 사용되는 헬퍼는 AuthenticationManagerBuilder를 사용합니다.

@Configuration
public class ApplicationSecurity extends WebSecurityConfigurerAdapter {

   ... // web stuff here

  @Autowired
  public void initialize(AuthenticationManagerBuilder builder, DataSource dataSource) {
    builder.jdbcAuthentication().dataSource(dataSource).withUser("dave")
      .password("secret").roles("USER");
  }

}
  • AuthenticationManager@Bean 메서드로 @Autowired되므로, AuthenticationManager를 빌드할 수 있다.

인가 (Authorization)


참고 문헌

>> Home