inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 시큐리티

DelegatingFilterProxy 질문

285

창신동 장첸

작성한 질문수 115

0

DelegatingFilterProxy를 공부하면서 두 가지 궁금한 점이 생겼습니다.

질문1.

package org.springframework.web.filter; 의 패키지 경로를 갖는 DelegatingFIlterProxy.java 프록시가

스프링컨텍스트의 빈이 아닌 서블릿컨텍스트 에 있는 빈이라는 것을 소스코드를 보고 알 수 있는지 궁금합니다.

DelegatingFilterProxy가 서블릿컨테이너에 있는 빈이라면 톰캣이 내장하고 있는 클래스라 생각이 들었고 그에 따라 springframework 패키지경로를 갖는 상황이 혼란스럽습니다 ㅠㅠ

 

질문2.

수업시간에 SecurityFilterAutoConfiguration -> DelegatingFilterProxyRegistrationBean 순으로

DelegatingFilterProxy가 생성되는 아래 생성자호출 로직을 살펴봤습니다.

new DelegatingFilterProxy(this.targetBeanName, getWebApplicationContext());

 

하지만, ctrl + shift + f 로 AbstractSecurityWebApplicationInitializer 추상클래스의 로직에서도 아래와 같이 DelegatingFilterProxy를 생성하는 것을 확인했는데요.

private void insertSpringSecurityFilterChain(ServletContext servletContext) {
		String filterName = DEFAULT_FILTER_NAME;
		DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy(filterName);
		String contextAttribute = getWebApplicationContextAttribute();
		if (contextAttribute != null) {
			springSecurityFilterChain.setContextAttribute(contextAttribute);
		}
		registerFilter(servletContext, true, filterName, springSecurityFilterChain);
	} 

 

위 두 가지에 어떤 차이점이 있는지 궁금합니다.

spring-boot Spring Security java

답변 1

1

정수원

질문하신 내용은 사실 초기화와 관련된 조금 깊은 부분이라 대략적인 흐름만 말씀드리면

일단 DelegatingFilterProxy 을 등록하는 DelegatingFilterProxyRegistrationBean 클래스가 ServletContextInitializer 를 구현하고 있습니다. 즉 서블릿 초기화에 관여하는데요.

DelegatingFilterProxyRegistrationBean 의 구문을 보시면

@Override
public DelegatingFilterProxy getFilter() {
   return new DelegatingFilterProxy(this.targetBeanName, getWebApplicationContext()) {

      @Override
      protected void initFilterBean() throws ServletException {
         // Don't initialize filter bean on init()
      }

   };
}

가 있는데 DelegatingFilterProxy 를 생성하고 등록하는 구문인데 여기서 생성한 DelegatingFilterProxy 를 부모 클래스인 AbstractFilterRegistrationBean 에서 아래와 같이 ServletContext 에 추가하고 있습니다.

@Override
protected Dynamic addRegistration(String description, ServletContext servletContext) {
   Filter filter = getFilter();
   return servletContext.addFilter(getOrDeduceName(filter), filter);
}

즉 DelegatingFilterProxy 를 서블릿 컨텍스트에 추가하고 있습니다.

그리고 AbstractSecurityWebApplicationInitializer 는 서블릿 3.0 초기화를 구현하고자 할 때 실행되는 클래스로서 스프링 부트 기반에서는 자동설정에 의해 생성되기 때문에 별도로 실행되지 않는다고 보시면 됩니다.

참고해 주시면 됩니다.

 

0

창신동 장첸

상세한 답변 감사드립니다.

DelegatingFIlterProxy.java 소스파일의 패키지가 스프링이 제공하긴 하지만

선생님 말씀을 듣고 이 클래스로 생성되는 객체자원은 servlet에 add되는 것으로 정리할 수 있었습니다

시큐리티 공부 버전 질문

0

175

1

[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈

0

186

1

AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우

0

175

1

강의 코드가 왜이렇게 뒤죽박죽인가요...

0

250

1

메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..

0

236

1

파라미터값이 넘어가지 않습니다 ....

0

374

1

security filterChain 설정 질문이 있습니다.

0

332

1

소스 부분 질문 드립니다.

0

209

2

섹션4 7번 강의 문제가 있는거 같네요.

0

344

2

파일이 수시로 이름이 바껴있네요 ㄷㄷ

0

305

1

HttpSessionSecurityContextRepository를 사용안하는 문제

0

555

2

error , exception 이 잘 안됩니다.

0

283

2

thymeleaf tag 질문합니다.

0

197

2

버전업하면서 deprecated된 것들이 너무많아요

0

478

1

spring security 패치 관련

0

437

1

모바일을 사용할때 토큰말고 세션

0

846

2

DB 연동한 인가 부분에 대한 질문입니다!

0

264

1

Ajax방식도 똑같이 Session방식을 사용하는건가요?

0

307

1

Config 파일 생성 시 질문이 있습니다.

0

227

1

강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..

1

431

2

403 에러 뜹니다.

0

813

2

login_proc의 존재에 대한 간략한 설명입니다

0

276

1

top.html에 로그인 링크를 만들어서 로그인을 해봤습니다

0

285

2

안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!

0

189

1