クラス ServerHttpSecurity
java.lang.ObjectSE
org.springframework.security.config.web.server.ServerHttpSecurity
ServerHttpSecurity
は Spring Security の HttpSecurity
に似ていますが、WebFlux 用です。特定の http リクエストに対して Web ベースのセキュリティを構成できます。デフォルトでは、すべてのリクエストに適用されますが、securityMatcher(ServerWebExchangeMatcher)
または他の同様の方法を使用して制限できます。最小構成は次のとおりです。@Configuration @EnableWebFluxSecurity public class MyMinimalSecurityConfiguration { @Bean public MapReactiveUserDetailsService userDetailsService() { UserDetails user = User.withDefaultPasswordEncoder() .username("user") .password("password") .roles("USER") .build(); return new MapReactiveUserDetailsService(user); } }以下は最小構成と同じですが、明示的に
ServerHttpSecurity
を宣言しています。@Configuration @EnableWebFluxSecurity public class MyExplicitSecurityConfiguration { @Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http .authorizeExchange() .anyExchange().authenticated() .and() .httpBasic().and() .formLogin(); return http.build(); } @Bean public MapReactiveUserDetailsService userDetailsService() { UserDetails user = User.withDefaultPasswordEncoder() .username("user") .password("password") .roles("USER") .build(); return new MapReactiveUserDetailsService(user); } }
- 導入:
- 5.0
ネストされたクラスのサマリー
ネストされたクラス修飾子と型クラス説明final class
匿名認証を構成しますclass
認可を構成しますfinal class
Spring Security 内で CORS サポートを構成します。final class
CSRF の保護を構成しますfinal class
例外処理を構成しますfinal class
フォームベースの認証を設定しますfinal class
HTTP レスポンスヘッダーを構成します。final class
HTTP 基本認証を構成しますclass
HTTPS リダイレクトルールを構成するfinal class
ログアウトを構成しますfinal class
final class
class
OAuth2 リソースサーバーサポートの構成final class
OIDC 1.0 ログアウトサポートを構成しますfinal class
ワンタイムトークンログインサポートを構成するfinal class
パスワード管理を構成します。final class
フローが中断されたときに使用されるリクエストキャッシュを構成します(つまりclass
セッションの管理方法を構成します。final class
X509 認証を構成しますコンストラクターの概要
コンストラクターメソッドのサマリー
修飾子と型メソッド説明addFilterAfter
(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order) 特定の位置の後にWebFilter
を追加します。addFilterAt
(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order) 特定の位置にWebFilter
を追加します。addFilterBefore
(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order) 特定の位置の前にWebFilter
を追加します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。anonymous
(Customizer<ServerHttpSecurity.AnonymousSpec> anonymousCustomizer) 匿名認証を有効にして構成します。デフォルトの認証マネージャーを構成します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。authorizeExchange
(Customizer<ServerHttpSecurity.AuthorizeExchangeSpec> authorizeExchangeCustomizer) 認可を構成します。build()
SecurityWebFilterChain
を構築しますcors()
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。cors
(Customizer<ServerHttpSecurity.CorsSpec> corsCustomizer) CORS ヘッダーを設定します。csrf()
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。csrf
(Customizer<ServerHttpSecurity.CsrfSpec> csrfCustomizer) デフォルトで有効になっている CSRF の保護を設定します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。exceptionHandling
(Customizer<ServerHttpSecurity.ExceptionHandlingSpec> exceptionHandlingCustomizer) 例外処理を構成します(つまり非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。formLogin
(Customizer<ServerHttpSecurity.FormLoginSpec> formLoginCustomizer) フォームベースの認証を設定します。headers()
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。headers
(Customizer<ServerHttpSecurity.HeaderSpec> headerCustomizer) HTTP レスポンスヘッダーを構成します。static ServerHttpSecurity
http()
新しいインスタンスを作成します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。httpBasic
(Customizer<ServerHttpSecurity.HttpBasicSpec> httpBasicCustomizer) HTTP 基本認証を構成します。logout()
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。logout
(Customizer<ServerHttpSecurity.LogoutSpec> logoutCustomizer) ログアウトを構成します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。oauth2Client
(Customizer<ServerHttpSecurity.OAuth2ClientSpec> oauth2ClientCustomizer) OAuth2 クライアントを構成します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。oauth2Login
(Customizer<ServerHttpSecurity.OAuth2LoginSpec> oauth2LoginCustomizer) OAuth 2.0 または OpenID Connect 1.0 プロバイダーを使用して認証サポートを構成します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。oauth2ResourceServer
(Customizer<ServerHttpSecurity.OAuth2ResourceServerSpec> oauth2ResourceServerCustomizer) OAuth 2.0 リソースサーバーのサポートを構成します。oidcLogout
(Customizer<ServerHttpSecurity.OidcLogoutSpec> oidcLogoutCustomizer) OIDC Connect 1.0 ログアウトサポートを構成します。oneTimeTokenLogin
(Customizer<ServerHttpSecurity.OneTimeTokenLoginSpec> oneTimeTokenLoginCustomizer) ワンタイムトークンログインサポートを構成します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。passwordManagement
(Customizer<ServerHttpSecurity.PasswordManagementSpec> passwordManagementCustomizer) パスワード管理を構成します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。redirectToHttps
(Customizer<ServerHttpSecurity.HttpsRedirectSpec> httpsRedirectCustomizer) HTTPS リダイレクトルールを設定します。非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。requestCache
(Customizer<ServerHttpSecurity.RequestCacheSpec> requestCacheCustomizer) フローが中断されたときに使用されるリクエストキャッシュを構成します(つまりsecurityContextRepository
(ServerSecurityContextRepository securityContextRepository) ReactorContextWebFilter
で使用される戦略。securityMatcher
(ServerWebExchangeMatcher matcher) この HttpSecurity インスタンスに適用されるリクエストを決定する ServerExchangeMatcher。セッション管理を設定します。protected void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) x509()
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。x509
(Customizer<ServerHttpSecurity.X509Spec> x509Customizer) クライアントから提供された証明書を使用して x509 認証を構成します。
コンストラクターの詳細
ServerHttpSecurity
protected ServerHttpSecurity()
メソッドの詳細
securityMatcher
この HttpSecurity インスタンスに適用されるリクエストを決定する ServerExchangeMatcher。- パラメーター:
matcher
- この HttpSecurity インスタンスに適用されるリクエストを決定する ServerExchangeMatcher。デフォルトはすべてのリクエストです。- 戻り値:
ServerHttpSecurity
の構成を続行するには
addFilterAt
public ServerHttpSecurity addFilterAt(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order) 特定の位置にWebFilter
を追加します。- パラメーター:
webFilter
- 追加するWebFilter
order
-WebFilter
を挿入する場所- 戻り値:
ServerHttpSecurity
の構成を続行するには
addFilterBefore
public ServerHttpSecurity addFilterBefore(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order) 特定の位置の前にWebFilter
を追加します。- パラメーター:
webFilter
- 追加するWebFilter
order
-WebFilter
を挿入する前の場所- 戻り値:
ServerHttpSecurity
の構成を続行するには- 導入:
- 5.2.0
addFilterAfter
public ServerHttpSecurity addFilterAfter(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order) 特定の位置の後にWebFilter
を追加します。- パラメーター:
webFilter
- 追加するWebFilter
order
-WebFilter
を挿入する場所- 戻り値:
ServerHttpSecurity
の構成を続行するには- 導入:
- 5.2.0
securityContextRepository
public ServerHttpSecurity securityContextRepository(ServerSecurityContextRepository securityContextRepository) - パラメーター:
securityContextRepository
- 使用するリポジトリ- 戻り値:
ServerHttpSecurity
の構成を続行するには
redirectToHttps
@DeprecatedSE(since="6.1", forRemoval=true) public ServerHttpSecurity.HttpsRedirectSpec redirectToHttps()非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、redirectToHttps(Customizer)
またはredirectToHttps(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。HTTPS リダイレクトルールを設定します。デフォルトが使用される場合:@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .redirectToHttps(); return http.build(); }
その後、すべての非 HTTPS リクエストが HTTPS にリダイレクトされます。通常、すべてのリクエストは HTTPS である必要があります。ただし、リダイレクトの焦点を絞ることもできます。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .redirectToHttps() .httpsRedirectWhen((serverWebExchange) -> serverWebExchange.getRequest().getHeaders().containsKey("X-Requires-Https")) return http.build(); }
- 戻り値:
ServerHttpSecurity.HttpsRedirectSpec
をカスタマイズする
redirectToHttps
public ServerHttpSecurity redirectToHttps(Customizer<ServerHttpSecurity.HttpsRedirectSpec> httpsRedirectCustomizer) HTTPS リダイレクトルールを設定します。デフォルトが使用される場合:@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .redirectToHttps(withDefaults()); return http.build(); }
その後、すべての非 HTTPS リクエストが HTTPS にリダイレクトされます。通常、すべてのリクエストは HTTPS である必要があります。ただし、リダイレクトの焦点を絞ることもできます。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .redirectToHttps((redirectToHttps) -> redirectToHttps .httpsRedirectWhen((serverWebExchange) -> serverWebExchange.getRequest().getHeaders().containsKey("X-Requires-Https")) ); return http.build(); }
- パラメーター:
httpsRedirectCustomizer
-Customizer
を使用して、ServerHttpSecurity.HttpsRedirectSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
csrf
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、csrf(Customizer)
またはcsrf(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。デフォルトで有効になっている CSRF の保護を設定します。次を使用して無効にできます。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .csrf().disabled(); return http.build(); }
追加の構成オプションは以下のとおりです。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .csrf() // Handle CSRF failures .accessDeniedHandler(accessDeniedHandler) // Custom persistence of CSRF Token .csrfTokenRepository(csrfTokenRepository) // custom matching when CSRF protection is enabled .requireCsrfProtectionMatcher(matcher); return http.build(); }
- 戻り値:
ServerHttpSecurity.CsrfSpec
をカスタマイズする
csrf
デフォルトで有効になっている CSRF の保護を設定します。次を使用して無効にできます。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .csrf((csrf) -> csrf.disabled() ); return http.build(); }
追加の構成オプションは以下のとおりです。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .csrf((csrf) -> csrf // Handle CSRF failures .accessDeniedHandler(accessDeniedHandler) // Custom persistence of CSRF Token .csrfTokenRepository(csrfTokenRepository) // custom matching when CSRF protection is enabled .requireCsrfProtectionMatcher(matcher) ); return http.build(); }
- パラメーター:
csrfCustomizer
-Customizer
を使用して、ServerHttpSecurity.CsrfSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
cors
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、cors(Customizer)
またはcors(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。CORS ヘッダーを設定します。デフォルトでは、CorsConfigurationSource
Bean が見つかった場合、CorsWebFilter
の作成に使用されます。ServerHttpSecurity.CorsSpec.configurationSource(CorsConfigurationSource)
が呼び出されると、代わりに使用されます。どちらも設定されていない場合、Cors 設定は何もしません。- 戻り値:
ServerHttpSecurity.CorsSpec
をカスタマイズする
cors
CORS ヘッダーを設定します。デフォルトでは、CorsConfigurationSource
Bean が見つかった場合、CorsWebFilter
の作成に使用されます。ServerHttpSecurity.CorsSpec.configurationSource(CorsConfigurationSource)
が呼び出されると、代わりに使用されます。どちらも設定されていない場合、Cors 設定は何もしません。- パラメーター:
corsCustomizer
-Customizer
を使用して、ServerHttpSecurity.CorsSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
anonymous
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、anonymous(Customizer)
またはanonymous(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。匿名認証を有効にして構成します。匿名認証はデフォルトで無効になっています。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .anonymous().key("key") .authorities("ROLE_ANONYMOUS"); return http.build(); }
- 戻り値:
ServerHttpSecurity.AnonymousSpec
をカスタマイズする- 導入:
- 5.2.0
anonymous
public ServerHttpSecurity anonymous(Customizer<ServerHttpSecurity.AnonymousSpec> anonymousCustomizer) 匿名認証を有効にして構成します。匿名認証はデフォルトで無効になっています。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .anonymous((anonymous) -> anonymous .key("key") .authorities("ROLE_ANONYMOUS") ); return http.build(); }
- パラメーター:
anonymousCustomizer
-Customizer
を使用して、ServerHttpSecurity.AnonymousSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
httpBasic
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、httpBasic(Customizer)
またはhttpBasic(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。HTTP 基本認証を構成します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .httpBasic() // used for authenticating the credentials .authenticationManager(authenticationManager) // Custom persistence of the authentication .securityContextRepository(securityContextRepository); return http.build(); }
- 戻り値:
ServerHttpSecurity.HttpBasicSpec
をカスタマイズする
httpBasic
public ServerHttpSecurity httpBasic(Customizer<ServerHttpSecurity.HttpBasicSpec> httpBasicCustomizer) HTTP 基本認証を構成します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .httpBasic((httpBasic) -> httpBasic // used for authenticating the credentials .authenticationManager(authenticationManager) // Custom persistence of the authentication .securityContextRepository(securityContextRepository) ); return http.build(); }
- パラメーター:
httpBasicCustomizer
-Customizer
を使用して、ServerHttpSecurity.HttpBasicSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
sessionManagement
public ServerHttpSecurity sessionManagement(Customizer<ServerHttpSecurity.SessionManagementSpec> customizer) セッション管理を設定します。構成例を以下に示します。@Bean SecurityWebFilterChain filterChain(ServerHttpSecurity http, ReactiveSessionRegistry sessionRegistry) { http // ... .sessionManagement((sessionManagement) -> sessionManagement .concurrentSessions((concurrentSessions) -> concurrentSessions .maxSessions(1) .maxSessionsPreventsLogin(true) .sessionRegistry(sessionRegistry) ) ); return http.build(); }
- パラメーター:
customizer
-Customizer
を使用して、ServerHttpSecurity.SessionManagementSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
の構成を続行するには- 導入:
- 6.3
passwordManagement
@DeprecatedSE(since="6.1", forRemoval=true) public ServerHttpSecurity.PasswordManagementSpec passwordManagement()非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、passwordManagement(Customizer)
またはpasswordManagement(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。パスワード管理を構成します。構成例を以下に示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .passwordManagement(); return http.build(); }
- 戻り値:
ServerHttpSecurity.PasswordManagementSpec
をカスタマイズする- 導入:
- 5.6
passwordManagement
public ServerHttpSecurity passwordManagement(Customizer<ServerHttpSecurity.PasswordManagementSpec> passwordManagementCustomizer) パスワード管理を構成します。構成例を以下に示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .passwordManagement(passwordManagement -> // Custom change password page. passwordManagement.changePasswordPage("/custom-change-password-page") ); return http.build(); }
- パラメーター:
passwordManagementCustomizer
-Customizer
を使用して、ServerHttpSecurity.PasswordManagementSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする- 導入:
- 5.6
formLogin
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、formLogin(Customizer)
またはformLogin(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。フォームベースの認証を設定します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .formLogin() // used for authenticating the credentials .authenticationManager(authenticationManager) // Custom persistence of the authentication .securityContextRepository(securityContextRepository) // expect a log in page at "/authenticate" // a POST "/authenticate" is where authentication occurs // error page at "/authenticate?error" .loginPage("/authenticate"); return http.build(); }
- 戻り値:
ServerHttpSecurity.FormLoginSpec
をカスタマイズする
formLogin
public ServerHttpSecurity formLogin(Customizer<ServerHttpSecurity.FormLoginSpec> formLoginCustomizer) フォームベースの認証を設定します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .formLogin((formLogin) -> formLogin // used for authenticating the credentials .authenticationManager(authenticationManager) // Custom persistence of the authentication .securityContextRepository(securityContextRepository) // expect a log in page at "/authenticate" // a POST "/authenticate" is where authentication occurs // error page at "/authenticate?error" .loginPage("/authenticate") ); return http.build(); }
- パラメーター:
formLoginCustomizer
-Customizer
を使用して、ServerHttpSecurity.FormLoginSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
x509
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、x509(Customizer)
またはx509(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。クライアントから提供された証明書を使用して x509 認証を構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http .x509() .authenticationManager(authenticationManager) .principalExtractor(principalExtractor); return http.build(); }
抽出子が指定されていない場合は、SubjectDnX509PrincipalExtractor
が使用されることに注意してください。authenticationManager が指定されていない場合は、ReactivePreAuthenticatedAuthenticationManager
が使用されます。- 戻り値:
ServerHttpSecurity.X509Spec
をカスタマイズする- 導入:
- 5.2
x509
クライアントから提供された証明書を使用して x509 認証を構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http .x509((x509) -> x509 .authenticationManager(authenticationManager) .principalExtractor(principalExtractor) ); return http.build(); }
抽出子が指定されていない場合は、SubjectDnX509PrincipalExtractor
が使用されることに注意してください。authenticationManager が指定されていない場合は、ReactivePreAuthenticatedAuthenticationManager
が使用されます。- パラメーター:
x509Customizer
-Customizer
を使用して、ServerHttpSecurity.X509Spec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする- 導入:
- 5.2
oauth2Login
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、oauth2Login(Customizer)
またはoauth2Login(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。OAuth 2.0 または OpenID Connect 1.0 プロバイダーを使用して認証サポートを構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .oauth2Login() .authenticationConverter(authenticationConverter) .authenticationManager(manager); return http.build(); }
- 戻り値:
ServerHttpSecurity.OAuth2LoginSpec
をカスタマイズする
oauth2Login
public ServerHttpSecurity oauth2Login(Customizer<ServerHttpSecurity.OAuth2LoginSpec> oauth2LoginCustomizer) OAuth 2.0 または OpenID Connect 1.0 プロバイダーを使用して認証サポートを構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .oauth2Login((oauth2Login) -> oauth2Login .authenticationConverter(authenticationConverter) .authenticationManager(manager) ); return http.build(); }
- パラメーター:
oauth2LoginCustomizer
-Customizer
を使用して、ServerHttpSecurity.OAuth2LoginSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
oauth2Client
@DeprecatedSE(since="6.1", forRemoval=true) public ServerHttpSecurity.OAuth2ClientSpec oauth2Client()非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、oauth2Client(Customizer)
またはoauth2Client(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。OAuth2 クライアントを構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .oauth2Client() .clientRegistrationRepository(clientRegistrationRepository) .authorizedClientRepository(authorizedClientRepository); return http.build(); }
- 戻り値:
ServerHttpSecurity.OAuth2ClientSpec
をカスタマイズする
oauth2Client
public ServerHttpSecurity oauth2Client(Customizer<ServerHttpSecurity.OAuth2ClientSpec> oauth2ClientCustomizer) OAuth2 クライアントを構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .oauth2Client((oauth2Client) -> oauth2Client .clientRegistrationRepository(clientRegistrationRepository) .authorizedClientRepository(authorizedClientRepository) ); return http.build(); }
- パラメーター:
oauth2ClientCustomizer
-Customizer
を使用して、ServerHttpSecurity.OAuth2ClientSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
oauth2ResourceServer
@DeprecatedSE(since="6.1", forRemoval=true) public ServerHttpSecurity.OAuth2ResourceServerSpec oauth2ResourceServer()非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。代わりにoauth2ResourceServer(Customizer)
を使用してくださいOAuth 2.0 リソースサーバーのサポートを構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .oauth2ResourceServer() .jwt() .publicKey(publicKey()); return http.build(); }
- 戻り値:
ServerHttpSecurity.OAuth2ResourceServerSpec
をカスタマイズする
oauth2ResourceServer
public ServerHttpSecurity oauth2ResourceServer(Customizer<ServerHttpSecurity.OAuth2ResourceServerSpec> oauth2ResourceServerCustomizer) OAuth 2.0 リソースサーバーのサポートを構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .oauth2ResourceServer((oauth2ResourceServer) -> oauth2ResourceServer .jwt((jwt) -> jwt .publicKey(publicKey()) ) ); return http.build(); }
- パラメーター:
oauth2ResourceServerCustomizer
-Customizer
を使用して、ServerHttpSecurity.OAuth2ResourceServerSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
oidcLogout
public ServerHttpSecurity oidcLogout(Customizer<ServerHttpSecurity.OidcLogoutSpec> oidcLogoutCustomizer) OIDC Connect 1.0 ログアウトサポートを構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .oidcLogout((logout) -> logout .backChannel(Customizer.withDefaults()) ); return http.build(); }
- パラメーター:
oidcLogoutCustomizer
-Customizer
を使用して、ServerHttpSecurity.OidcLogoutSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする- 導入:
- 6.2
headers
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、headers(Customizer)
またはheaders(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。HTTP レスポンスヘッダーを構成します。デフォルトのヘッダーは次のとおりです。Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff Strict-Transport-Security: max-age=31536000 ; includeSubDomains X-Frame-Options: DENY X-XSS-Protection: 0
そのため、"Strict-Transport-Security" は安全なリクエストにのみ追加されます。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .headers() // customize frame options to be same origin .frameOptions() .mode(XFrameOptionsServerHttpHeadersWriter.Mode.SAMEORIGIN) .and() // disable cache control .cache().disable(); return http.build(); }
- 戻り値:
ServerHttpSecurity.HeaderSpec
をカスタマイズする
headers
HTTP レスポンスヘッダーを構成します。デフォルトのヘッダーは次のとおりです。Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff Strict-Transport-Security: max-age=31536000 ; includeSubDomains X-Frame-Options: DENY X-XSS-Protection: 0
そのため、"Strict-Transport-Security" は安全なリクエストにのみ追加されます。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .headers((headers) -> headers // customize frame options to be same origin .frameOptions((frameOptions) -> frameOptions .mode(XFrameOptionsServerHttpHeadersWriter.Mode.SAMEORIGIN) ) // disable cache control .cache((cache) -> cache .disable() ) ); return http.build(); }
- パラメーター:
headerCustomizer
-Customizer
を使用して、ServerHttpSecurity.HeaderSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
exceptionHandling
@DeprecatedSE(since="6.1", forRemoval=true) public ServerHttpSecurity.ExceptionHandlingSpec exceptionHandling()非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、exceptionHandling(Customizer)
またはexceptionHandling(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。例外処理を構成します(つまり、認証がリクエストされたときに処理します)。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .exceptionHandling() // customize how to request for authentication .authenticationEntryPoint(entryPoint); return http.build(); }
- 戻り値:
ServerHttpSecurity.ExceptionHandlingSpec
をカスタマイズする
exceptionHandling
public ServerHttpSecurity exceptionHandling(Customizer<ServerHttpSecurity.ExceptionHandlingSpec> exceptionHandlingCustomizer) 例外処理を構成します(つまり、認証がリクエストされたときに処理します)。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .exceptionHandling((exceptionHandling) -> exceptionHandling // customize how to request for authentication .authenticationEntryPoint(entryPoint) ); return http.build(); }
- パラメーター:
exceptionHandlingCustomizer
-Customizer
を使用して、ServerHttpSecurity.ExceptionHandlingSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
authorizeExchange
@DeprecatedSE(since="6.1", forRemoval=true) public ServerHttpSecurity.AuthorizeExchangeSpec authorizeExchange()非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、authorizeExchange(Customizer)
またはauthorizeExchange(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。認可を構成します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .authorizeExchange() // any URL that starts with /admin/ requires the role "ROLE_ADMIN" .pathMatchers("/admin/**").hasRole("ADMIN") // a POST to /users requires the role "USER_POST" .pathMatchers(HttpMethod.POST, "/users").hasAuthority("USER_POST") // a request to /users/{username} requires the current authentication's username // to be equal to the {username} .pathMatchers("/users/{username}").access((authentication, context) -> authentication .map(Authentication::getName) .map((username) -> username.equals(context.getVariables().get("username"))) .map(AuthorizationDecision::new) ) // allows providing a custom matching strategy that requires the role "ROLE_CUSTOM" .matchers(customMatcher).hasRole("CUSTOM") // any other request requires the user to be authenticated .anyExchange().authenticated(); return http.build(); }
- 戻り値:
ServerHttpSecurity.AuthorizeExchangeSpec
をカスタマイズする
authorizeExchange
public ServerHttpSecurity authorizeExchange(Customizer<ServerHttpSecurity.AuthorizeExchangeSpec> authorizeExchangeCustomizer) 認可を構成します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .authorizeExchange((exchanges) -> exchanges // any URL that starts with /admin/ requires the role "ROLE_ADMIN" .pathMatchers("/admin/**").hasRole("ADMIN") // a POST to /users requires the role "USER_POST" .pathMatchers(HttpMethod.POST, "/users").hasAuthority("USER_POST") // a request to /users/{username} requires the current authentication's username // to be equal to the {username} .pathMatchers("/users/{username}").access((authentication, context) -> authentication .map(Authentication::getName) .map((username) -> username.equals(context.getVariables().get("username"))) .map(AuthorizationDecision::new) ) // allows providing a custom matching strategy that requires the role "ROLE_CUSTOM" .matchers(customMatcher).hasRole("CUSTOM") // any other request requires the user to be authenticated .anyExchange().authenticated() ); return http.build(); }
- パラメーター:
authorizeExchangeCustomizer
-Customizer
を使用して、ServerHttpSecurity.AuthorizeExchangeSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
logout
非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、logout(Customizer)
またはlogout(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。ログアウトを構成します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .logout() // configures how log out is done .logoutHandler(logoutHandler) // log out will be performed on POST /signout .logoutUrl("/signout") // configure what is done on logout success .logoutSuccessHandler(successHandler); return http.build(); }
- 戻り値:
ServerHttpSecurity.LogoutSpec
をカスタマイズする
logout
ログアウトを構成します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .logout((logout) -> logout // configures how log out is done .logoutHandler(logoutHandler) // log out will be performed on POST /signout .logoutUrl("/signout") // configure what is done on logout success .logoutSuccessHandler(successHandler) ); return http.build(); }
- パラメーター:
logoutCustomizer
-Customizer
を使用して、ServerHttpSecurity.LogoutSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
requestCache
@DeprecatedSE(since="6.1", forRemoval=true) public ServerHttpSecurity.RequestCacheSpec requestCache()非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。7.0 の取り外し用。デフォルトをそのまま使用するには、requestCache(Customizer)
またはrequestCache(Customizer.withDefaults())
を使用します。詳細については、ドキュメントを参照してください。リクエストが認証後にリプレイできるように、フローが中断されたときに(つまり、資格情報をリクエストしたために)使用されるリクエストキャッシュを構成します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .requestCache() // configures how the request is cached .requestCache(requestCache); return http.build(); }
- 戻り値:
ServerHttpSecurity.RequestCacheSpec
をカスタマイズする
requestCache
public ServerHttpSecurity requestCache(Customizer<ServerHttpSecurity.RequestCacheSpec> requestCacheCustomizer) リクエストが認証後にリプレイできるように、フローが中断されたときに(つまり、資格情報をリクエストしたために)使用されるリクエストキャッシュを構成します。以下に設定例を示します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http // ... .requestCache((requestCache) -> requestCache // configures how the request is cached .requestCache(customRequestCache) ); return http.build(); }
- パラメーター:
requestCacheCustomizer
-Customizer
を使用して、ServerHttpSecurity.RequestCacheSpec
により多くのオプションを提供します。- 戻り値:
ServerHttpSecurity
をカスタマイズする
authenticationManager
デフォルトの認証マネージャーを構成します。- パラメーター:
manager
- 使用する認証マネージャー- 戻り値:
ServerHttpSecurity
をカスタマイズする
oneTimeTokenLogin
public ServerHttpSecurity oneTimeTokenLogin(Customizer<ServerHttpSecurity.OneTimeTokenLoginSpec> oneTimeTokenLoginCustomizer) ワンタイムトークンログインサポートを構成します。構成例
@Configuration @EnableWebFluxSecurity public class SecurityConfig { @Bean public SecurityWebFilterChain securityFilterChain(ServerHttpSecurity http) throws Exception { http // ... .oneTimeTokenLogin(Customizer.withDefaults()); return http.build(); } @Bean public ServerOneTimeTokenGenerationSuccessHandler oneTimeTokenGenerationSuccessHandler() { return new MyMagicLinkServerOneTimeTokenGenerationSuccessHandler(); } }
- パラメーター:
oneTimeTokenLoginCustomizer
-Customizer
を使用して、ServerHttpSecurity.OneTimeTokenLoginSpec
により多くのオプションを提供します。- 戻り値:
- さらにカスタマイズするための
ServerHttpSecurity
build
SecurityWebFilterChain
を構築しますhttp
新しいインスタンスを作成します。- 戻り値:
- 新しい
ServerHttpSecurity
インスタンス
setApplicationContext
protected void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - 例外:
org.springframework.beans.BeansException