中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

成都網站建設是什么百度店面定位怎么申請

成都網站建設是什么,百度店面定位怎么申請,100條經典廣告語,如何做簡易網站一、Builder設計模式 WebSecurity、HttpSecurity、AuthenticationManagerBuilder 都是框架中的構建者,把他們放到一起看看他們的共同特點: 查看AuthenticationManagerBuilder的繼承結構圖: 查看HttpSecurity的繼承結構圖: 查看W…

一、Builder設計模式

WebSecurityHttpSecurity、AuthenticationManagerBuilder 都是框架中的構建者,把他們放到一起看看他們的共同特點:

查看AuthenticationManagerBuilder的繼承結構圖:

在這里插入圖片描述

查看HttpSecurity的繼承結構圖:

在這里插入圖片描述
查看WebSecurity的繼承結構圖:

在這里插入圖片描述
可以看出他們都有這樣一條繼承樹:

|- SecurityBuilder|- AbstractSecurityBuilder|- AbstractConfiguredSecurityBuilder

二、SecurityBuilder

/*** Interface for building an Object** @param <O> The type of the Object being built* @author Rob Winch* @since 3.2*/
public interface SecurityBuilder<O> {/*** Builds the object and returns it or null.* @return the Object to be built or null if the implementation allows it.* @throws Exception if an error occurred when building the Object*/O build() throws Exception;}

SecurityBuilder是一個接口,當調用它的 build() 方法時,會創(chuàng)建一個對象。將要創(chuàng)建的對象類型由泛型 O 限制。這個接口是所有構造器的頂級接口,也是Spring Security 框架中使用Builder設計模式的基礎接口。

三、AbstractSecurityBuilder

/*** A base {@link SecurityBuilder} that ensures the object being built is only built one* time.** @param <O> the type of Object that is being built* @author Rob Winch**/
public abstract class AbstractSecurityBuilder<O> implements SecurityBuilder<O> {// 標記對象是否處于創(chuàng)建中private AtomicBoolean building = new AtomicBoolean();private O object;@Overridepublic final O build() throws Exception {if (this.building.compareAndSet(false, true)) {// 對象的實際底構建過程再 doBuild() 方法中實現this.object = doBuild();return this.object;}throw new AlreadyBuiltException("This object has already been built");}/*** 獲取已生成的對象。如果尚未構建,則會引發(fā)異常。* @return the Object that was built*/public final O getObject() {if (!this.building.get()) {throw new IllegalStateException("This object has not been built");}return this.object;}/*** 子類需實現這個方法來執(zhí)行對象構建。* @return the object that should be returned by {@link #build()}.* @throws Exception if an error occurs*/protected abstract O doBuild() throws Exception;}

AbstractSecurityBuilderSecurityBuilder的一個基礎實現抽象類,提供構造器的基礎流程和控制,能夠確保對象O只被創(chuàng)建一次。

這個類很簡單:

  • 定義了一個原子操作的對象,用來標記當前對象是否處于構造中

    private AtomicBoolean building = new AtomicBoolean();
    
  • 實現SecurityBuilder接口的 build() 方法。

    調用 doBuild() 方法完成構造,并且在調用 doBuild() 之前需要原子修改 buildingtrue,只有修改成功才能執(zhí)行 doBuild() 方法,這間接的保證了:對象只構造一次,確保構造的唯一性和原子性。

  • 定義一個 getObject() 方法,方便獲取構造的對象。

