クラス ServerHttpSecurity
- java.lang.Object
-
- org.springframework.security.config.web.server.ServerHttpSecurity
public class ServerHttpSecurity extends java.lang.ObjectServerHttpSecurityは Spring Security のHttpSecurityに似ていますが、WebFlux 用です。特定の http リクエストに対して Web ベースのセキュリティを構成できます。デフォルトでは、すべてのリクエストに適用されますが、securityMatcher(ServerWebExchangeMatcher)または他の同様の方法を使用して制限できます。最小構成は次のとおりです。@EnableWebFluxSecurity public class MyMinimalSecurityConfiguration { @Bean public MapReactiveUserDetailsService userDetailsService() { UserDetails user = User.withDefaultPasswordEncoder() .username("user") .password("password") .roles("USER") .build(); return new MapReactiveUserDetailsService(user); } }以下は最小構成と同じですが、明示的にServerHttpSecurityを宣言しています。@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
ネストされたクラスの要約
ネストされたクラス 修飾子と型 クラス 説明 classServerHttpSecurity.AnonymousSpec匿名認証を構成しますclassServerHttpSecurity.AuthorizeExchangeSpec認可を構成しますclassServerHttpSecurity.CorsSpecSpring Security 内で CORS サポートを構成します。classServerHttpSecurity.CsrfSpecCSRF の保護を構成しますclassServerHttpSecurity.ExceptionHandlingSpec例外処理を構成しますclassServerHttpSecurity.FormLoginSpecフォームベースの認証を設定しますclassServerHttpSecurity.HeaderSpecHTTP レスポンスヘッダーを構成します。classServerHttpSecurity.HttpBasicSpecHTTP 基本認証を構成しますclassServerHttpSecurity.HttpsRedirectSpecHTTPS リダイレクトルールを構成するclassServerHttpSecurity.LogoutSpecログアウトを構成しますclassServerHttpSecurity.OAuth2ClientSpecclassServerHttpSecurity.OAuth2LoginSpecclassServerHttpSecurity.OAuth2ResourceServerSpecOAuth2 リソースサーバーサポートの構成classServerHttpSecurity.PasswordManagementSpecパスワード管理を構成します。classServerHttpSecurity.RequestCacheSpecフローが中断されたときに使用されるリクエストキャッシュを構成します(つまりclassServerHttpSecurity.X509SpecX509 認証を構成します
コンストラクターの概要
コンストラクター 修飾子 コンストラクター 説明 protectedServerHttpSecurity()
メソッドのサマリー
メソッドの詳細
securityMatcher
public ServerHttpSecurity securityMatcher(ServerWebExchangeMatcher matcher)
この HttpSecurity インスタンスに適用されるリクエストを決定する ServerExchangeMatcher。- パラメーター:
matcher- この HttpSecurity インスタンスに適用されるリクエストを決定する ServerExchangeMatcher。デフォルトはすべてのリクエストです。- 戻り値:
ServerHttpSecurityの構成を続行するには
addFilterAt
public ServerHttpSecurity addFilterAt(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order)
特定の位置にWebFilterを追加します。- パラメーター:
webFilter- 追加するWebFilterorder-WebFilterを挿入する場所- 戻り値:
ServerHttpSecurityの構成を続行するには
addFilterBefore
public ServerHttpSecurity addFilterBefore(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order)
特定の位置の前にWebFilterを追加します。- パラメーター:
webFilter- 追加するWebFilterorder-WebFilterを挿入する前の場所- 戻り値:
ServerHttpSecurityの構成を続行するには- 導入:
- 5.2.0
addFilterAfter
public ServerHttpSecurity addFilterAfter(org.springframework.web.server.WebFilter webFilter, SecurityWebFiltersOrder order)
特定の位置の後にWebFilterを追加します。- パラメーター:
webFilter- 追加するWebFilterorder-WebFilterを挿入する場所- 戻り値:
ServerHttpSecurityの構成を続行するには- 導入:
- 5.2.0
securityContextRepository
public ServerHttpSecurity securityContextRepository(ServerSecurityContextRepository securityContextRepository)
- パラメーター:
securityContextRepository- 使用するリポジトリ- 戻り値:
ServerHttpSecurityの構成を続行するには
redirectToHttps
public ServerHttpSecurity.HttpsRedirectSpec redirectToHttps()
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
public ServerHttpSecurity.CsrfSpec csrf()
デフォルトで有効になっている 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
public ServerHttpSecurity csrf(Customizer<ServerHttpSecurity.CsrfSpec> csrfCustomizer)
デフォルトで有効になっている 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
public ServerHttpSecurity.CorsSpec cors()
CORS ヘッダーを設定します。デフォルトでは、CorsConfigurationSourceBean が見つかった場合、CorsWebFilterの作成に使用されます。ServerHttpSecurity.CorsSpec.configurationSource(CorsConfigurationSource)が呼び出されると、代わりに使用されます。どちらも設定されていない場合、Cors 設定は何もしません。- 戻り値:
ServerHttpSecurity.CorsSpecをカスタマイズする
cors
public ServerHttpSecurity cors(Customizer<ServerHttpSecurity.CorsSpec> corsCustomizer)
CORS ヘッダーを設定します。デフォルトでは、CorsConfigurationSourceBean が見つかった場合、CorsWebFilterの作成に使用されます。ServerHttpSecurity.CorsSpec.configurationSource(CorsConfigurationSource)が呼び出されると、代わりに使用されます。どちらも設定されていない場合、Cors 設定は何もしません。- パラメーター:
corsCustomizer-Customizerを使用して、ServerHttpSecurity.CorsSpecにより多くのオプションを提供します。- 戻り値:
ServerHttpSecurityをカスタマイズする
anonymous
public ServerHttpSecurity.AnonymousSpec anonymous()
匿名認証を有効にして構成します。匿名認証はデフォルトで無効になっています。@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
public ServerHttpSecurity.HttpBasicSpec httpBasic()
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をカスタマイズする
passwordManagement
public ServerHttpSecurity.PasswordManagementSpec passwordManagement()
パスワード管理を構成します。構成例を以下に示します。@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
public ServerHttpSecurity.FormLoginSpec formLogin()
フォームベースの認証を設定します。以下に設定例を示します。@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
public ServerHttpSecurity.X509Spec x509()
クライアントから提供された証明書を使用して x509 認証を構成します。@Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http .x509() .authenticationManager(authenticationManager) .principalExtractor(principalExtractor); return http.build(); }抽出子が指定されていない場合は、SubjectDnX509PrincipalExtractorが使用されることに注意してください。authenticationManager が指定されていない場合は、ReactivePreAuthenticatedAuthenticationManagerが使用されます。- 戻り値:
ServerHttpSecurity.X509Specをカスタマイズする- 導入:
- 5.2
x509
public ServerHttpSecurity x509(Customizer<ServerHttpSecurity.X509Spec> x509Customizer)
クライアントから提供された証明書を使用して 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
public ServerHttpSecurity.OAuth2LoginSpec oauth2Login()
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
public ServerHttpSecurity.OAuth2ClientSpec oauth2Client()
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
public ServerHttpSecurity.OAuth2ResourceServerSpec oauth2ResourceServer()
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をカスタマイズする
headers
public 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: 1; mode=block
そのため、"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
public ServerHttpSecurity headers(Customizer<ServerHttpSecurity.HeaderSpec> headerCustomizer)
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: 1; mode=block
そのため、"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
public ServerHttpSecurity.ExceptionHandlingSpec exceptionHandling()
例外処理を構成します(つまり、認証がリクエストされたときに処理します)。以下に設定例を示します。@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
public ServerHttpSecurity.AuthorizeExchangeSpec authorizeExchange()
認可を構成します。以下に設定例を示します。@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
public ServerHttpSecurity.LogoutSpec logout()
ログアウトを構成します。以下に設定例を示します。@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
public ServerHttpSecurity logout(Customizer<ServerHttpSecurity.LogoutSpec> logoutCustomizer)
ログアウトを構成します。以下に設定例を示します。@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
public ServerHttpSecurity.RequestCacheSpec requestCache()
リクエストが認証後にリプレイできるように、フローが中断されたときに(つまり、資格情報をリクエストしたために)使用されるリクエストキャッシュを構成します。以下に設定例を示します。@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
public ServerHttpSecurity authenticationManager(ReactiveAuthenticationManager manager)
デフォルトの認証マネージャーを構成します。- パラメーター:
manager- 使用する認証マネージャー- 戻り値:
ServerHttpSecurityをカスタマイズする
build
public SecurityWebFilterChain build()
SecurityWebFilterChainを構築します
http
public static ServerHttpSecurity http()
新しいインスタンスを作成します。- 戻り値:
- 新しい
ServerHttpSecurityインスタンス
setApplicationContext
protected void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- 例外:
org.springframework.beans.BeansException