Spring Security Config : 概念模型接口 SecurityConfigurer

SecurityConfigurerSpring Security Config对安全配置器的概念建模接口,该接口约定了Spring Security Config的各种安全配置器实现类的统一行为:

  1. 调用方法#init初始化安全构建器;
  2. 调用方法#configure配置安全构建器;

这是一个泛型接口,泛型参数O来表示所要配置的安全构建器SecurityBuilder要构建的目标对象类型(O可以理解成是Output的缩写)。泛型参数B表示当前安全配置器所要初始化和配置的安全构建器类型(B可以理解成是Builder的缩写)。

一个SecurityBuilder上可以应用多个SecurityConfigurer。如果一个SecurityBuilder上要应用多个SecurityConfigurer,所有的SecurityConfigurer#init方法的调用需要早于任何一个SecurityConfigurer#configure方法的调用。关于这一定义,在Spring Security Config关于SecurityBuilder的抽象实现类AbstractConfiguredSecurityBuilder中可以看到。

源代码

源代码版本 : Spring Security Config 5.1.4.RELEASE

package org.springframework.security.config.annotation;

/**
 * Allows for configuring a SecurityBuilder. All SecurityConfigurer first
 * have their #init(SecurityBuilder) method invoked. After all
 * #init(SecurityBuilder) methods have been invoked, each
 * #configure(SecurityBuilder) method is invoked.
 *
 * @see AbstractConfiguredSecurityBuilder
 *
 * @author Rob Winch
 *
 * @param  The object being built by the SecurityBuilder B
 * @param  The SecurityBuilder that builds objects of type O. This is also the
 * SecurityBuilder that is being configured.
 */
public interface SecurityConfigurer<O, B extends SecurityBuilder<O>> {
	/**
	 * Initialize the SecurityBuilder. Here only shared state should be created
	 * and modified, but not properties on the SecurityBuilder used for building
	 * the object. This ensures that the #configure(SecurityBuilder) method uses
	 * the correct shared objects when building.
	 *
	 * @param builder
	 * @throws Exception
	 */
	void init(B builder) throws Exception;

	/**
	 * Configure the SecurityBuilder by setting the necessary properties on the
	 * SecurityBuilder.
	 *
	 * @param builder
	 * @throws Exception
	 */
	void configure(B builder) throws Exception;
}

你可能感兴趣的:(Spring,Security,分析)