  • 定義抽象方法 doBuild() ,加入模板模式,交給子類自行實現。

四、AbstractConfiguredSecurityBuilder

源碼注釋:
A base SecurityBuilder that allows SecurityConfigurer to be applied to it. This makes modifying the SecurityBuilder a strategy that can be customized and broken up into a number of SecurityConfigurer objects that have more specific goals than that of the SecurityBuilder.

一個基本的SecurityBuilder,允許將SecurityConfigurer應用于它。這使得修改SecurityBuilder的策略可以自定義并分解為許多SecurityConfigurer對象,這些對象具有比SecurityBuilder更具體的目標。

For example, a SecurityBuilder may build an DelegatingFilterProxy, but a SecurityConfigurer might populate the SecurityBuilder with the filters necessary for session management, form based login, authorization, etc.
請參閱:
WebSecurity
作者:
Rob Winch
類型形參:
<O> – The object that this builder returns 此構造器返回的對象
<B> – The type of this builder (that is returned by the base class) 此構造器的類型(由基類返回)

它繼承自 AbstractSecurityBuilder ,在此之上又做了一些擴展。先來看看里面都有什么:

在這里插入圖片描述

4.1 內部靜態(tài)枚舉類 BuildState

這個枚舉類用來表示應用程序(構造器構造對象)的狀態(tài),代碼相對簡單,就不粘貼源碼了。

枚舉類中只有一個 int 類型的成員變量 order 表示狀態(tài)編號:

  • UNBUILT(0) :未構造

    構造器的 build 方法被調用之前的狀態(tài)

  • INITIALIZING(1) : 初始化中

    構造器的 build 方法第一次被調用,到所有 SecurityConfigurerinit 方法都被調用完這期間都是 INITIALIZING 狀態(tài)

  • CONFIGURING(2): 配置中

    表示從所有的 SecurityConfigurerinit 方法都被調用完,直到所有 configure 方法都被調用

    意思就是所有配置器都初始化了,直到配置都被調用這段時間都時 CONFIGURING 狀態(tài)

  • BUILDING(3) :對象構造中

    表示已經執(zhí)行完所有的 SecurityConfigurerconfigure 方法,到剛剛執(zhí)行完 AbstractConfiguredSecurityBuilderperformBuild 方法這期間

    意思就是從將所有配置器的配置都配置完成開始,到構造完這個對象這段時間都是 BUILDING 狀態(tài)

  • BUILT(4) :對象已經構造完成

    表示對象已經構造完成。

枚舉類中還有兩個方法:

  • isInitializingINITIALIZING狀態(tài)時返回true

  • isConfigured:大于等于 CONFIGURING 的時候返回 true

    也就是說配置器初始化完成時在構造器看來就算以配置狀態(tài)了。

4.2 成員變量

private final Log logger = LogFactory.getLog(getClass());private final LinkedHashMap<Class<? extends SecurityConfigurer<O, B>>, List<SecurityConfigurer<O, B>>> configurers = new LinkedHashMap<>();private final List<SecurityConfigurer<O, B>> configurersAddedInInitializing = new ArrayList<>();private final Map<Class<?>, Object> sharedObjects = new HashMap<>();private final boolean allowConfigurersOfSameType;private BuildState buildState = BuildState.UNBUILT;private ObjectPostProcessor<Object> objectPostProcessor;
  • configurers:所要應用到當前 SecurityBuilder 上的所有的 SecurityConfigurer。
  • configurersAddedInInitializing:用于記錄在初始化期間添加進來的 SecurityConfigurer。
  • sharedObjects:共享對象。
  • ObjectPostProcessor:由外部調用者提供,這是一個后置處理對象,在創(chuàng)建完對象后會用到這個后置處理對象。

4.3 構造方法

/**** Creates a new instance with the provided {@link ObjectPostProcessor}. This post* processor must support Object since there are many types of objects that may be* post processed.* @param objectPostProcessor the {@link ObjectPostProcessor} to use*/
protected AbstractConfiguredSecurityBuilder(ObjectPostProcessor<Object> objectPostProcessor) {this(objectPostProcessor, false);
}/**** Creates a new instance with the provided {@link ObjectPostProcessor}. This post* processor must support Object since there are many types of objects that may be* post processed.* @param objectPostProcessor the {@link ObjectPostProcessor} to use* @param allowConfigurersOfSameType if true, will not override other* {@link SecurityConfigurer}'s when performing apply*/
protected AbstractConfiguredSecurityBuilder(ObjectPostProcessor<Object> objectPostProcessor,boolean allowConfigurersOfSameType) {Assert.notNull(objectPostProcessor, "objectPostProcessor cannot be null");this.objectPostProcessor = objectPostProcessor;this.allowConfigurersOfSameType = allowConfigurersOfSameType;
}

構造函數只對兩個成員變量進行了賦值:

