[rest api 프로젝트 구축] - spring security (2)

geun kim·2023년 3월 27일
0

REST API 구축

목록 보기
11/20

스프링 시큐리티

● 웹 시큐리티 (Filter 기반 시큐리티) : 웹 요청에 보안 설정
● 메소드 시큐리티 : 메소드에 보안 설정
● 이 둘 다 Security Interceptor를 사용합니다.

○ 리소스에 접근을 허용할 것이냐 말것이냐를 결정하는 로직이 들어있음

의존성 추가
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>

테스트 다 깨짐 (401 Unauthorized)

● 깨지는 이유는 스프링 부트가 제공하는 스프링 시큐리티 기본 설정 때문

주요 Class

SecurityContextHolder : 인증정보 보관
AuthenticationManager : 로그인 담당 , SecurityContextHolder에 인증정보 확인

인증 방법 : BasicAuthentication, 여러가지.....
BasicAuthentication 인증 방법 :

header에 authentication,basic,username,password를 합쳐서 encoding 하여
서버에 인증 요청을 보내오면 UserDetailsService가 password를 가지고SecurityContextHolder에서 정보(username,password)를 찾아 요청 시 보내온 username과 password 일치하는 지 확인 하여 인증을 처리한다.
password는 매칭여부는 PasswordEncoder가 검증한다.

구현 class
UserDetailsService
PasswordEncoder

AccessDecisionManager : 권한확인

profile
Devops Load Map

0개의 댓글