Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the construction process of SecurityFilterChain?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how is the construction process of SecurityFilterChain". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The core Bean that Spring Security embeds into Servlet is a filter called springSecurityFilterChain. This filter is the core entry of Spring Security.

No matter what kind of Web application, Spring Security obtains "springSecurityFilterChain" from IOC. There is only one registration entry for this Bean. In the class WebSecurityConfiguration, the configuration object is opened by the annotation @ EnableWebSecurity.

@ Bean (name = AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) public Filter springSecurityFilterChain () throws Exception {... return webSecurity.build ();}

Builder mode: WebSecurity, built product is: Filter, specific type is FilterChainProxy

Public final class WebSecurity extends AbstractConfiguredSecurityBuilder implements SecurityBuilder, ApplicationContextAware {...}

Template method mode: AbstractConfiguredSecurityBuilder. The template method is the builder's build method. After templating, the doBuild method is called. DoBuild is still a template method.

Overrideprotected final O doBuild () throws Exception {synchronized (configurers) {buildState = BuildState.INITIALIZING; / /-initialization-beforeInit (); init (); buildState = BuildState.CONFIGURING; / /-configuration properties-beforeConfigure (); configure (); buildState = BuildState.BUILDING; / /-built products-O result = performBuild (); buildState = BuildState.BUILT Return result;}}

The core construction method, the performBuild method, is implemented in the subclass, where the build class is WebSecurity

@ Overrideprotected Filter performBuild () throws Exception {/ / chain length int chainSize = ignoredRequests.size () + securityFilterChainBuilders.size (); / / Construction of SecurityFilterChain List securityFilterChains = new ArrayList (chainSize); / / part I: from requests that do not require security: ignoredRequest for (RequestMatcher ignoredRequest: ignoredRequests) {securityFilterChains.add (new DefaultSecurityFilterChain (ignoredRequest)); part II: from requests for security: securityFilterChainBuilders for (SecurityBuilder)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report