  • objectPostProcessor:由外部調用者提供,這是一個后置處理對象,在創(chuàng)建完對象后會用到這個后置處理對象。

  • allowConfigurersOfSameType:從源碼可以看出,默認情況下 allowConfigurersOfSameTypefalse 。

    這個成員變量的含義:

    • true 表示允許相同類型的構造器,在應用配置器時不會覆蓋相同類型的配。

4.4 方法

4.4.1 getOrBuild 方法

想要用構造器獲取最終構造的對象時,需調用這個方法。

這個方法的邏輯很簡單,調用 isUnbuilt() 方法判斷對象創(chuàng)建狀態(tài)是否未構建完成( return buildState == BuildState.UNBUILT ):

  • 如果對象已經創(chuàng)建就直接返回已經構建好的對象,
  • 否則調用構造器的 build() 方法構建對象并返回已構建完成的對象。

從剛才看到的父類 AbstractSecurityBuilder 代碼中可以知道真正的構建過程是調用子類 doBuild() 方法完成的。

isUnbuilt() 方法中,對 configurers 成員變量加了鎖(synchronized),保證獲取到的構建完成狀態(tài)時,對象真的已經構建好了。

/*** Similar to {@link #build()} and {@link #getObject()} but checks the state to* determine if {@link #build()} needs to be called first.* @return the result of {@link #build()} or {@link #getObject()}. If an error occurs* while building, returns null.*/
public O getOrBuild() {if (!isUnbuilt()) {return getObject();}try {return build();}catch (Exception ex) {this.logger.debug("Failed to perform build. Returning null", ex);return null;}
}/*** Determines if the object is unbuilt.* @return true, if unbuilt else false*/
private boolean isUnbuilt() {synchronized (this.configurers) {return this.buildState == BuildState.UNBUILT;}
}

4.4.2 doBuild 方法

使用以下步驟對configurers執(zhí)行生成:

/*** Executes the build using the {@link SecurityConfigurer}'s that have been applied* using the following steps:** <ul>* <li>Invokes {@link #beforeInit()} for any subclass to hook into</li>* <li>Invokes {@link SecurityConfigurer#init(SecurityBuilder)} for any* {@link SecurityConfigurer} that was applied to this builder.</li>* <li>Invokes {@link #beforeConfigure()} for any subclass to hook into</li>* <li>Invokes {@link #performBuild()} which actually builds the Object</li>* </ul>*/
@Override
protected final O doBuild() throws Exception {synchronized (this.configurers) {this.buildState = BuildState.INITIALIZING;beforeInit();init();this.buildState = BuildState.CONFIGURING;beforeConfigure();configure();this.buildState = BuildState.BUILDING;O result = performBuild();this.buildState = BuildState.BUILT;return result;}
}
  • 構建過程對 configurers 加鎖。
  • 方法體中時構建對象的整個流程,包括狀態(tài)變化。
  • 構建過程大致分為構建器初始化 beforeInit()、init(),構建器配置 beforeConfigure()、configure(),構建對象 performBuild()。

構建過程對 configurers 加鎖,也就意味著進入構建方法后 configurers 中的構建器應該都準備好了。這個時候如果再添加或者修改配置器都會失敗。

4.4.3 beforeInit 方法 和 beforeConfigure 方法

這兩個方法是抽象方法,由子類實現。子類通過覆蓋這兩個方法可以掛鉤到對象構建的生命周期中,實現:在配置器(SecurityConfigurer)調用初始化方法或者配置方法之前做用戶自定義的操作。

/*** Invoked prior to invoking each {@link SecurityConfigurer#init(SecurityBuilder)}* method. Subclasses may override this method to hook into the lifecycle without* using a {@link SecurityConfigurer}.*/
protected void beforeInit() throws Exception {
}/*** Invoked prior to invoking each* {@link SecurityConfigurer#configure(SecurityBuilder)} method. Subclasses may* override this method to hook into the lifecycle without using a* {@link SecurityConfigurer}.*/
protected void beforeConfigure() throws Exception {
}

在這里插入圖片描述

4.4.4 init 方法

@SuppressWarnings("unchecked")
private void init() throws Exception {Collection<SecurityConfigurer<O, B>> configurers = getConfigurers();for (SecurityConfigurer<O, B> configurer : configurers) {configurer.init((B) this);}for (SecurityConfigurer<O, B> configurer : this.configurersAddedInInitializing) {configurer.init((B) this);}
}

方法很簡單功能很簡單,就是遍歷 configurersconfigurersAddedInInitializing ,對里面存儲的配置器進行初始化。

配置器初始化的詳細內容到看配置器源碼時在了解。

4.4.5 configure 方法

@SuppressWarnings("unchecked")
private void configure() throws Exception {Collection<SecurityConfigurer<O, B>> configurers = getConfigurers();for (SecurityConfigurer<O, B> configurer : configurers) {configurer.configure((B) this);}
}private Collection<SecurityConfigurer<O, B>> getConfigurers() {List<SecurityConfigurer<O, B>> result = new ArrayList<>();for (List<SecurityConfigurer<O, B>> configs : this.configurers.values()) {result.addAll(configs);}return result;
}

遍歷 configurers ,調用所有配置器的 configure(SecurityBuilder b) 方法對當前的構建器(this)進行配置。

配置器配置詳細內容到看配置器源碼時在了解。

4.4.6 performBuild 方法

這也是一個抽象方法,需要子類實現,完成對象的創(chuàng)建并返回。
在這里插入圖片描述

4.4.7 apply 方法

/*** Applies a {@link SecurityConfigurerAdapter} to this {@link SecurityBuilder} and* invokes {@link SecurityConfigurerAdapter#setBuilder(SecurityBuilder)}.* @param configurer* @return the {@link SecurityConfigurerAdapter} for further customizations* @throws Exception*/
@SuppressWarnings("unchecked")
public <C extends SecurityConfigurerAdapter<O, B>> C apply(C configurer) throws Exception {configurer.addObjectPostProcessor(this.objectPostProcessor);configurer.setBuilder((B) this);add(configurer);return configurer;
}/*** Applies a {@link SecurityConfigurer} to this {@link SecurityBuilder} overriding any* {@link SecurityConfigurer} of the exact same class. Note that object hierarchies* are not considered.* @param configurer* @return the {@link SecurityConfigurerAdapter} for further customizations* @throws Exception*/
public <C extends SecurityConfigurer<O, B>> C apply(C configurer) throws Exception {add(configurer);return configurer;
}

在這里插入圖片描述

這個方法的作用是將 SecurityConfigurerAdapter (配置器的適配器)或者 SecurityConfigurer (配置器)應用到當前的構建器。這兩個方法是相互重載的,他們最后都調用了 add(configurer) 方法,將配置器添加到構建器,方便構建時使用(初始,配置)。

關于 SecurityConfigurerAdapterSecurityConfigurer 后面再詳細了解。這里觀察可以看出,他們實現了相同的接口,都可以作為add方法的參數。

而且 public <C extends SecurityConfigurerAdapter<O,B>> C apply(C configurer)throws Exception方法在6.2 版本標記為廢棄。

4.4.8 add 方法

/*** Adds {@link SecurityConfigurer} ensuring that it is allowed and invoking* {@link SecurityConfigurer#init(SecurityBuilder)} immediately if necessary.* @param configurer the {@link SecurityConfigurer} to add*/
@SuppressWarnings("unchecked")
private <C extends SecurityConfigurer<O, B>> void add(C configurer) {Assert.notNull(configurer, "configurer cannot be null");Class<? extends SecurityConfigurer<O, B>> clazz = (Class<? extends SecurityConfigurer<O, B>>) configurer.getClass();synchronized (this.configurers) {if (this.buildState.isConfigured()) {throw new IllegalStateException("Cannot apply " + configurer + " to already built object");}List<SecurityConfigurer<O, B>> configs = null;if (this.allowConfigurersOfSameType) {configs = this.configurers.get(clazz);}configs = (configs != null) ? configs : new ArrayList<>(1);configs.add(configurer);this.configurers.put(clazz, configs);if (this.buildState.isInitializing()) {this.configurersAddedInInitializing.add(configurer);}}
}

這個方法將配置器添加到一個map集合里面,這個map中以配置器的類名為 Key,以存放這個類型的配置器的 List 集合為 Value。

