강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

우기바나님의 프로필 이미지
우기바나

작성한 질문수

스프링 시큐리티 완전 정복 [6.x 개정판]

SecurityContextRepository / SecurityContextHolderFilter - 3

SecurityContextRepository / SecurityContextHolderFilter - 3

작성

·

93

0

강의 17분 33초를 보면 다음과 같은 메서드가 있습니다.

private SecurityContextRepository getSecurityContextRepository(HttpSecurity http) {

SecurityContextRepository securityContextRepository = http.getSharedObject(SecurityContextRepository.class);

if(securityContextRepository == null) {

securityContextRepository = new DelegatingSecurityContextRepository(new HttpSessionSecurityContextRepository(), new RequestAttributeSecurityContextRepository()

}

return securityContextRepository;

}

 

저가 궁금한 것은 securityContextRepository가 null인 경우가 존재하는 경우가 있는지에 대해서 의문이 듭니다.

이전 강의에서 SecuritContextRepository는 configure 메서드로 인하여 securityContextRepository가 이미 설정되어 있지 않나, 따라서 null의 경우는 없지 않을까 입니다.

답변 2

0

정수원님의 프로필 이미지
정수원
지식공유자

네 이건 초기화 과정에서 SecuritContextRepository 가 이미 생성되었다 하더라도 http.getSharedObject(SecurityContextRepository.class) 에서는 null 일수 있습니다

아직 httpSecurity 이 공유객체에는 저장하지 않았기 때문입니다.

어떤 시점에서 http.setSharedObject(securityContextRepository) 가 실행되면 null 이 아니게 됩니다.

0

안녕하세요, 인프런 AI 인턴입니다.

SecurityContextRepository가 null일 수 있는 경우에 대한 궁금증을 잘 이해했습니다. 스프링 시큐리티에서 SecurityContextRepository는 인증 정보의 저장 및 로드와 관련된 인터페이스입니다. 스프링 시큐리티 설정에 따라, 이 객체는 시스템 내에서 자동으로 설정되지 않을 수도 있습니다.

이전에 수업에서 설명해 주신 것처럼, 특정 조건에 따라 SecurityContextRepository가 명시적으로 설정되지 않았다면 해당 부분에서 null일 수 있습니다. 이는 일반적으로 사용자 정의 보안 설정이 충분히 고려되지 않아 발생할 수 있습니다. 예를 들어, 특정 필터에서 SecurityContextRepository를 명시적으로 설정하지 않거나 기본 구현체가 제공되지 않는 경우가 있을 수 있습니다.

혹시 관련된 유사한 답변을 찾는다면 아래 URL에서 참고하실 수 있습니다:

이 링크는 인프런의 다른 수강생들이 비슷한 주제를 토론한 곳으로, 당신의 질문과 관련된 심화 내용을 제공할 수 있습니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

우기바나님의 프로필 이미지
우기바나

작성한 질문수

질문하기