クラス WebSecurityConfigurerAdapter
- java.lang.Object
-
- org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
- 実装されたすべてのインターフェース:
SecurityConfigurer<javax.servlet.Filter,WebSecurity>
,WebSecurityConfigurer<WebSecurity>
@Order(100) public abstract class WebSecurityConfigurerAdapter extends java.lang.Object implements WebSecurityConfigurer<WebSecurity>
WebSecurityConfigurer
インスタンスを作成するための便利な基本クラスを提供します。この実装では、メソッドをオーバーライドすることでカスタマイズできます。開発者がデフォルトを継承できるように、
SpringFactoriesLoader
からAbstractHttpConfigurer
をルックアップした結果を自動的に適用します。これを行うには、AbstractHttpConfigurer を継承するクラスを作成してから、クラスパスの "META-INF/spring.factories" に次のようなファイルを作成する必要があります。org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer = sample.MyClassThatExtendsAbstractHttpConfigurer
追加する必要があるクラスが複数ある場合は、"," を使用して値を区切ることができます。例:org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer = sample.MyClassThatExtendsAbstractHttpConfigurer, sample.OtherThatExtendsAbstractHttpConfigurer
- 関連事項:
EnableWebSecurity
コンストラクターのサマリー
コンストラクター 修飾子 コンストラクター 説明 protected
WebSecurityConfigurerAdapter()
デフォルトの構成を有効にしてインスタンスを作成します。protected
WebSecurityConfigurerAdapter(boolean disableDefaults)
デフォルトの構成を有効にするかどうかを指定できるインスタンスを作成します。
メソッドのサマリー
コンストラクターの詳細
WebSecurityConfigurerAdapter
protected WebSecurityConfigurerAdapter()
デフォルトの構成を有効にしてインスタンスを作成します。
WebSecurityConfigurerAdapter
protected WebSecurityConfigurerAdapter(boolean disableDefaults)
デフォルトの構成を有効にするかどうかを指定できるインスタンスを作成します。フレームワークの実装方法をより深く理解する必要があるため、デフォルト設定を無効にすることは、より高度な使用箇所と考える必要があります。- パラメーター:
disableDefaults
- デフォルトの構成を無効にする場合は true、それ以外の場合は false
メソッドの詳細
configure
protected void configure(AuthenticationManagerBuilder auth) throws java.lang.Exception
AuthenticationManager
の取得を試みるために、authenticationManager()
のデフォルト実装で使用されます。オーバーライドする場合は、AuthenticationManagerBuilder
を使用してAuthenticationManager
を指定する必要があります。authenticationManagerBean()
メソッドを使用して、結果のAuthenticationManager
を Bean として公開できます。userDetailsServiceBean()
を使用して、AuthenticationManagerBuilder
で Bean として作成された最後に実装されたUserDetailsService
を公開できます。UserDetailsService
は、他のSecurityContextConfigurer
で使用するためにAbstractConfiguredSecurityBuilder.getSharedObject(Class)
に自動的に入力されます (つまり、RememberMeConfigurer )例: 次の構成を使用して、メモリ内認証
UserDetailsService
を公開するメモリ内認証を登録できます。@Override protected void configure(AuthenticationManagerBuilder auth) { auth // enable in memory based authentication with a user named // "user" and "admin" .inMemoryAuthentication().withUser("user").password("password").roles("USER").and() .withUser("admin").password("password").roles("USER", "ADMIN"); } // Expose the UserDetailsService as a Bean @Bean @Override public UserDetailsService userDetailsServiceBean() throws Exception { return super.userDetailsServiceBean(); }
- パラメーター:
auth
- 使用するAuthenticationManagerBuilder
- 例外:
java.lang.Exception
getHttp
protected final HttpSecurity getHttp() throws java.lang.Exception
HttpSecurity
を作成するか、現在のインスタンスを返します- 戻り値:
HttpSecurity
- 例外:
java.lang.Exception
authenticationManagerBean
public AuthenticationManager authenticationManagerBean() throws java.lang.Exception
このメソッドをオーバーライドして、configure(AuthenticationManagerBuilder)
からAuthenticationManager
を公開し、Bean として公開します。例:@Bean(name name="myAuthenticationManager") @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); }
- 戻り値:
AuthenticationManager
- 例外:
java.lang.Exception
authenticationManager
protected AuthenticationManager authenticationManager() throws java.lang.Exception
使用するAuthenticationManager
を取得します。デフォルトの戦略は、configure(AuthenticationManagerBuilder)
メソッドがオーバーライドされて、渡されたAuthenticationManagerBuilder
を使用するかどうかです。それ以外の場合は、AuthenticationManager
を型ごとにオートワイヤーします。- 戻り値:
- 使用する
AuthenticationManager
- 例外:
java.lang.Exception
userDetailsServiceBean
public UserDetailsService userDetailsServiceBean() throws java.lang.Exception
このメソッドをオーバーライドして、configure(AuthenticationManagerBuilder)
から作成されたUserDetailsService
を Bean として公開します。一般に、このメソッドでは次のオーバーライドのみを行う必要があります。@Bean(name = "myUserDetailsService") // any or no name specified is allowed @Override public UserDetailsService userDetailsServiceBean() throws Exception { return super.userDetailsServiceBean(); }
返されるインスタンスを変更するには、開発者は代わりにuserDetailsService()
を変更する必要があります- 戻り値:
UserDetailsService
- 例外:
java.lang.Exception
- 関連事項:
userDetailsService()
userDetailsService
protected UserDetailsService userDetailsService()
ApplicationContext
と対話せずに、userDetailsServiceBean()
からUserDetailsService
を変更およびアクセスできます。userDetailsServiceBean()
のインスタンスを変更する場合、開発者はこのメソッドをオーバーライドする必要があります。- 戻り値:
- 使用する
UserDetailsService
init
public void init(WebSecurity web) throws java.lang.Exception
インターフェースからコピーされた説明:SecurityConfigurer
SecurityBuilder
を初期化します。ここでは、共有状態のみを作成および変更する必要がありますが、オブジェクトの構築に使用されるSecurityBuilder
のプロパティは作成および変更しないでください。これにより、構築時にSecurityConfigurer.configure(SecurityBuilder)
メソッドが正しい共有オブジェクトを使用するようになります。ここで設定を適用する必要があります。- 次で指定:
- インターフェース
SecurityConfigurer<javax.servlet.Filter,WebSecurity>
のinit
- 例外:
java.lang.Exception
configure
public void configure(WebSecurity web) throws java.lang.Exception
このメソッドをオーバーライドして、WebSecurity
を構成します。例: 特定のリクエストを無視したい場合。このメソッドで指定されたエンドポイントは Spring Security によって無視されます。つまり、エンドポイントは CSRF、XSS、クリックジャッキングなどから保護されません。代わりに、一般的な脆弱性からエンドポイントを保護する場合は、configure(HttpSecurity)
およびHttpSecurity.authorizeRequests()
構成方法を参照してください。- 次で指定:
- インターフェース
SecurityConfigurer<javax.servlet.Filter,WebSecurity>
のconfigure
- 例外:
java.lang.Exception
configure
protected void configure(HttpSecurity http) throws java.lang.Exception
このメソッドをオーバーライドして、HttpSecurity
を構成します。通常、サブクラスは構成をオーバーライドする可能性があるため、super を呼び出してこのメソッドを呼び出すことはできません。デフォルトの構成は次のとおりです。http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().httpBasic();
公開されているものも含め、一般的な脆弱性に対する防御を必要とするエンドポイントをここで指定できます。パブリックエンドポイントの詳細については、HttpSecurity.authorizeRequests()
および `permitAll()` 認可ルールを参照してください。- パラメーター:
http
- 変更するHttpSecurity
- 例外:
java.lang.Exception
- エラーが発生した場合
getApplicationContext
protected final org.springframework.context.ApplicationContext getApplicationContext()
ApplicationContext を取得します- 戻り値:
- コンテキスト
setApplicationContext
@Autowired public void setApplicationContext(org.springframework.context.ApplicationContext context)
setTrustResolver
@Autowired(required=false) public void setTrustResolver(AuthenticationTrustResolver trustResolver)
setContentNegotationStrategy
@Autowired(required=false) public void setContentNegotationStrategy(org.springframework.web.accept.ContentNegotiationStrategy contentNegotiationStrategy)
setObjectPostProcessor
@Autowired public void setObjectPostProcessor(ObjectPostProcessor<java.lang.Object> objectPostProcessor)
setAuthenticationConfiguration
@Autowired public void setAuthenticationConfiguration(AuthenticationConfiguration authenticationConfiguration)