  • 在執(zhí)行添加操作時會對 configurers 加鎖(synchronized )。

  • 通過構造方法中設置的 allowConfigurersOfSameType 值判斷是否允許添加相同類型的配置器,如果是 true ,那么在添加之前會根據類名先從 map 中獲取該類型配置器鏈表(List),如果獲取到了就把要添加的配置器追加到后面,然后把追加了新配置器的List再放回到 map 里面,如果獲取到 null ,接創(chuàng)建一個新的 List 來存放配置器。

  • 添加配置器時,如果該構建器已經處于以配置狀態(tài)(大于等于 CONFIGURING.order ),那么會拋出異常;如果該構建器已經處于 INITIALIZING 狀態(tài),那么久將這個適配器鏈表存放到 configurersAddedInInitializing 這個map中;否則將適配器鏈表存放到 configurers 這個 map 集合中。

遺留一個問題,沒有看出來為什么要使用 configurersAddedInInitializing ,如果沒有 configurersAddedInInitializing 這個設計會出現什么并發(fā)問題嗎?

4.4.9 其他方法

在這里插入圖片描述

剩下的方法都是一些getsetremove 方法很好理解,不做多余追述。

http://www.risenshineclean.com/news/21539.html

相關文章:

  • 阿里媽媽新建網站怎么做百度客服投訴中心
  • 嘉峪關市建設局建管科網站外鏈價格
  • 查看網站有沒有備案全國疫情防控最新數據
  • 手機上做整蠱網站全網推廣軟件
  • 農產品網站開發(fā) 文獻綜述seo外包公司興田德潤官方地址
  • 網站制作技巧百度競價怎么做開戶需要多少錢
  • 找做網站的朋友抖音流量推廣神器軟件
  • 中山商城型網站建設廣州網站優(yōu)化方式
  • 海報設計分析網站seo的內容是什么
  • wordpress c博客seo實戰(zhàn)密碼第三版pdf下載
  • 有哪些網站做汽車周邊服務一句簡短走心文案
  • wordpress可以建官網嘛搜索引擎優(yōu)化排名
  • 新鄉(xiāng)網站建設百度推廣搜索排名
  • 企業(yè)起名網站怎么做搜索引擎營銷的分類
  • 河北網站建設品牌大全網站seo 工具
  • 阿里云備案個人可以做網站嗎怎么建立一個網站
  • 網站模板織夢免費西安百度推廣優(yōu)化公司
  • 公司網站建設需求書網站設計公司哪家專業(yè)
  • 網站欄目劃分怎么做制作網頁的流程
  • 用php和mysql做網站網絡推廣常見的方法
  • 做網站的技術支持網絡營銷招聘崗位有哪些
  • 手機免費建設網站制作推廣普通話宣傳海報
  • 電商網站如何提高轉化率企業(yè)品牌推廣營銷方案
  • 合肥網站建設信息搜索引擎廣告投放
  • 員工做違法網站百度數據
  • 什么是b2c網站營銷存在的問題及改進
  • 哈爾濱網站建設價格網站制作流程和方法
  • wordpress 愛范兒主題seo自學網app
  • 網站建設策劃基本流程圖yahoo搜索
  • 哪個建立網站好小程序開發(fā)