HttpSessionSecurityContextRepository를 사용안하는 문제
553
19 câu hỏi đã được viết
선생님 안녕하세요.
스프링 시큐리티 업데이트 버전만 손꼽아 기다리는 중입니다ㅠㅠ
우선 저는 프로젝트에서 기존 버전이 아니라 최신 버전으로 Security를 적용하고 session 저장소로 @EnableRedisHttpSession를 사용해 Redis를 사용하는 중입니다.
Redis에 sessionId가 저장되는것까지 확인했습니다.
선생님 강의보면서 참고하면서 잘 따라왔다고 생각했는데, 아래처럼 에러가 뜹니다. HttpSessionSecurityContextRepository에서 SPRING_SECURITY_CONTEXT Key를 이용해서 찾은게 SecurityContext가 아닌 Authentication 인증객체라는 내용 같은데요.
Authentication < SecurityContext < SecurityContextHolder가 아니라 Authentication < SecurityContextHolder가 된것 같습니다.
20240322 21:08:43.930 [http-nio-8080-exec-2] WARN o.s.s.w.c.HttpSessionSecurityContextRepository - SPRING_SECURITY_CONTEXT did not contain a SecurityContext but contained: '{authentication={authorities=[{authority=ROLE_ADMIN}], details={remoteAddress=0:0:0:0:0:0:0:1, sessionId=null}, authenticated=true, principal={password=null, username=sejinpark@email.com, authorities=[{authority=ROLE_ADMIN}], accountNonExpired=true, accountNonLocked=true, credentialsNonExpired=true, enabled=true}, credentials=null, name=sejinpark@email.com}}'; are you improperly modifying the HttpSession directly (you should always use SecurityContextHolder) or using the HttpSession attribute reserved for this class?
그래서 로그인한 상태에서 아래 내용을 출력해도 AnonymousUser가 뜨는데요.
SecurityContextHolder.getContext().getAuthentication()
인증 저장소 필터 챕터에서 SecurityContextPersistenceFilter를 deprecated되서 SecurityContextHolderFilter를 디버깅해봤더니, SecurityContextRepository 구현체 2개 (HttpSessionSecurityContextRepository, DelegatingSecurityContextRepository) 중에서 DelegatingSecurityContextRepository로만 가서 문제인것 같습니다. 아예 HttpSessionSecurityContextRepository로 들어가질 않더라구요. 이게 문제인것 같은데, 어느부분을 확인해아할지, 혹은 어떤 필터를 커스텀해야할지 여쭙고싶습니답
참고로 securityContext를 아래처럼 설정했습니다
.securityContext((securityContext) -> securityContext
.securityContextRepository(new DelegatingSecurityContextRepository(
new HttpSessionSecurityContextRepository()
))
Câu trả lời 2
0
안녕하세요, 인프런 AI 인턴입니다. 세진님.
스프링 시큐리티의 인증 저장소와 관련하여 직면한 문제에 대해 설명해주셨네요. 로그인 상태에서 AnonymousUser가 반환되고, HttpSessionSecurityContextRepository를 올바르게 사용하지 못하는 문제로 보입니다.
스프링 시큐리티의 인증 과정과 저장소 관리기에 대한 깊은 이해가 필요한 상황입니다. 질문하신 내용과 아주 유사한 상황을 다룬 질문이 있어, 해당 내용이 도움이 될 것 같습니다.
“Session 과 SecurityContext에 관련된 질문입니다.”에서는
SecurityContextHolder,SecurityContext,Authentication, 그리고Session사이의 관계 및 다루는 방법에 대해 논의되었습니다. 프로젝트에 적용하려는HttpSessionSecurityContextRepository의 사용법에서 어려움을 겪고 계신 점과 관련이 있어 보입니다.“스프링 시큐리티 주요 아키텍처 이해 - 4. 인증 저장소 관련 질문”에서는
SecurityContext를 커스텀하여 사용하는 상황을 다뤘습니다. 이는SecurityContextHolder를 통해 접근하는 방법과 관련된 문제를 해결하는 데 도움이 될 수 있습니다.
위 내용을 참고하여 HttpSessionSecurityContextRepository와 SecurityContextPersistenceFilter대신 사용된 SecurityContextHolderFilter 관련 문제를 해결할 방향을 찾으시길 바랍니다.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.
시큐리티 공부 버전 질문
0
173
1
[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈
0
183
1
AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우
0
172
1
강의 코드가 왜이렇게 뒤죽박죽인가요...
0
246
1
메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..
0
233
1
파라미터값이 넘어가지 않습니다 ....
0
372
1
security filterChain 설정 질문이 있습니다.
0
328
1
소스 부분 질문 드립니다.
0
206
2
섹션4 7번 강의 문제가 있는거 같네요.
0
342
2
파일이 수시로 이름이 바껴있네요 ㄷㄷ
0
302
1
error , exception 이 잘 안됩니다.
0
275
2
thymeleaf tag 질문합니다.
0
194
2
버전업하면서 deprecated된 것들이 너무많아요
0
476
1
spring security 패치 관련
0
435
1
모바일을 사용할때 토큰말고 세션
0
843
2
DB 연동한 인가 부분에 대한 질문입니다!
0
262
1
Ajax방식도 똑같이 Session방식을 사용하는건가요?
0
305
1
Config 파일 생성 시 질문이 있습니다.
0
223
1
강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..
1
427
2
403 에러 뜹니다.
0
809
2
login_proc의 존재에 대한 간략한 설명입니다
0
272
1
top.html에 로그인 링크를 만들어서 로그인을 해봤습니다
0
275
2
안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!
0
186
1
안녕하세요. 익명 객체와 세션 관련 궁금증입니다.
0
288
1

