Giriş
Şu satırı dahil ederiz
Şu satırı dahil ederiz
import org.springframework.web.filter.DelegatingFilterProxy;
Açıklaması şöyle
This is a servlet filter embedded in the spring context. Its job is to delegate the incoming request to a bunch of filters (not managed as spring beans) provided by the Spring web framework and hence the name, DelegatingFilterProxy.
Açıklaması şöyle
This is a filter implementation that takes a springbean name as init param and delegates the filter request to that bean.
Bu bean SecurityFilterAutoConfiguration tarafından yaratılır. SecurityFilterAutoConfiguration içindeki kod şöyle
@Bean@ConditionalOnBean(name = DEFAULT_FILTER_NAME)public DelegatingFilterProxyRegistrationBean securityFilterChainRegistration(SecurityProperties securityProperties) {DelegatingFilterProxyRegistrationBean registration =
new DelegatingFilterProxyRegistrationBean(DEFAULT_FILTER_NAME);registration.setOrder(securityProperties.getFilter().getOrder());registration.setDispatcherTypes(getDispatcherTypes(securityProperties));return registration;}
Açıklaması şöyle
You’d notice that Spring boot autoconfigures a Bean of the type DelegatingFilterProxy via a filter registration class -> DelegatingFilterProxyRegistrationBean class. The bean is only created if another bean named -> springSecurityFilterChain is found in the classpath.springSecurityFilterChain is an alias for the Spring Security’s FilterChainProxy class. It means this filter is optional and only created if we use spring security in our application.You’d also notice that while creating this DelegatingFilterProxy Filter, we pass the springSecurityFilterChain name in its constructor. It is done, to set the delegation link between the two classes. DelegatingFilterProxy uses this delegation link during runtime to invoke spring security functionality.
Şöyle yaparız.
<filter>
<filter-name>myFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>myFilterBean<param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>myFilter</filter-name>
<url-pattern>/myFilterPattern/*</url-pattern>
</filter-mapping>
Filtre şöyledirpublic class MyFilter extends GenericFilterBean {
@Autowired
InjectedBean someInjectedBean;
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
}
Hiç yorum yok:
Yorum Gönder