对于最新的稳定版本,请使用 Spring Security 6.5.0! |
Web 应用程序安全
<debug>
启用 Spring Security 调试基础结构。 这将提供人类可读的 (多行) 调试信息,以监控进入安全过滤器的请求。 这可能包括敏感信息,例如请求参数或标头,并且只能在开发环境中使用。
<http>
如果您使用<http>
元素中,一个FilterChainProxy
创建名为“springSecurityFilterChain”的 Bean,并使用元素中的配置在FilterChainProxy
.
从 Spring Security 3.1 开始,额外的http
元素可用于添加额外的过滤器链[1]有关如何从web.xml
].
一些核心过滤器始终在过滤器链中创建,而其他过滤器将根据存在的属性和子元素添加到堆栈中。
标准过滤器的位置是固定的(参见命名空间介绍中的过滤器顺序表),当用户必须在FilterChainProxy
豆。
当然,如果您需要完全控制配置,您仍然可以执行此作。
所有需要引用AuthenticationManager
将自动注入 namespace 配置创建的内部实例。
每<http>
namespace 块总是创建一个SecurityContextPersistenceFilter
一ExceptionTranslationFilter
以及FilterSecurityInterceptor
.
这些是固定的,不能用替代品代替。
<http> 属性
的<http>
元素控制核心过滤器上的一些属性。
-
访问决策管理器引用Optional 属性,用于指定
AccessDecisionManager
实现,该实现应用于授权 HTTP 请求。 默认情况下,一个AffirmativeBased
implementation 用于RoleVoter
以及一个AuthenticatedVoter
.
-
身份验证管理器引用对
AuthenticationManager
用于FilterChain
由此 HTTP 元素创建。
-
观察注册表引用对
ObservationRegistry
用于FilterChain
和相关组件
-
自动配置自动注册登录表单、BASIC 认证、注销服务。 如果设置为 “true”,则添加所有这些功能(尽管您仍然可以通过提供相应的元素来自定义每个功能的配置)。 如果未指定,则默认为 “false”。 不建议使用此属性。 请改用显式配置元素以避免混淆。
-
创建会话控制 Spring Security 类创建 HTTP 会话的急切程度。 选项包括:
-
always
- 如果不存在会话,Spring Security 将主动创建一个会话。 -
ifRequired
- Spring Security 将仅在需要会话时才创建会话(默认值)。 -
never
- Spring Security 永远不会创建会话,但如果应用程序创建会话,则会使用会话。 -
stateless
- Spring Security 不会创建会话并忽略该会话以获取 SpringAuthentication
.
-
-
disable-url-rewriting (禁用 url 重写)防止将会话 ID 附加到应用程序中的 URL。 如果此属性设置为
true
. 默认值为true
.
-
入口点引用通常
AuthenticationEntryPoint
used 将根据已配置的身份验证机制进行设置。 此属性允许通过定义自定义的AuthenticationEntryPoint
bean,它将启动身份验证过程。
-
jaas-api 配置如果可用,则以
Subject
收购自JaasAuthenticationToken
这是通过添加JaasApiIntegrationFilter
bean 添加到堆栈中。 默认为false
.
-
名称Bean 标识符,用于在上下文中的其他位置引用 Bean。
-
每次请求一次对应于
observeOncePerRequest
的属性FilterSecurityInterceptor
. 默认为false
.
-
filter-all-dispatcher-types对应于
shouldFilterAllDispatcherTypes
属性的AuthorizationFilter
.在以下情况下不起作用use-authorization-manager=false
. 默认为true
.
-
模式为 http 元素定义模式可控制请求,这些请求将通过它定义的过滤器列表进行过滤。 解释取决于配置的 request-matcher。 如果未定义模式,则将匹配所有请求,因此应首先声明最具体的模式。
-
领域设置用于基本身份验证的领域名称(如果启用)。 对应于
realmName
属性BasicAuthenticationEntryPoint
.
-
请求匹配器定义
RequestMatcher
策略FilterChainProxy
以及由intercept-url
匹配传入请求。 选项当前为mvc
,ant
,regex
和ciRegex
,对于 Spring MVC,分别为 ant、regular-expression 和 event-insensitive regular-expression。 使用其 pattern、method 和 servlet-path 属性为每个 intercept-url 元素创建一个单独的实例。 Ant 路径使用AntPathRequestMatcher
,则使用RegexRequestMatcher
对于 Spring MVC 路径,匹配MvcRequestMatcher
被使用。 有关如何执行匹配的更多详细信息,请参阅这些类的 Javadoc。 如果 Classpath 中存在 Spring MVC,则 MVC 是默认策略,如果没有,则使用 Ant 路径。
-
请求匹配器引用对实现
RequestMatcher
这将确定此FilterChain
应该使用。 这是 pattern 的更强大的替代方案。
-
安全请求模式可以映射到空的过滤器链,方法是将此属性设置为
none
. 不会应用任何安全性,并且 Spring Security 的任何功能都不可用。
-
security-context-repository-ref 的允许注入自定义
SecurityContextHolderStrategy
到SecurityContextPersistenceFilter
,SecurityContextHolderFilter
,BasicAuthenticationFilter
,UsernamePasswordAuthenticationFilter
,ExceptionTranslationFilter
,LogoutFilter
等。
-
安全上下文显式保存如果为 true,则使用
SecurityContextHolderFilter
而不是SecurityContextPersistenceFilter
. 需要显式保存
-
security-context-repository-ref 的允许注入自定义
SecurityContextRepository
到SecurityContextPersistenceFilter
.
-
servlet api-provision提供
HttpServletRequest
安全方法,例如isUserInRole()
和getPrincipal()
这些 API 是通过添加SecurityContextHolderAwareRequestFilter
bean 添加到堆栈中。 默认为true
.
-
使用表达式在
access
属性,如基于表达式的访问控制一章中所述。 默认值为 true。
<access-denied-handler>
此元素允许您设置errorPage
属性为默认值AccessDeniedHandler
由ExceptionTranslationFilter
、使用 error-page 属性,或者使用 ref 属性提供您自己的实现。
这在 ExceptionTranslationFilter 一节中有更详细的讨论。
<cors>
此元素允许配置CorsFilter
.
如果没有CorsFilter
或CorsConfigurationSource
,并且 Spring MVC 位于类路径上,则HandlerMappingIntrospector
用作CorsConfigurationSource
.
<cors> 属性
的<cors>
元素控制 headers 元素。
-
裁判指定 Bean 名称的 Optional 属性
CorsFilter
.
-
cors-configuration-source-ref指定 Bean 名称的 Optional 属性
CorsConfigurationSource
注入到CorsFilter
由 XML 命名空间创建。
<headers>
此元素允许配置要与响应一起发送的其他 (安全) 标头。 它可以轻松配置多个标头,还允许通过 header 元素设置自定义标头。 其他信息,可以在参考的 Security Headers 部分找到。
-
Cache-Control
,Pragma
和Expires
- 可以使用 cache-control 元素进行设置。 这可确保浏览器不会缓存受保护的页面。 -
Strict-Transport-Security
- 可以使用 hsts 元素进行设置。 这可确保浏览器自动请求 HTTPS 以用于将来的请求。 -
X-Frame-Options
- 可以使用 frame-options 元素进行设置。 X-Frame-Options 标头可用于防止点击劫持攻击。 -
X-XSS-Protection
- 可以使用 xss-protection 元素进行设置。 浏览器可以使用 X-XSS-Protection 标头进行基本控制。 -
X-Content-Type-Options
- 可以使用 content-type-options 元素进行设置。 X-Content-Type-Options 标头可防止 Internet Explorer 对远离声明的 content-type 的响应进行 MIME 探查。 这也适用于 Google Chrome 下载扩展程序时。 -
Public-Key-Pinning
或Public-Key-Pinning-Report-Only
- 可以使用 hpkp 元素进行设置。 这允许 HTTPS 网站抵御攻击者使用错误颁发或其他欺诈性证书的假冒。 -
Content-Security-Policy
或Content-Security-Policy-Report-Only
- 可以使用 content-security-policy 元素进行设置。内容安全策略 (CSP) 是 Web 应用程序可以用来缓解内容注入漏洞的一种机制,例如跨站点脚本 (XSS)。 -
Referrer-Policy
- 可以使用 referrer-policy 元素进行设置,Referrer-Policy 是 Web 应用程序可以用来管理 referrer 字段的一种机制,该字段包含用户所在的最后一个页面。 -
Feature-Policy
- 可以使用 feature-policy 元素进行设置,Feature-Policy 是一种机制,允许 Web 开发人员有选择地启用、禁用和修改浏览器中某些 API 和 Web 功能的行为。 -
Cross-Origin-Opener-Policy
- 可以使用 cross-origin-opener-policy 元素进行设置,Cross-Origin-Opener-Policy 是一种机制,允许您确保顶级文档不会与跨源文档共享浏览上下文组。 -
Cross-Origin-Embedder-Policy
- 可以使用 cross-origin-embedder-policy 元素进行设置,Cross-Origin-Embedder-Policy 是一种机制,可防止文档加载任何未明确授予文档权限的跨域资源。 -
Cross-Origin-Resource-Policy
- 可以使用 cross-origin-resource-policy 元素进行设置,Cross-Origin-Resource-Policy 是一种机制,它传达了浏览器阻止对给定资源的无 cors 跨源/跨站点请求的愿望。
<headers> 属性
的<headers>
元素控制 headers 元素。
-
默认值-已禁用可选属性,指定禁用默认的 Spring Security 的 HTTP 响应 Headers。 默认值为 false (包括默认 headers)。
-
禁用指定禁用 Spring Security 的 HTTP 响应标头的可选属性。 默认值为 false (启用标头)。
<hsts>
启用后,将 Strict-Transport-Security 标头添加到任何安全请求的响应中。 这允许服务器指示浏览器自动使用 HTTPS 来处理将来的请求。
<hsts> 属性
-
禁用指定是否应禁用 Strict-Transport-Security。 默认为 false。
-
include-sub-domains (包含子域)指定是否应包含子域。 默认为 true。
-
最大年龄秒指定应将主机视为已知 HSTS 主机的最长时间。 默认 1 年。
-
请求匹配器引用用于确定是否应设置 Headers 的 RequestMatcher 实例。 默认值为 HttpServletRequest.isSecure() 为 true。
-
预加载指定是否应包含 preload。 默认为 false。
<hpkp>
启用后,将 Public Key Pinning Extension for HTTP 标头添加到任何安全请求的响应中。 这允许 HTTPS 网站抵御攻击者使用错误颁发或其他欺诈性证书的假冒。
<hpkp> 属性
-
禁用指定是否应禁用 HTTP 公钥固定 (HPKP)。 默认为 true。
-
include-sub-domains (包含子域)指定是否应包含子域。 默认为 false。
-
最大年龄秒设置 Public-Key-Pins 标头的 max-age 指令的值。 默认 60 天。
-
仅限报告指定浏览器是否应仅报告 pin 验证失败。 默认为 true。
-
report-uri指定浏览器应向其报告 pin 验证失败的 URI。
<内容安全策略>
启用后,将内容安全策略 (CSP) 标头添加到响应中。 CSP 是 Web 应用程序可以用来缓解内容注入漏洞的一种机制,例如跨站点脚本 (XSS)。
<content-security-policy> 属性
-
策略指令Content-Security-Policy 标头的安全策略指令,或者如果 report-only 设置为 true,则使用 Content-Security-Policy-Report-Only 标头。
-
仅限报告设置为 true,以启用 Content-Security-Policy-Report-Only 标头,仅用于报告策略冲突。 默认为 false。
<referrer-policy>
启用后,将 Referrer Policy 标头添加到响应中。
<功能策略>
启用后,将 Feature Policy 标头添加到响应中。
<frame-options>
启用后,会将 X-Frame-Options 标头添加到响应中,这将允许较新的浏览器进行一些安全检查并防止点击劫持攻击。
<frame-options> 属性
-
禁用如果禁用,则不会包含 X-Frame-Options 标头。 默认为 false。
-
政策
-
DENY
该页面无法显示在框架中,无论哪个站点尝试这样做。 这是指定 frame-options-policy 时的默认值。 -
SAMEORIGIN
页面只能显示在与页面本身同源的框架中
换句话说,如果指定 DENY,则不仅在从其他站点加载时尝试在框架中加载页面会失败,而且从同一站点加载时,尝试加载页面也会失败。 另一方面,如果指定 SAMEORIGIN,则只要在框架中包含该页面的站点与提供该页面的站点相同,您仍可以在框架中使用该页面。
-
<permissions-policy>
将 Permissions-Policy 标头添加到响应中。
<xss-protection>
将 X-XSS-Protection 标头添加到响应中,以帮助防止反射/类型 1 跨站点脚本 (XSS) 攻击。 这绝不是对 XSS 攻击的全面保护!
<xss-protection> 属性
-
xss-protection-disabled 已禁用不要包含用于反射/Type-1 跨站点脚本 (XSS) 保护的标头。
-
xss-protection-header-值显式设置反射/Type-1 跨站点脚本 (XSS) 标头的值。 以下之一: “0”, “1”, “1;mode=block“的默认为 “0”。
<内容类型选项>
将值为 nosniff 的 X-Content-Type-Options 标头添加到响应中。 这将禁用 IE8+ 和 Chrome 扩展的 MIME 探查。
<content-type-options> 的父元素
<匿名>
<csrf>
此元素将向应用程序添加跨站点请求伪造程序 (CSRF) 保护。 它还更新了默认的 RequestCache,以仅在身份验证成功后重放 “GET” 请求。 其他信息可以在参考的跨站点请求伪造 (CSRF) 部分找到。
<csrf> 属性
-
禁用指定禁用 Spring Security 的 CSRF 保护的可选属性。 默认值为 false (启用 CSRF 保护)。 强烈建议启用 CSRF 保护。
-
Tokens存储库引用要使用的 CsrfTokenRepository。 默认值为
HttpSessionCsrfTokenRepository
.
-
请求处理程序引用可选的
CsrfTokenRequestHandler
使用。默认值为CsrfTokenRequestAttributeHandler
.
-
请求匹配器引用RequestMatcher 实例,用于确定是否应应用 CSRF。 默认为除 “GET”、“TRACE”、“HEAD”、“OPTIONS” 之外的任何 HTTP 方法。
<自定义过滤器>
此元素用于将过滤器添加到过滤器链中。
它不会创建任何其他 bean,但用于选择 type 为jakarta.servlet.Filter
它已经在应用程序上下文中定义,并将其添加到 Spring Security 维护的过滤器链中的特定位置。
完整的详细信息可以在 命名空间 章节中找到。
<表达式处理程序>
<表单登录>
用于添加UsernamePasswordAuthenticationFilter
添加到过滤器堆栈中,并将LoginUrlAuthenticationEntryPoint
添加到应用程序上下文中以按需提供身份验证。
这将始终优先于其他命名空间创建的入口点。
如果未提供任何属性,则会在 URL “/login” 处自动生成一个登录页面[2]可以使用<form-login>
属性.
<form-login> 属性
-
始终使用默认目标如果设置为
true
,则用户将始终从 default-target-url 给定的值开始,无论他们如何到达登录页面。 映射到alwaysUseDefaultTargetUrl
的属性UsernamePasswordAuthenticationFilter
. 默认值为false
.
-
身份验证详细信息源引用对
AuthenticationDetailsSource
将由 Authentication 过滤器使用
-
authentication-failure-handler-ref (身份验证失败处理程序引用)可用作 authentication-failure-url 的替代方法,让您在身份验证失败后完全控制导航流。 该值应为
AuthenticationFailureHandler
bean 中。
-
身份验证失败 URL映射到
authenticationFailureUrl
的属性UsernamePasswordAuthenticationFilter
. 定义浏览器在登录失败时将重定向到的 URL。 默认为/login?error
,这将由自动登录页面生成器自动处理,并重新呈现带有错误消息的登录页面。
-
authentication-success-handler-ref (身份验证成功处理程序引用)这可以用作 default-target-url 和 always-use-default-target 的替代方法,让您在成功进行身份验证后完全控制导航流。 该值应为
AuthenticationSuccessHandler
bean 中。 默认情况下,SavedRequestAwareAuthenticationSuccessHandler
使用并注入 default-target-url 。
-
默认目标 URL映射到
defaultTargetUrl
的属性UsernamePasswordAuthenticationFilter
. 如果未设置,则默认值为 “/” (应用程序根目录)。 如果用户在尝试访问受保护资源时未被要求登录,则登录后将被带到此 URL,此时他们将被带到最初请求的 URL。
-
登录页面应用于呈现登录页面的 URL。 映射到
loginFormUrl
属性的LoginUrlAuthenticationEntryPoint
. 默认为 “/login”。
-
登录处理 URL映射到
filterProcessesUrl
的属性UsernamePasswordAuthenticationFilter
. 默认值为 “/login”。
-
密码参数包含密码的请求参数的名称。 默认为 “password”。
-
username-parameter (用户名参数)包含 username 的请求参数的名称。 默认为 “username”。
-
authentication-success-forward-url (身份验证成功转发 URL)映射 a
ForwardAuthenticationSuccessHandler
自authenticationSuccessHandler
的属性UsernamePasswordAuthenticationFilter
.
-
身份验证失败转发 URL映射 a
ForwardAuthenticationFailureHandler
自authenticationFailureHandler
的属性UsernamePasswordAuthenticationFilter
.
<oauth2-login>
OAuth 2.0 登录功能使用 OAuth 2.0 和/或 OpenID Connect 1.0 提供程序配置身份验证支持。
<oauth2-login> 属性
-
客户端注册存储库引用对
ClientRegistrationRepository
.
-
访问Tokens响应客户端引用对
OAuth2AccessTokenResponseClient
.
-
用户服务引用对
OAuth2UserService
.
-
oidc-用户服务引用对 OpenID Connect 的引用
OAuth2UserService
.
-
登录处理 URL筛选器处理身份验证请求的 URI。
-
登录页面用于将用户发送到登录的 URI。
-
authentication-success-handler-ref (身份验证成功处理程序引用)对
AuthenticationSuccessHandler
.
-
authentication-failure-handler-ref (身份验证失败处理程序引用)对
AuthenticationFailureHandler
.
-
jwt-decoder-factory-ref对
JwtDecoderFactory
使用者OidcAuthorizationCodeAuthenticationProvider
.
<oauth2-client>
<client-registrations>
向 OAuth 2.0 或 OpenID Connect 1.0 提供程序注册 (ClientRegistration) 的客户端的容器元素。
<客户端注册>
表示向 OAuth 2.0 或 OpenID Connect 1.0 提供程序注册的客户端。
<client-registration> 属性
-
注册 ID唯一标识
ClientRegistration
.
-
客户端 ID客户端标识符。
-
客户端密钥客户端密钥。
-
客户端身份验证方法用于向 Provider 验证 Client 的方法。 支持的值为 client_secret_basic、client_secret_post、private_key_jwt、client_secret_jwt 和 none(公共客户端)。
-
重定向 URI客户端已注册的重定向 URI,在最终用户对客户端进行身份验证和授权访问后,授权服务器会将最终用户的用户代理重定向到该 URI。
-
范围客户端在授权请求流程中请求的范围,例如 openid、email 或 profile。
-
客户端名称用于客户端的描述性名称。 该名称可能在某些情况下使用,例如在自动生成的登录页面中显示客户端的名称时。
-
提供商 ID对关联提供程序的引用。可以引用
<provider>
元素或使用常见提供程序之一(Google、GitHub、Facebook、Okta)。
<提供商>
OAuth 2.0 或 OpenID Connect 1.0 提供者的配置信息。
<provider> 属性
-
提供商 ID唯一标识提供程序的 ID。
-
Tokens URI授权服务器的Tokens端点 URI。
-
用户信息-URI用于访问经过身份验证的最终用户的声明/属性的 UserInfo Endpoint URI。
-
用户信息身份验证方法将访问Tokens发送到 UserInfo Endpoint 时使用的身份验证方法。 支持的值为 header、form 和 query。
-
用户信息用户名属性UserInfo Response 中返回的属性的名称,该属性引用最终用户的 Name 或 Identifier。
-
jwk-set-uri用于从授权服务器检索 JSON Web 密钥 (JWK) 集的 URI,其中包含用于验证 ID Tokens的 JSON Web 签名 (JWS) 的加密密钥,以及可选的 UserInfo 响应。
<oauth2-resource-server>
<opaque-token>
表示将授权不透明Tokens的 OAuth 2.0 资源服务器
<opaque-token> 属性
-
内省器-参考对
OpaqueTokenIntrospector
.这是一个更大的组件,它会覆盖introspection-uri
,client-id
和client-secret
.
-
introspection-uriIntrospection Uri 用于内省不透明Tokens的详细信息。应附有
client-id
和client-secret
.
-
客户端 ID用于对提供的
introspection-uri
.
-
客户端密钥用于对提供的
introspection-uri
.
-
身份验证转换器引用对
OpaqueTokenAuthenticationConverter
.负责将成功的自省结果转换为Authentication
实例。
<依赖方注册>
向 SAML 2.0 身份提供程序注册 (ClientRegistration) 的信赖方的容器元素。
<依赖方注册>
表示向 SAML 2.0 身份提供程序注册的信赖方
<relian-party-registration> 属性
-
注册 ID唯一标识
RelyingPartyRegistration
.
-
元数据位置断言方元数据位置。
-
客户端 ID信赖方的 EntityID。
-
assertion-consumer-service-location (断言使用者服务位置)AssertionConsumerService 位置。相当于
<AssertionConsumerService Location="…"/>
在依赖方的<SPSSODescriptor>
.
-
assertion-consumer-service-binding 的 AssertionConsumerService 绑定。相当于
<AssertionConsumerService Binding="…"/>
在依赖方的<SPSSODescriptor>
. 支持的值为 POST 和 REDIRECT。
-
单点注销服务位置SingleLogoutService 位置。等效于 <SingleLogoutService Location=“...“/> 在依赖方的 <SPSSODescriptor>.
-
单点注销服务响应位置SingleLogoutService ResponseLocation 的 ResponseLocation 中。等效于 <SingleLogoutService ResponseLocation=“...“/> 在依赖方的 <SPSSODescriptor>.
-
单点注销服务绑定SingleLogoutService 绑定。等效于 <SingleLogoutService Binding=“...“/> 在依赖方的 <SPSSODescriptor>. 支持的值为 POST 和 REDIRECT。
-
断言方 ID对关联断言方的引用。必须引用
<asserting-party>
元素。
<asserting-party>
SAML 2.0 断言方的配置信息。
<asserting-party> 属性
-
断言方 ID唯一标识断言方的 ID。
-
实体 ID断言方的 EntityID
-
want-authn-requests-signed 请求这
WantAuthnRequestsSigned
设置,指示断言方希望依赖方应签署AuthnRequest
在发送之前。
-
单点登录服务位置SingleSignOnService 位置。
-
服务绑定单点登录SingleSignOnService 绑定。 支持的值为 POST 和 REDIRECT。
-
签名算法的列表
org.opensaml.saml.ext.saml2alg.SigningMethod
此断言方的算法,按优先顺序排列。
-
单点注销服务位置SingleLogoutService 位置。等效于 <SingleLogoutService Location=“...“/> 在断言方的 <IDPSSODescriptor> 中。
-
单点注销服务响应位置SingleLogoutService ResponseLocation 的 ResponseLocation 中。等效于 <SingleLogoutService ResponseLocation=“...“/> 在断言方的 <IDPSSODescriptor> 中。
-
单点注销服务绑定SingleLogoutService 绑定。等效于 <SingleLogoutService Binding=“...“/> 在断言方的 <IDPSSODescriptor> 中。 支持的值为 POST 和 REDIRECT。
<http-basic>
<拦截 url>
此元素用于定义应用程序感兴趣的 URL 模式集,并配置应如何处理这些模式。
它用于构造FilterInvocationSecurityMetadataSource
由FilterSecurityInterceptor
.
它还负责配置ChannelProcessingFilter
例如,如果特定 URL 需要通过 HTTPS 访问。
将指定的模式与传入请求匹配时,将按照声明元素的顺序进行匹配。
因此,最具体的模式应该放在最前面,最通用的模式应该放在最后。
<intercept-url> 属性
-
访问列出将存储在
FilterInvocationSecurityMetadataSource
对于定义的 URL 模式/方法组合。 这应该是安全配置属性(例如角色名称)的逗号分隔列表。
-
方法HTTP 方法,将与模式和 servlet 路径(可选)结合使用,以匹配传入请求。 如果省略,则任何方法都将匹配。 如果指定了带和不带方法的相同模式,则特定于方法的匹配将优先。
-
模式定义 URL 路径的模式。 内容将取决于
request-matcher
属性,因此如果 Spring MVC 在 Classpath 中,则默认为 MVC 匹配器。
-
请求匹配器引用对
RequestMatcher
将用于确定此<intercept-url>
被使用。
-
requires-channel Can be "http" or "https" depending on whether a particular URL pattern should be accessed over HTTP or HTTPS respectively. Alternatively the value "any" can be used when there is no preference. If this attribute is present on any
<intercept-url>
element, then aChannelProcessingFilter
will be added to the filter stack and its additional dependencies added to the application context.
If a <port-mappings>
configuration is added, this will be used to by the SecureChannelProcessor
和InsecureChannelProcessor
beans to determine the ports used for redirecting to HTTP/HTTPS.
This property is invalid for filter-security-metadata-source |
-
servlet-path The servlet path which will be used in combination with the pattern and HTTP method to match an incoming request. This attribute is only applicable when request-matcher is 'mvc'. In addition, the value is only required in the following 2 use cases: 1) There are 2 or more
HttpServlet
's registered in theServletContext
that have mappings starting with and are different; 2) The pattern starts with the same value of a registered'/'
HttpServlet
path, excluding the default (root)HttpServlet
'/'
.
This property is invalid for filter-security-metadata-source |
<jee>
<logout>
添加LogoutFilter
to the filter stack.
This is configured with a SecurityContextLogoutHandler
.
<logout> Attributes
-
invalidate-session Maps to the
invalidateHttpSession
的SecurityContextLogoutHandler
. Defaults to "true", so the session will be invalidated on logout.
-
logout-success-url The destination URL which the user will be taken to after logging out. Defaults to <form-login-login-page>/?logout (i.e. /login?logout)
Setting this attribute will inject the
SessionManagementFilter
with aSimpleRedirectInvalidSessionStrategy
configured with the attribute value. When an invalid session ID is submitted, the strategy will be invoked, redirecting to the configured URL.
-
logout-url The URL which will cause a logout (i.e. which will be processed by the filter). Defaults to "/logout".
-
success-handler-ref May be used to supply an instance of
LogoutSuccessHandler
which will be invoked to control the navigation after logging out.
<saml2-login>
The SAML 2.0 Login feature configures authentication support using an SAML 2.0 Service Provider.
<saml2-login> Attributes
-
relying-party-registration-repository-ref Reference to the
RelyingPartyRegistrationRepository
.
-
authentication-request-repository-ref Reference to the
Saml2AuthenticationRequestRepository
.
-
authentication-request-context-resolver-ref Reference to the
Saml2AuthenticationRequestResolver
.
-
authentication-converter-ref Reference to the
AuthenticationConverter
.
-
登录处理 URL筛选器处理身份验证请求的 URI。
-
登录页面用于将用户发送到登录的 URI。
-
authentication-success-handler-ref (身份验证成功处理程序引用)对
AuthenticationSuccessHandler
.
-
authentication-failure-handler-ref (身份验证失败处理程序引用)对
AuthenticationFailureHandler
.
-
authentication-manager-ref Reference to the
AuthenticationManager
.
<saml2-logout>
The SAML 2.0 Single Logout feature configures support for RP- and AP-initiated SAML 2.0 Single Logout.
<saml2-logout> Attributes
-
logout-url The URL by which the relying or asserting party can trigger logout.
-
logout-request-url The URL by which the asserting party can send a SAML 2.0 Logout Request.
-
logout-response-url The URL by which the asserting party can send a SAML 2.0 Logout Response.
-
relying-party-registration-repository-ref Reference to the
RelyingPartyRegistrationRepository
.
-
logout-request-validator-ref Reference to the
Saml2LogoutRequestValidator
.
-
logout-request-resolver-ref Reference to the
Saml2LogoutRequestResolver
.
-
logout-request-repository-ref Reference to the
Saml2LogoutRequestRepository
.
-
logout-response-validator-ref Reference to the
Saml2LogoutResponseValidator
.
-
logout-response-resolver-ref Reference to the
Saml2LogoutResponseResolver
.
<password-management>
<port-mappings>
By default, an instance of PortMapperImpl
will be added to the configuration for use in redirecting to secure and insecure URLs.
This element can optionally be used to override the default mappings which that class defines.
Each child <port-mapping>
element defines a pair of HTTP:HTTPS ports.
The default mappings are 80:443 and 8080:8443.
An example of overriding these can be found in Redirect to HTTPS.
<port-mapping>
<remember-me>
Adds the RememberMeAuthenticationFilter
to the stack.
This in turn will be configured with either a TokenBasedRememberMeServices
, a PersistentTokenBasedRememberMeServices
or a user-specified bean implementing RememberMeServices
depending on the attribute settings.
<remember-me> Attributes
-
authentication-success-handler-ref Sets the
authenticationSuccessHandler
property on theRememberMeAuthenticationFilter
if custom navigation is required. The value should be the name of aAuthenticationSuccessHandler
bean 中。
-
data-source-ref A reference to a
DataSource
bean. If this is set,PersistentTokenBasedRememberMeServices
will be used and configured with aJdbcTokenRepositoryImpl
实例。
-
remember-me-parameter The name of the request parameter which toggles remember-me authentication. Defaults to "remember-me". Maps to the "parameter" property of
AbstractRememberMeServices
.
-
key Maps to the "key" property of
AbstractRememberMeServices
. Should be set to a unique value to ensure that remember-me cookies are only valid within the one application [3]. If this is not set a secure random value will be generated. Since generating secure random values can take a while, setting this value explicitly can help improve startup times when using the remember-me functionality.
-
services-alias Exports the internally defined
RememberMeServices
as a bean alias, allowing it to be used by other beans in the application context.
-
services-ref Allows complete control of the
RememberMeServices
implementation that will be used by the filter. The value should be theid
of a bean in the application context which implements this interface. Should also implementLogoutHandler
if a logout filter is in use.
-
token-repository-ref Configures a
PersistentTokenBasedRememberMeServices
but allows the use of a customPersistentTokenRepository
bean.
-
token-validity-seconds Maps to the
tokenValiditySeconds
的属性AbstractRememberMeServices
. Specifies the period in seconds for which the remember-me cookie should be valid. By default it will be valid for 14 days.
-
user-service-ref The remember-me services implementations require access to a
UserDetailsService
, so there has to be one defined in the application context. If there is only one, it will be selected and used automatically by the namespace configuration. If there are multiple instances, you can specify a beanid
explicitly using this attribute.
<request-cache> Element
<session-management>
Session-management related functionality is implemented by the addition of a SessionManagementFilter
to the filter stack.
<session-management> Attributes
-
authentication-strategy-explicit-invocation Setting this attribute to true will mean that
SessionManagementFilter
will not be injected and explicit invocation of SessionAuthenticationStrategy is required.
-
invalid-session-url Setting this attribute will inject the
SessionManagementFilter
with aSimpleRedirectInvalidSessionStrategy
configured with the attribute value. When an invalid session ID is submitted, the strategy will be invoked, redirecting to the configured URL.
-
invalid-session-url Allows injection of the InvalidSessionStrategy instance used by the SessionManagementFilter. Use either this or the
invalid-session-url
attribute but not both.
-
session-authentication-error-url Defines the URL of the error page which should be shown when the SessionAuthenticationStrategy raises an exception. If not set, an unauthorized (401) error code will be returned to the client. Note that this attribute doesn’t apply if the error occurs during a form-based login, where the URL for authentication failure will take precedence.
-
session-authentication-strategy-ref Allows injection of the SessionAuthenticationStrategy instance used by the SessionManagementFilter
-
session-fixation-protection Indicates how session fixation protection will be applied when a user authenticates. If set to "none", no protection will be applied. "newSession" will create a new empty session, with only Spring Security-related attributes migrated. "migrateSession" will create a new session and copy all session attributes to the new session. In Servlet 3.1 (Java EE 7) and newer containers, specifying "changeSessionId" will keep the existing session and use the container-supplied session fixation protection (HttpServletRequest#changeSessionId()). Defaults to "changeSessionId" in Servlet 3.1 and newer containers, "migrateSession" in older containers. Throws an exception if "changeSessionId" is used in older containers.
If session fixation protection is enabled, the
SessionManagementFilter
is injected with an appropriately configuredDefaultSessionAuthenticationStrategy
. See the Javadoc for this class for more details.
<concurrency-control>
Adds support for concurrent session control, allowing limits to be placed on the number of active sessions a user can have.
A ConcurrentSessionFilter
will be created, and a ConcurrentSessionControlAuthenticationStrategy
will be used with the SessionManagementFilter
.
If a form-login
element has been declared, the strategy object will also be injected into the created authentication filter.
An instance of SessionRegistry
(a SessionRegistryImpl
instance unless the user wishes to use a custom bean) will be created for use by the strategy.
<concurrency-control> Attributes
-
error-if-maximum-exceeded If set to "true" a
SessionAuthenticationException
will be raised when a user attempts to exceed the maximum allowed number of sessions. The default behaviour is to expire the original session.
-
expired-url The URL a user will be redirected to if they attempt to use a session which has been "expired" by the concurrent session controller because the user has exceeded the number of allowed sessions and has logged in again elsewhere. Should be set unless
exception-if-maximum-exceeded
is set. If no value is supplied, an expiry message will just be written directly back to the response.
-
expired-url Allows injection of the ExpiredSessionStrategy instance used by the ConcurrentSessionFilter
-
max-sessions Maps to the
maximumSessions
的属性ConcurrentSessionControlAuthenticationStrategy
. Specify-1
as the value to support unlimited sessions.
-
session-registry-alias It can also be useful to have a reference to the internal session registry for use in your own beans or an admin interface. You can expose the internal bean using the
session-registry-alias
attribute, giving it a name that you can use elsewhere in your configuration.
-
session-registry-ref The user can supply their own
SessionRegistry
implementation using thesession-registry-ref
attribute. The other concurrent session control beans will be wired up to use it.
<x509>
Adds support for X.509 authentication.
An X509AuthenticationFilter
will be added to the stack and an Http403ForbiddenEntryPoint
bean will be created.
The latter will only be used if no other authentication mechanisms are in use (its only functionality is to return an HTTP 403 error code).
A PreAuthenticatedAuthenticationProvider
will also be created which delegates the loading of user authorities to a UserDetailsService
.
<x509> Attributes
-
authentication-details-source-ref A reference to an
AuthenticationDetailsSource
-
subject-principal-regex Defines a regular expression which will be used to extract the username from the certificate (for use with the
UserDetailsService
).
-
user-service-ref Allows a specific
UserDetailsService
to be used with X.509 in the case where multiple instances are configured. If not set, an attempt will be made to locate a suitable instance automatically and use that.
<filter-chain-map>
Used to explicitly configure a FilterChainProxy instance with a FilterChainMap
<filter-chain-map> Attributes
-
request-matcher Defines the strategy to use for matching incoming requests. Currently the options are 'ant' (for ant path patterns), 'regex' for regular expressions and 'ciRegex' for case-insensitive regular expressions.
<filter-chain>
Used within to define a specific URL pattern and the list of filters which apply to the URLs matching that pattern. When multiple filter-chain elements are assembled in a list in order to configure a FilterChainProxy, the most specific patterns must be placed at the top of the list, with most general ones at the bottom.
<filter-chain> Attributes
-
filters A comma separated list of references to Spring beans that implement
Filter
. The value "none" means that noFilter
should be used for thisFilterChain
.
-
pattern A pattern that creates RequestMatcher in combination with the request-matcher
-
请求匹配器引用对
RequestMatcher
that will be used to determine if anyFilter
从filters
attribute should be invoked.
<filter-security-metadata-source>
Used to explicitly configure a FilterSecurityMetadataSource bean for use with a FilterSecurityInterceptor. Usually only needed if you are configuring a FilterChainProxy explicitly, rather than using the<http> element. The intercept-url elements used should only contain pattern, method and access attributes. Any others will result in a configuration error.
<filter-security-metadata-source> Attributes
-
id 一个 Bean 标识符,用于引用上下文中其他位置的 Bean。
-
request-matcher Defines the strategy use for matching incoming requests. Currently the options are 'ant' (for ant path patterns), 'regex' for regular expressions and 'ciRegex' for case-insensitive regular expressions.
-
use-expressions Enables the use of expressions in the 'access' attributes in <intercept-url> elements rather than the traditional list of configuration attributes. Defaults to 'true'. If enabled, each attribute should contain a single Boolean expression. If the expression evaluates to 'true', access will be granted.
DefaultLoginPageGeneratingFilter
is responsible for rendering the login page and will provide login forms for both normal form login and/or OIDC if required.
PersistentTokenBasedRememberMeServices
, where the tokens are stored on the server side.