수강이 제한됩니다.
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결스프링 시큐리티
AffirmativeBased 를 생성 시 한글 변환 안 되게 해결
섹션 5. 웹 기반 인가처리 DB 연동에서 AffirmativeBased 를 생성해서 사용할 때 AccessDeniedException 발생 시 메시지가 한글로 변환되는 현상https://www.inflearn.com/questions/871752/%EC%84%B9%EC%85%98-5-%EC%9B%B9-%EA%B8%B0%EB%B0%98-%EC%9D%B8%EA%B0%80%EC%B2%98%EB%A6%AC-db-%EC%97%B0%EB%8F%99%EC%97%90%EC%84%9C-affirmativebased-%EB%A5%BC-%EC%83%9D%EC%84%B1%ED%95%B4%EC%84%9C-%EC%82%AC%EC%9A%A9%ED%95%A0-%EB%95%8C-accessdeniedexception-%EB%B0%9C%EC%83%9D-%EC%8B%9C위 질문 내용 해결한 것 같아요.선생님.. 맞는지만 봐주세요.스프링시큐리티가 초기화 될 때 ApplicationContextAwareProcessor 클래스의 invokeAwareInterfaces() 메소드에서 내부적으로 사용하는 AffirmativeBased 의 setMessageSource(this.applicationContext); 를 호출하네요. applicationContext는 ConfigurableApplicationContext 클래스로 선언되어 있습니다.그래서 security/configs/SecurityConig 에서 동일하게 선언을 하고@Autowired ConfigurableApplicationContext applicationContext;setMessageSource() 에 전달했습니다.private AccessDecisionManager affirmativeBased() { AffirmativeBased affirmativeBased = new AffirmativeBased(getAccessDecisionVoters()); affirmativeBased.setMessageSource(this.applicationContext); return affirmativeBased; }그러니 메시지가 한글로 변환되지 않고 영문으로 잘 나오네요.그리고 applicationContext 가 동일한 객체이냐 가 궁금해서 디버깅을 해보면 먼저 SecurityConfig에서 AffirmativeBased 생성을 먼저 시작하는데 이때 applicationContext 는 디버깅 창에서 applicationContext = {AnnotationConfigServletWebServerApplicationContext@9659} "org.springframework.boot.web.servlet.context.AnnotationConfigSevletWebServerApplicationContext@6ae4b437, ..." 이렇게 표현됩니다.그 다음 ApplicationContextAwareProcessor 의 invokeAwareInterfaces() 가 호출되는데.여기서 120줄 에서 break point 잡고 this.applicationContext 을 디버깅 해보면this.applicationContext = {AnnotationConfigServletWebServerApplicationContext@9659} "org.springframework.boot.web.servlet.context.AnnotationConfigSevletWebServerApplicationContext@6ae4b437, ..." 로 동일하네요. 맞는 것 같은데..이렇게 구현하면 되는지요?
- 미해결스프링 시큐리티
FilterChainProxy 궁금한게 있어요
안녕하세요.스프링 시큐리티 주요 아키텍처 이해 - #01. FilterChainProxy (9:45)에서 "각 필터들은 필터간의 체인으로 다 연결되어 있겠죠" 라고 말씀하시면서 필터간에 짝을 지어주시는 부분이 필터들이 서로 참조하고 있다는 뜻은 아닌거죠?필터에서 chain.dofilter() 호출하면 VirtualFilterChain에서 다음 필터를 호출해서, 필터들이 연속적으로 호출 되는걸로 이해했는데 헷갈려서요...체인으로 연결되었다는게 무슨 의미인지 알수있을까요?
- 미해결스프링 시큐리티
5-3 에서 계속 403에러가 발생하는 이유를 모르겠네요;;
{ "timestamp": "2023-05-14T12:49:46.896+00:00", "status": 403, "error": "Forbidden", "path": "/api/login"} https://github.com/whitewise95/springSecurity 마스터 브랜치입니다.
- 미해결스프링 시큐리티
섹션 5. 웹 기반 인가처리 DB 연동에서 AffirmativeBased 를 생성해서 사용할 때 AccessDeniedException 발생 시 메시지가 한글로 변환되는 현상
AffirmativeBased 객체에 대한 질문 https://www.inflearn.com/questions/327562/affirmativebased-%EA%B0%9D%EC%B2%B4%EC%97%90-%EB%8C%80%ED%95%9C-%EC%A7%88%EB%AC%B8%EC%9E%85%EB%8B%88%EB%8B%A4한글 인코딩 오류https://www.inflearn.com/questions/52731/%ED%95%9C%EA%B8%80-%EC%9D%B8%EC%BD%94%EB%94%A9-%EC%98%A4%EB%A5%98위 내용 모두 동일 내용이네요.ch05-03 에서 섹션5와 섹션 6까지 많은 것을 구현하셔서 해당 내용에 대한 branch가 없네요. 선생님 github의 ch05-03a branch 에서 재현 되네요. 이 브랜치가 섹션 5에서 섹션 6까지 모두 구현된 소스 같아요.ch05-03a branch 의 application.properties 에서 spring.profiles.active=pointcut 를 주석 처리 후 실행 시키면 실행이 되고 user 로 로그인한 다음에 메시지 페이지에 접근하면 재현 됩니다.AffirmativeBased 클래스의 84번 줄에 break point 잡고 디버깅하면 messages.getMessage() 호출 후 AccessDeniedException 을 생성하여 throw 될 때 detailMessage를 보면 "Access is denied" 이 "접근이 거부되었습니다" 라고 변경되어 저장되네요.왜 locale 문제가 발생하는지 잘 모르겠네요. 저는 영문으로 사용해야 하는데 이 원인이 해결되지 않으면 자원 관리에 대한 DB 연동 자체를 사용할 수 없을 것 같아요ㅠ선생님 왜 그런지 도와주세요.
- 해결됨스프링 시큐리티
섹션 4. Ajax 내용 중 front end / 리다이렉트 질문
안녕하세요. 선생님.섹션 4 Ajax 공부 중 궁금한 점이 있어서 질문 드립니다.너무 궁금해요.. 선생님 꼭 답변 부탁드리겠습니다. 1. 7장 front end에서도 루트로 강제 redirect 시킨 것을 원래 가고자 했던 곳으로 redirect 되도록 구현 가능한지요? 7장에 login.htm 파일을 보면 로그인 성공 시 front end 에서 window.location = '/'; 로 루트 페이지로 강제 이동 시켰네요. FormAuthenticationSuccessHandler 처럼 RequestCache 이용하여 서버에서 이전에 가고자했던 곳으로 redirect 시키는 것 처럼.. front end 에서도 구현 가능한 방법이 있는지요? 2. 3장 내용의 서버 redirect3장 인증필터 인증처리자 내용을 구동 시키면 4장 내용 AjaxAuthenticationSuccessHandler 를 구현하지 않았기 때문에 로그인에 성공하면 원래 가고자 했던 곳으로 redirect 302 응답을 서버에서 내려주네요. 그래서 ajax.http 에서 로그인을 시도하면 자동 redirect 가 되네요.질문 1과 비교하여 front-end 에서 redirect 를 하는게 맞는지 서버에서 해주는게 맞는지 실무에서는 어떻게 구현하는지? 알고 싶습니다. 어떤게 더 좋은지.. 3. 서버에서 302 redirect 와 json 데이터 응답4장 인증핸들러의 내용중 AjaxAuthenticationSuccessHandler 내용을 보면 redirect 페이지를 내려주는게 아니라 json 데이터를 내려주는데.. FormAuthenticationSuccessHandler 처럼 RequestCache 구현하여 302 redirect 응답과 json 데이터도 함께 내려주는게 가능한지요? 4. 위 내용 중 어느 구현이 실무에서 많이 사용하는 구현인지 알려주세요.
- 해결됨스프링 시큐리티
Intellij git branch 하이라이팅 방법
안녕하세요. 강의 잘 듣고 있습니다. 세션 4 강의 내용을 보고 있는데.. 선생님 intellij 왼쪽 상단에 git branch 가 highlighting 되어 분홍색(?) 으로 표시되는 신기한 걸 봤네요. 이거 어떻게 하는 건가요? 좋은 기능 같아서요. plugin 이면 어떤 plugin 을 설치해야 되는지 알려주실 수 있는지요?
- 미해결스프링 시큐리티
Ip 제한의 대한 질문이 있습니다.
강의에서 설명해주신 내용은 잘 이해했습니다.강의의 내용은 permitAll 자원을 제외하고, 나머지 인가 자원의 대한 Ip 권한 체크인데요.개인적인 생각으로는 보통 특정 자원이 아닌, 모든 자원의 대한 IP 제한을 하지 않나 싶습니다.그렇게되면, Voter로는 해당 구현이 어려워 보이는데요.[permitAll은 FilterSecurityInterceptor를 상속한 PermitAllFilter에서 처리하기 때문]모든 자원에 대한 IP 제한을 할 경우, 커스텀 필터[IpAccessFilter]를 만들어서 제한을 해야한다고 생각합니다.그러 경우, FilterSecurityInterceptor 전에 두고, 화이트 리스트 IP가 아니라면 AccessDeniedException을 발생할까 고민중입니다. 해당 필터의 위치는 어느쪽이 적합한지와 제가 질문드린 내용의 대한 강사님의 생각이 궁금합니다.
- 미해결스프링 시큐리티
Security 6.0에서의 다중보안설정
안녕하세요, 강의 잘 듣고 있는 수강생입니다. 현재 강의를 들으면서 토이프로젝트를 구축 중입니다.https://www.inflearn.com/questions/42102/%EB%8B%A4%EC%A4%91-%EB%B3%B4%EC%95%88-%EC%84%A4%EC%A0%95위 링크의 질문에서 선생님께서 답변 달아주신 내용인,Admin의 url 에 따른 인증 방식은 Form,User의 url 에 따른 인증 방식은 Rest 방식으로 구분 지으려는 상황입니다. 6.0 버전에 따른 강의는 추후 개정하신다는건 공지를 통해서 알고는 있는데.. 제가 이리저리 뜯어봐도 도저히 인증 방식 다르게 적용하는 부분이 너무나도 안 되서 답답하다보니 질문글을 남기게 됐습니다.. Security 6.0 이상에서 "/api"로 시작하는 url과 "/web"으로 시작하는 url 요청에 따라 다른 인증방식을 적용할 수 있는 간단한 예시를 알려주실 수 있으실까요?
- 미해결스프링 시큐리티
SessionManagementFilter의 대한 문의드립니다.
https://www.inflearn.com/course/lecture?courseSlug=%EC%BD%94%EC%96%B4-%EC%8A%A4%ED%94%84%EB%A7%81-%EC%8B%9C%ED%81%90%EB%A6%AC%ED%8B%B0&unitId=29835&tab=curriculum해당 강의를 듣고 질문이 있습니다.FilterChainProxy의 시큐리티 필터 목록을 보면 SessionManagementFilter가 별도로 있는데요.강사님이 설명해주신 내용과 ppt를 보면, UsernamePasswordAuthenticationFilter에서 호출되는 CompositeSessionAuthenticationStrategy의 strategy들을 SessionManagementFilter라 말씀하시는 것 같습니다.그럼 시큐리티 필터 목록에 있는 SessionManagementFilter는 언제 호출되는걸까요?혹시라도 제가 잘못 이해한 부분이 있다면, 피드백 부탁드립니다.
- 미해결스프링 시큐리티
CSRF 세션클러스터링
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.서버가 이중화되어 있고 웹서버와 WAS 사이 클러스터링은 처리가 되어 있습니다.서버 A에서 로그인 후 서버 B에서 로그인이 잘 되는것을 확인했습니다.크롬 개발자 도구에서 POST방식으로 호출 시 헤더에 CSRF 토큰이 존재하는 것 까진 확인하였는데 401에러가 발생합니다. 오류 원인 예상가는 부분은 CSRF 토큰이 각 서버에 공유되지 않아 발생하는게 아닌가 싶습니다...혹시 이 상황을 어떻게 해결해야할까요,,,
- 미해결스프링 시큐리티
ajax 인증 유지
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.안녕하세요 security6로 ajax 로그인 구현을 따라하고 있습니다. 그런데 /api/login을 호출할 떄는 인증이 잘 되는데 그 후 /api/messages 를 호출하면 user, manager 둘다 항상 unauthorized로 나와서 보니 /api/messages를 호출할 때 securitycontext에 이전에 등록한 authentication을 찾을 수 없는데 원인과 해결방법을 찾을 수 없어 질문드립니다.githubhttps://github.com/jjoylee/security-demo/tree/master/src/main/java/com/example/securitydemo/security/config
- 미해결스프링 시큐리티
UsernamePasswordAuthenticationToken 생성 질문입니다.
new UsernamePasswordAuthenticationToken(accountContext.getAccount(), null, accountContext.getAuthorities());아래처럼 토큰을 생성하신 이유가 궁금합니다.UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(accountContext.getAccount(),null, accountContext.getAuthorities());강사님께서 다른 질문에 답변해주신걸 보면1. pricipal 객체는 UserDetails 타입의 Wrapper 객체가 아닌 실제 객체(?)를 참조하는게 더 낫다.2. credentials는 이미 우리가 만든 CustomAuthenticationProvider에서 비밀번호를 검증했으므로 null로 세팅했다.라고 이해햇습니다.그렇다면 역으로1. 다음 필터에서 principal 객체는 유저의 이름만 필요하다고하면 유저이름만 세팅해도 무방한가요?즉, 어플리케이션에서 필요로하는 principal 객체가 무엇이냐에 따라 다르게 세팅하면 되는게 맞나요?2. 다음 필터에서 credentials 항목을 필요로 한다면, 해당 항목도 null이아닌 account객체에 있는 패스워드로 채우는게 맞나요?
- 해결됨스프링 시큐리티
authenticationProvider, secret_key 관련 질문
현재 문제 상황이 이렇습니다.secret_key value 가 "secret" 이 아니여도 정상적으로 로그인 되버립니다. 그래서 SecurityConfig 설정을 잘못해서 authenticationProvider 나 authenticationDetailSource 가 정상적으로 작동을 안하는지 의심되서 각각 코드에 break 를 걸고 debug 를 돌렸더니 break 가 걸려서 돌아갑니다. 그리고 진짜 진짜 신기한게 secret_key 가 null 인게 debug 모드에서 확인됩니다.그리고 secret_key == null 이 true 인게 확인됩니다. 그런데 exception 이 작동을 안하고 그냥 로그인이 되버립니다. 대체 이게 무슨일인거죠.. https://github.com/Hosung-Ahn/backend-practice/tree/main/demo-security코드로 봐주시면 너무 감사할 것 같습니다..
- 미해결스프링 시큐리티
Ajax에서 진도를 못나가고 막혀 있습니다.
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. WebSecurityConfigurerAdapter Deprecated 되서 사용을 못하는데 이거에 대한 소스 코드 공유를 해주시면 안될까요?수업 따라가기가 벅찹니다. 돈을 주고 강의를 듣는데 이런 부분은 업데이트가 필요하다고 생각합니다.
- 미해결스프링 시큐리티
스프링 시큐리티 6부터는 아예 로직이 바뀐 듯 싶습니다.
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.질문이라고 보기에는 조금 어려울 수도 있는 글이긴 한데, 물론 강의는 스프링 시큐리티 5로 되어있긴 하지만 저는 시큐리티 6로 따라보고 있는데요.지금까지 강의 내용은 완벽히 일치하진 않아도 소스 보면서 비슷한 부분이 많이 남아 있었는데, 6버전부터는 아예 Vote 작업과 관련된 내용이 모두 deprecate 되고 모든 처리는 AuthorizationFilter 에서 진행되는 듯 합니다.사실 강의 보면서도 Voting 작업의 실제 필요성에 대해서 의문이 있긴 했는데, 아마 그러한 의견이 반영되었는지는 잘 모르겠습니다.
- 해결됨스프링 시큐리티
안녕하세요 강사님.
안녕하세요 강사님강의 내용을 듣고 제가 이해한 부분이 맞는지 여부와추가적으로 질문드리고 싶은 내용이 있습니다. 유저가 최초 로그인을(인증) 하게 되면SecurityContextPersistenceFilter에 HttpSessionSecurityContextRepository를 통해 SecurityContext를 생성하고UsernamePasswordAuthenticaionFilter에서 인증 처리를 거친 후에SecurityContextPersistenceFilter에서 Session에 저장하여 SecurityContext를 저장한다. 인증 이후에 유저가 요청하게 되면SecurityContextPersistenceFilter에 HttpSessionSecurityContextRepository를 통해 Session에서 SecurityContext를 가져와서SecurityContextHolder에 저장한다. 우선 제가 이해한 부분은 이렇습니다.맞게 이해했는지 궁금합니다. 그리고 여기서 추가로 여쭤보고 싶은 점이1. SecurityContextPersistenceFilter에 설명 강의 부분에서최종 응답 시 공통 로직으로 SecurityContextHolder에서 clearContext()를 한다고 설명해주셨는데SecurityContextHolder를 clear하지 않고 유지해야 Authentication객체를 계속 유지하는 게 아닌지 궁금합니다.또한 로그인한 유저 객체를 가져올 때SecurityContextHolder.getContext().getAuthentication()을 통해서 가져오는데최종 응답 시에 clearContext()를 한다면 어떻게 가져오는지 궁금합니다. 2. ajax 방식을 연습할 겸 따로 프로젝트를 만들어서 진행해봤습니다.거기서 FormLogin방식 자체를 사용하지 않았더니 filterChainProxy에 UsernamePasswordAuthenticationFilter 자체가 등록되지 않는 것 같습니다.UsernamePasswordAuthenticationFilter는 FormLogin 방식에서만 등록되는 필터인가요?그리고 인증 이후 SecurityContextPersistenceFilter에서 SecurityContextHolder에 값을 저장하는 로직이 궁금합니다.자체 필터를 등록하고 해당 필터에서 HttpSession에 SecurityContext key("SPRING_SECURITY_CONTEXT")로 authentication을 저장해도SecurityContextPersistenceFilter에서 SecurityContextHolder에 SecurityContext를 설정하지 않는 것 같습니다.
- 미해결스프링 시큐리티
접근이 거부되었습니다. 예외가 발생합니다.
5) 웹 기반 인가처리 DB 연동 - FilterInvocationSecurityMetadataSource (2) 강의 관련 질문입니다. 참고로, 현재 SecurityConfig 파일이 파일명으로 구분해서 Ajax 인증용과 폼인증 두개 입니다.문제는 로그인까지 성공하고 /mypage 로 들어가면 접근 거부 예외가 생깁니다.'org.springframework.security.access.AccessDeniedException: 접근이 거부되었습니다.' SecurityConfig , AjaxSecurityConfig 설정파일명으로 구분했고 마지막에설정 코드도 올렸지만 authenticationManager 같은 Bean 메서드들도 이름으로 구분했습니다. 사용자정보, 권한정보등 제대로 갖고 왔는데 어디가 잘못된건지 잘모르겠네요..혹시 시큐리티 설정파일에서 서비스 클래스 두가지를 사용해서 그런지 의심도 되고 그렇네요..private final SecurityResourceService securityResourceService;private final UserDetailsService userDetailsService; 아래에 도움이 될까 해서 디버깅화면 캡쳐해서 올렸습니다.그리고 코드는 아래 깃허브에 올렸습니다.walnutnamu/corespringsecurity (github.com)감사합니다. AbstractSecurityInterceptor 클래스UrlFilterInvocationSecurityMetadataSource 클래스 RoleVoter 클래스ExceptionTranslationFilter 클래스FormAccessDeniedHandler 클래스AccessDeniedException 클래스 웹페이지에는 흰 배경만 나타나고 302 코드를 반환하네요.Request URL:http://localhost:8080/mypageRequest Method:GETStatus Code:302Remote Address:[::1]:8080Referrer Policy:strict-origin-when-cross-orig 시큐리티 설정파일 @Configuration@RequiredArgsConstructor@Order(1)public class SecurityConfig {@Beanpublic WebSecurityCustomizer configure() {return (web) -> web.ignoring().mvcMatchers("/css/**","/js/**","/error");}private final AuthenticationConfiguration authenticationConfiguration;private final AuthenticationDetailsSource authenticationDetailsSource;private final AuthenticationSuccessHandler formAuthenticationSuccessHandler;private final AuthenticationFailureHandler formAuthenticationFailureHandler;private final SecurityResourceService securityResourceService;private final UserDetailsService userDetailsService;public PasswordEncoder passwordEncoder() {return PasswordEncoderFactories.createDelegatingPasswordEncoder();}@Beanpublic SecurityFilterChain filterChain(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/", "/users", "user/login/**", "/login*").permitAll().antMatchers("/mypage").hasRole("USER").antMatchers("/messages").hasRole("MANAGER").antMatchers("/config").hasRole("ADMIN").anyRequest().authenticated().and().exceptionHandling()//.accessDeniedPage("/denied").accessDeniedHandler(accessDeniedHandler()).and().addFilterBefore(customFilterSecurityInterceptor(), FilterSecurityInterceptor.class);http.formLogin().loginPage("/login").loginProcessingUrl("/login_proc").authenticationDetailsSource(authenticationDetailsSource).defaultSuccessUrl("/").successHandler(formAuthenticationSuccessHandler).failureHandler(formAuthenticationFailureHandler).permitAll();//http.csrf().disable();return http.build();}public FormAuthenticationProvider formAuthenticationProvider() {return new FormAuthenticationProvider(userDetailsService, passwordEncoder());}@Beanpublic AccessDeniedHandler accessDeniedHandler(){FormAccessDeniedHandler accessDeniedHandler = new FormAccessDeniedHandler();accessDeniedHandler.setErrorPage("/denied");return accessDeniedHandler;}@Beanpublic AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {ProviderManager authenticationManager = (ProviderManager) authenticationConfiguration.getAuthenticationManager();authenticationManager.getProviders().add(formAuthenticationProvider());return authenticationManager;}@Beanpublic FilterSecurityInterceptor customFilterSecurityInterceptor() throws Exception {FilterSecurityInterceptor filterSecurityInterceptor = new FilterSecurityInterceptor();filterSecurityInterceptor.setSecurityMetadataSource(urlFilterInvocationSecurityMetadataSource());filterSecurityInterceptor.setAccessDecisionManager(affirmativeBased());filterSecurityInterceptor.setAuthenticationManager(authenticationManager(authenticationConfiguration));return filterSecurityInterceptor;}public AccessDecisionManager affirmativeBased() {AffirmativeBased affirmativeBased = new AffirmativeBased(getAccessDecisionVoters());return affirmativeBased;}private List<AccessDecisionVoter<?>> getAccessDecisionVoters() {return Arrays.asList(new RoleVoter());}/*** 자원/권한 정보를 저장하고 있는 클래스를 빈으로 생성* @return* @throws Exception*/@Beanpublic FilterInvocationSecurityMetadataSource urlFilterInvocationSecurityMetadataSource() throws Exception {return new UrlFilterInvocationSecurityMetadataSource(urlResourcesMapFactoryBean().getObject());}private UrlResourcesMapFactoryBean urlResourcesMapFactoryBean() {UrlResourcesMapFactoryBean urlResourcesMapFactoryBean = new UrlResourcesMapFactoryBean();urlResourcesMapFactoryBean.setSecurityResourceService(securityResourceService);return urlResourcesMapFactoryBean;}}
- 해결됨스프링 시큐리티
예시로 들어주신 상황에 대한 의문점이 있습니다.
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. 여기서는 공격자가 이미지 태그를 이용해서 특정 주소로의 요청을 보내도록 유도하는 것 같은데, 이 경우에는 GET 메서드로 요청을 보내므로 따로 csrf 토큰을 검사하지 않으니, 여전히 공격에 취약하다고 봐야 하지 않나요?
- 해결됨스프링 시큐리티
SessionCreationPolicy의 IF_REQUIRED와 NEVER 속성에 대해서
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. IF_REQUIRED의 설명 중 "필요시"라고 되어있는 부분이 있는데 어떤 상황이 "필요시"에 해당할까요??NEVER의 설명 중 스프링 시큐리티가 생성하지 않지만 "이미 존재"하면 사용이라고 써놓으셨는데, 애초에 생성하지 않았는데 어떻게 이미 존재할 수 있나요??
- 미해결스프링 시큐리티
접근이 거부되었습니다. 예외가 발생합니다.
5) 웹 기반 인가처리 DB 연동 - FilterInvocationSecurityMetadataSource (2) 강의 관련 질문입니다. 참고로, 현재 SecurityConfig 파일이 파일명으로 구분해서 Ajax 인증용과 폼인증 두개 입니다.문제는 로그인까지 성공하고 /mypage 로 들어가면 접근 거부 예외가 생깁니다.'org.springframework.security.access.AccessDeniedException: 접근이 거부되었습니다.' SecurityConfig , AjaxSecurityConfig 설정파일명으로 구분했고 마지막에 설정 코드도 올렸지만 authenticationManager 같은 Bean 메서드들도 이름으로 구분했습니다. 사용자정보, 권한정보등 제대로 갖고 왔는데 어디가 잘못된건지 잘모르겠네요..혹시 시큐리티 설정파일에서 서비스 클래스 두가지를 사용해서 그런지 의심도 되고 그렇네요..private final SecurityResourceService securityResourceService;private final UserDetailsService userDetailsService; 아래에 도움이 될까 해서 디버깅화면 캡쳐해서 올렸습니다.감사합니다. AbstractSecurityInterceptor 클래스UrlFilterInvocationSecurityMetadataSource 클래스 RoleVoter 클래스ExceptionTranslationFilter 클래스FormAccessDeniedHandler 클래스AccessDeniedException 클래스 웹페이지에는 흰 배경만 나타나고 302 코드를 반환하네요.Request URL:http://localhost:8080/mypageRequest Method:GETStatus Code:302Remote Address:[::1]:8080Referrer Policy:strict-origin-when-cross-orig 시큐리티 설정파일 @Configuration@RequiredArgsConstructor@Order(1)public class SecurityConfig { @Bean public WebSecurityCustomizer configure() { return (web) -> web.ignoring().mvcMatchers( "/css/**", "/js/**", "/error" ); } private final AuthenticationConfiguration authenticationConfiguration; private final AuthenticationDetailsSource authenticationDetailsSource; private final AuthenticationSuccessHandler formAuthenticationSuccessHandler; private final AuthenticationFailureHandler formAuthenticationFailureHandler; private final SecurityResourceService securityResourceService; private final UserDetailsService userDetailsService; public PasswordEncoder passwordEncoder() { return PasswordEncoderFactories.createDelegatingPasswordEncoder(); } @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/", "/users", "user/login/**", "/login*").permitAll() .antMatchers("/mypage").hasRole("USER") .antMatchers("/messages").hasRole("MANAGER") .antMatchers("/config").hasRole("ADMIN") .anyRequest().authenticated() .and() .exceptionHandling() //.accessDeniedPage("/denied") .accessDeniedHandler(accessDeniedHandler()) .and() .addFilterBefore(customFilterSecurityInterceptor(), FilterSecurityInterceptor.class) ; http .formLogin() .loginPage("/login") .loginProcessingUrl("/login_proc") .authenticationDetailsSource(authenticationDetailsSource) .defaultSuccessUrl("/") .successHandler(formAuthenticationSuccessHandler) .failureHandler(formAuthenticationFailureHandler) .permitAll() ; //http.csrf().disable(); return http.build(); } public FormAuthenticationProvider formAuthenticationProvider() { return new FormAuthenticationProvider(userDetailsService, passwordEncoder()); } @Bean public AccessDeniedHandler accessDeniedHandler(){ FormAccessDeniedHandler accessDeniedHandler = new FormAccessDeniedHandler(); accessDeniedHandler.setErrorPage("/denied"); return accessDeniedHandler; } @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { ProviderManager authenticationManager = (ProviderManager) authenticationConfiguration.getAuthenticationManager(); authenticationManager.getProviders().add(formAuthenticationProvider()); return authenticationManager; } @Bean public FilterSecurityInterceptor customFilterSecurityInterceptor() throws Exception { FilterSecurityInterceptor filterSecurityInterceptor = new FilterSecurityInterceptor(); filterSecurityInterceptor.setSecurityMetadataSource(urlFilterInvocationSecurityMetadataSource()); filterSecurityInterceptor.setAccessDecisionManager(affirmativeBased()); filterSecurityInterceptor.setAuthenticationManager(authenticationManager(authenticationConfiguration)); return filterSecurityInterceptor; } public AccessDecisionManager affirmativeBased() { AffirmativeBased affirmativeBased = new AffirmativeBased(getAccessDecisionVoters()); return affirmativeBased; } private List<AccessDecisionVoter<?>> getAccessDecisionVoters() { return Arrays.asList(new RoleVoter()); } /** * 자원/권한 정보를 저장하고 있는 클래스를 빈으로 생성 * @return * @throws Exception */ @Bean public FilterInvocationSecurityMetadataSource urlFilterInvocationSecurityMetadataSource() throws Exception { return new UrlFilterInvocationSecurityMetadataSource(urlResourcesMapFactoryBean().getObject()); } private UrlResourcesMapFactoryBean urlResourcesMapFactoryBean() { UrlResourcesMapFactoryBean urlResourcesMapFactoryBean = new UrlResourcesMapFactoryBean(); urlResourcesMapFactoryBean.setSecurityResourceService(securityResourceService); return urlResourcesMapFactoryBean; }}