对于最新的稳定版本,请使用 Spring Security 6.5.0spring-doc.cadn.net.cn

Web 应用程序安全

<debug>

启用 Spring Security 调试基础结构。 这将提供人类可读的 (多行) 调试信息,以监控进入安全过滤器的请求。 这可能包括敏感信息,例如请求参数或标头,并且只能在开发环境中使用。spring-doc.cadn.net.cn

<http>

如果您使用<http>元素中,一个FilterChainProxy创建名为“springSecurityFilterChain”的 Bean,并使用元素中的配置在FilterChainProxy. 从 Spring Security 3.1 开始,额外的http元素可用于添加额外的过滤器链[1]有关如何从web.xml]. 一些核心过滤器始终在过滤器链中创建,而其他过滤器将根据存在的属性和子元素添加到堆栈中。 标准过滤器的位置是固定的(参见命名空间介绍中的过滤器顺序表),当用户必须在FilterChainProxy豆。 当然,如果您需要完全控制配置,您仍然可以执行此作。spring-doc.cadn.net.cn

所有需要引用AuthenticationManager将自动注入 namespace 配置创建的内部实例。spring-doc.cadn.net.cn

<http>namespace 块总是创建一个SecurityContextPersistenceFilterExceptionTranslationFilter以及FilterSecurityInterceptor. 这些是固定的,不能用替代品代替。spring-doc.cadn.net.cn

<http> 属性

<http>元素控制核心过滤器上的一些属性。spring-doc.cadn.net.cn

  • 使用授权管理器使用 AuthorizationManager API 而不是 SecurityMetadataSource(默认为 true)spring-doc.cadn.net.cn

  • 访问决策管理器引用使用此 AuthorizationManager,而不是从 <intercept-url> 元素派生一个spring-doc.cadn.net.cn

  • 访问决策管理器引用Optional 属性,用于指定AccessDecisionManager实现,该实现应用于授权 HTTP 请求。 默认情况下,一个AffirmativeBasedimplementation 用于RoleVoter以及一个AuthenticatedVoter.spring-doc.cadn.net.cn

  • 身份验证管理器引用AuthenticationManager用于FilterChain由此 HTTP 元素创建。spring-doc.cadn.net.cn

  • 自动配置自动注册登录表单、BASIC 认证、注销服务。 如果设置为 “true”,则添加所有这些功能(尽管您仍然可以通过提供相应的元素来自定义每个功能的配置)。 如果未指定,则默认为 “false”。 不建议使用此属性。 请改用显式配置元素以避免混淆。spring-doc.cadn.net.cn

  • 创建会话控制 Spring Security 类创建 HTTP 会话的急切程度。 选项包括:spring-doc.cadn.net.cn

    • always- 如果不存在会话,Spring Security 将主动创建一个会话。spring-doc.cadn.net.cn

    • ifRequired- Spring Security 将仅在需要会话时才创建会话(默认值)。spring-doc.cadn.net.cn

    • never- Spring Security 永远不会创建会话,但如果应用程序创建会话,则会使用会话。spring-doc.cadn.net.cn

    • stateless- Spring Security 不会创建会话并忽略该会话以获取 SpringAuthentication.spring-doc.cadn.net.cn

  • disable-url-rewriting (禁用 url 重写)防止将会话 ID 附加到应用程序中的 URL。 如果此属性设置为true. 默认值为true.spring-doc.cadn.net.cn

  • 入口点引用通常AuthenticationEntryPointused 将根据已配置的身份验证机制进行设置。 此属性允许通过定义自定义的AuthenticationEntryPointbean,它将启动身份验证过程。spring-doc.cadn.net.cn

  • jaas-api 配置如果可用,则以Subject收购自JaasAuthenticationToken这是通过添加JaasApiIntegrationFilterbean 添加到堆栈中。 默认为false.spring-doc.cadn.net.cn

  • 每次请求一次对应于observeOncePerRequest的属性FilterSecurityInterceptor. 默认为false.spring-doc.cadn.net.cn

  • filter-all-dispatcher-types对应于shouldFilterAllDispatcherTypes属性的AuthorizationFilter.在以下情况下不起作用use-authorization-manager=false. 默认为true.spring-doc.cadn.net.cn

  • 模式http 元素定义模式可控制请求,这些请求将通过它定义的过滤器列表进行过滤。 解释取决于配置的 request-matcher。 如果未定义模式,则将匹配所有请求,因此应首先声明最具体的模式。spring-doc.cadn.net.cn

  • 领域设置用于基本身份验证的领域名称(如果启用)。 对应于realmName属性BasicAuthenticationEntryPoint.spring-doc.cadn.net.cn

  • 请求匹配器定义RequestMatcher策略FilterChainProxy以及由intercept-url匹配传入请求。 选项当前为mvc,ant,regexciRegex,对于 Spring MVC,分别为 ant、regular-expression 和 event-insensitive regular-expression。 使用其 patternmethodservlet-path 属性为每个 intercept-url 元素创建一个单独的实例。 Ant 路径使用AntPathRequestMatcher,则使用RegexRequestMatcher对于 Spring MVC 路径,匹配MvcRequestMatcher被使用。 有关如何执行匹配的更多详细信息,请参阅这些类的 Javadoc。 如果 Classpath 中存在 Spring MVC,则 MVC 是默认策略,如果没有,则使用 Ant 路径。spring-doc.cadn.net.cn

  • 请求匹配器引用对实现RequestMatcher这将确定此FilterChain应该使用。 这是 pattern 的更强大的替代方案。spring-doc.cadn.net.cn

  • 安全请求模式可以映射到空的过滤器链,方法是将此属性设置为none. 不会应用任何安全性,并且 Spring Security 的任何功能都不可用。spring-doc.cadn.net.cn

  • security-context-repository-ref 的允许注入自定义SecurityContextHolderStrategySecurityContextPersistenceFilter,SecurityContextHolderFilter,BasicAuthenticationFilter,UsernamePasswordAuthenticationFilter,ExceptionTranslationFilter,LogoutFilter等。spring-doc.cadn.net.cn

  • 安全上下文显式保存如果为 true,则使用SecurityContextHolderFilter而不是SecurityContextPersistenceFilter. 需要显式保存spring-doc.cadn.net.cn

  • security-context-repository-ref 的允许注入自定义SecurityContextRepositorySecurityContextPersistenceFilter.spring-doc.cadn.net.cn

  • servlet api-provision提供HttpServletRequest安全方法,例如isUserInRole()getPrincipal()这些 API 是通过添加SecurityContextHolderAwareRequestFilterbean 添加到堆栈中。 默认为true.spring-doc.cadn.net.cn

<access-denied-handler>

此元素允许您设置errorPage属性为默认值AccessDeniedHandlerExceptionTranslationFilter、使用 error-page 属性,或者使用 ref 属性提供您自己的实现。 这在 ExceptionTranslationFilter 一节中有更详细的讨论。spring-doc.cadn.net.cn

<access-denied-handler 的父元素>

<access-denied-handler> 属性

  • 错误页如果经过身份验证的用户请求他们无权访问的页面,则将被重定向到被拒绝的页面。spring-doc.cadn.net.cn

<cors>

此元素允许配置CorsFilter. 如果没有CorsFilterCorsConfigurationSource,并且 Spring MVC 位于类路径上,则HandlerMappingIntrospector用作CorsConfigurationSource.spring-doc.cadn.net.cn

<cors> 属性

<cors>元素控制 headers 元素。spring-doc.cadn.net.cn

  • cors-configuration-source-ref指定 Bean 名称的 Optional 属性CorsConfigurationSource注入到CorsFilter由 XML 命名空间创建。spring-doc.cadn.net.cn

< 的父元素>

<headers>

此元素允许配置要与响应一起发送的其他 (安全) 标头。 它可以轻松配置多个标头,还允许通过 header 元素设置自定义标头。 其他信息,可以在参考的 Security Headers 部分找到。spring-doc.cadn.net.cn

<headers> 属性

<headers>元素控制 headers 元素。spring-doc.cadn.net.cn

  • 默认值-已禁用可选属性,指定禁用默认的 Spring Security 的 HTTP 响应 Headers。 默认值为 false (包括默认 headers)。spring-doc.cadn.net.cn

  • 禁用指定禁用 Spring Security 的 HTTP 响应标头的可选属性。 默认值为 false (启用标头)。spring-doc.cadn.net.cn

<headers 的父元素>

<cache-control>

增加Cache-Control,PragmaExpires标头,以确保浏览器不会缓存受保护的页面。spring-doc.cadn.net.cn

<cache-control> 属性

<cache-control 的父元素>

<hsts>

启用后,将 Strict-Transport-Security 标头添加到任何安全请求的响应中。 这允许服务器指示浏览器自动使用 HTTPS 来处理将来的请求。spring-doc.cadn.net.cn

<hsts> 属性

  • include-sub-domains (包含子域)指定是否应包含子域。 默认为 true。spring-doc.cadn.net.cn

  • 最大年龄秒指定应将主机视为已知 HSTS 主机的最长时间。 默认 1 年。spring-doc.cadn.net.cn

  • 请求匹配器引用用于确定是否应设置 Headers 的 RequestMatcher 实例。 默认值为 HttpServletRequest.isSecure() 为 true。spring-doc.cadn.net.cn

<hsts 的父元素>

<hpkp>

启用后,将 Public Key Pinning Extension for HTTP 标头添加到任何安全请求的响应中。 这允许 HTTPS 网站抵御攻击者使用错误颁发或其他欺诈性证书的假冒。spring-doc.cadn.net.cn

<hpkp> 属性

  • include-sub-domains (包含子域)指定是否应包含子域。 默认为 false。spring-doc.cadn.net.cn

  • 最大年龄秒设置 Public-Key-Pins 标头的 max-age 指令的值。 默认 60 天。spring-doc.cadn.net.cn

<hpkp 的父元素>

<引脚>

<pins 的子元素>

<pin>

使用 base64 编码的 SPKI 指纹作为值,使用加密哈希算法作为属性来指定 pinspring-doc.cadn.net.cn

<pin> 属性

<pin 的父元素>

<内容安全策略>

启用后,将内容安全策略 (CSP) 标头添加到响应中。 CSP 是 Web 应用程序可以用来缓解内容注入漏洞的一种机制,例如跨站点脚本 (XSS)。spring-doc.cadn.net.cn

<content-security-policy> 属性

  • 策略指令Content-Security-Policy 标头的安全策略指令,或者如果 report-only 设置为 true,则使用 Content-Security-Policy-Report-Only 标头。spring-doc.cadn.net.cn

  • 仅限报告设置为 true,以启用 Content-Security-Policy-Report-Only 标头,仅用于报告策略冲突。 默认为 false。spring-doc.cadn.net.cn

<content-security-policy 的父元素>

<referrer-policy>

启用后,将 Referrer Policy 标头添加到响应中。spring-doc.cadn.net.cn

<referrer-policy> 属性

<referrer-policy 的父元素>

<功能策略>

启用后,将 Feature Policy 标头添加到响应中。spring-doc.cadn.net.cn

<feature-policy> 属性

<feature-policy 的父元素>

<frame-options>

启用后,会将 X-Frame-Options 标头添加到响应中,这将允许较新的浏览器进行一些安全检查并防止点击劫持攻击。spring-doc.cadn.net.cn

<frame-options> 属性

  • 政策spring-doc.cadn.net.cn

    • DENY该页面无法显示在框架中,无论哪个站点尝试这样做。 这是指定 frame-options-policy 时的默认值。spring-doc.cadn.net.cn

    • SAMEORIGIN页面只能显示在与页面本身同源的框架中spring-doc.cadn.net.cn

    换句话说,如果指定 DENY,则不仅在从其他站点加载时尝试在框架中加载页面会失败,而且从同一站点加载时,尝试加载页面也会失败。 另一方面,如果指定 SAMEORIGIN,则只要在框架中包含该页面的站点与提供该页面的站点相同,您仍可以在框架中使用该页面。spring-doc.cadn.net.cn

<frame-options> 的父元素

<permissions-policy>

<permissions-policy> 属性

<permissions-policy 的父元素>

<xss-protection>

X-XSS-Protection 标头添加到响应中,以帮助防止反射/类型 1 跨站点脚本 (XSS) 攻击。 这绝不是对 XSS 攻击的全面保护!spring-doc.cadn.net.cn

<xss-protection> 属性

<xss-protection 的父元素>

<内容类型选项>

将值为 nosniff 的 X-Content-Type-Options 标头添加到响应中。 这将禁用 IE8+ 和 Chrome 扩展的 MIME 探查spring-doc.cadn.net.cn

<content-type-options> 属性

<content-type-options> 的父元素

<跨源嵌入器策略>

启用后,将 Cross-Origin-Embedder-Policy 标头添加到响应中。spring-doc.cadn.net.cn

<cross-origin-embedder-policy> 属性
<cross-origin-embedder-policy 的父元素>

<跨域打开器策略>

启用后,将 Cross-Origin-Opener-Policy 标头添加到响应中。spring-doc.cadn.net.cn

<cross-origin-opener-policy> 属性
<cross-origin-opener-policy 的父元素>

<跨源资源策略>

启用后,将 Cross-Origin-Resource-Policy 标头添加到响应中。spring-doc.cadn.net.cn

<cross-origin-resource-policy> 属性
<cross-origin-resource-policy 的父元素>

<header>

向响应中添加额外的 Headers,name 和 value 都需要指定。spring-doc.cadn.net.cn

<header-attributes> 属性

<header 的父元素>

<匿名>

添加一个AnonymousAuthenticationFilter添加到堆栈中,并将AnonymousAuthenticationProvider. 如果您使用的是IS_AUTHENTICATED_ANONYMOUSLY属性。spring-doc.cadn.net.cn

<anonymous> 的父元素

<anonymous> 属性

  • 启用使用默认命名空间设置时,将自动启用匿名 “authentication” 工具。 您可以使用此属性禁用它。spring-doc.cadn.net.cn

  • 授予权限应分配给匿名请求的已授予权限。 通常用于为匿名请求分配特定角色,这些角色随后可用于授权决策。 如果未设置,则默认为ROLE_ANONYMOUS.spring-doc.cadn.net.cn

  • 钥匙提供程序和筛选器之间共享的密钥。 这通常不需要设置。 如果未设置,它将默认为安全的随机生成值。 这意味着设置此值可以缩短使用匿名功能时的启动时间,因为生成安全随机值可能需要一段时间。spring-doc.cadn.net.cn

  • 用户名应分配给匿名请求的用户名。 这允许识别主体,这对于日志记录和审计可能很重要。 如果未设置,则默认为anonymousUser.spring-doc.cadn.net.cn

<csrf>

此元素将向应用程序添加跨站点请求伪造程序 (CSRF) 保护。 它还更新了默认的 RequestCache,以仅在身份验证成功后重放 “GET” 请求。 其他信息可以在参考的跨站点请求伪造 (CSRF) 部分找到。spring-doc.cadn.net.cn

<csrf 的父元素>

<csrf> 属性

  • 禁用指定禁用 Spring Security 的 CSRF 保护的可选属性。 默认值为 false (启用 CSRF 保护)。 强烈建议启用 CSRF 保护。spring-doc.cadn.net.cn

  • Tokens存储库引用要使用的 CsrfTokenRepository。 默认值为HttpSessionCsrfTokenRepository.spring-doc.cadn.net.cn

  • 请求处理程序引用可选的CsrfTokenRequestHandler使用。默认值为CsrfTokenRequestAttributeHandler.spring-doc.cadn.net.cn

  • 请求匹配器引用RequestMatcher 实例,用于确定是否应应用 CSRF。 默认为除 “GET”、“TRACE”、“HEAD”、“OPTIONS” 之外的任何 HTTP 方法。spring-doc.cadn.net.cn

<自定义过滤器>

此元素用于将过滤器添加到过滤器链中。 它不会创建任何其他 bean,但用于选择 type 为jakarta.servlet.Filter它已经在应用程序上下文中定义,并将其添加到 Spring Security 维护的过滤器链中的特定位置。 完整的详细信息可以在 命名空间 章节中找到。spring-doc.cadn.net.cn

<custom-filter 的父元素>

<custom-filter> 属性

  • 紧接在之后的 filter,custom-filter 应放置在链中。 只有希望将自己的过滤器混合到安全过滤器链中并对标准 Spring Security 过滤器有一定了解的高级用户才需要此功能。 过滤器名称映射到特定的 Spring Security 实现过滤器。spring-doc.cadn.net.cn

  • 位置自定义过滤器应在链中放置的显式位置。 如果要更换标准过滤器,请使用。spring-doc.cadn.net.cn

<表达式处理程序>

定义SecurityExpressionHandler实例,如果启用了基于表达式的访问控制,则将使用该实例。 如果未提供,将使用默认实现(不支持 ACL)。spring-doc.cadn.net.cn

<expression-handler> 属性

<表单登录>

用于添加UsernamePasswordAuthenticationFilter添加到过滤器堆栈中,并将LoginUrlAuthenticationEntryPoint添加到应用程序上下文中以按需提供身份验证。 这将始终优先于其他命名空间创建的入口点。 如果未提供任何属性,则会在 URL “/login” 处自动生成一个登录页面[2]可以使用<form-login>属性.spring-doc.cadn.net.cn

<form-login> 的父元素

<form-login> 属性

  • 始终使用默认目标如果设置为true,则用户将始终从 default-target-url 给定的值开始,无论他们如何到达登录页面。 映射到alwaysUseDefaultTargetUrl的属性UsernamePasswordAuthenticationFilter. 默认值为false.spring-doc.cadn.net.cn

  • 身份验证详细信息源引用AuthenticationDetailsSource将由 Authentication 过滤器使用spring-doc.cadn.net.cn

  • authentication-failure-handler-ref (身份验证失败处理程序引用)可用作 authentication-failure-url 的替代方法,让您在身份验证失败后完全控制导航流。 该值应为AuthenticationFailureHandlerbean 中。spring-doc.cadn.net.cn

  • 身份验证失败 URL映射到authenticationFailureUrl的属性UsernamePasswordAuthenticationFilter. 定义浏览器在登录失败时将重定向到的 URL。 默认为/login?error,这将由自动登录页面生成器自动处理,并重新呈现带有错误消息的登录页面。spring-doc.cadn.net.cn

  • 默认目标 URL映射到defaultTargetUrl的属性UsernamePasswordAuthenticationFilter. 如果未设置,则默认值为 “/” (应用程序根目录)。 如果用户在尝试访问受保护资源时未被要求登录,则登录后将被带到此 URL,此时他们将被带到最初请求的 URL。spring-doc.cadn.net.cn

  • 登录页面应用于呈现登录页面的 URL。 映射到loginFormUrl属性的LoginUrlAuthenticationEntryPoint. 默认为 “/login”。spring-doc.cadn.net.cn

  • 登录处理 URL映射到filterProcessesUrl的属性UsernamePasswordAuthenticationFilter. 默认值为 “/login”。spring-doc.cadn.net.cn

  • username-parameter (用户名参数)包含 username 的请求参数的名称。 默认为 “username”。spring-doc.cadn.net.cn

  • authentication-success-forward-url (身份验证成功转发 URL)映射 aForwardAuthenticationSuccessHandlerauthenticationSuccessHandler的属性UsernamePasswordAuthenticationFilter.spring-doc.cadn.net.cn

  • 身份验证失败转发 URL映射 aForwardAuthenticationFailureHandlerauthenticationFailureHandler的属性UsernamePasswordAuthenticationFilter.spring-doc.cadn.net.cn

<oauth2-login>

OAuth 2.0 登录功能使用 OAuth 2.0 和/或 OpenID Connect 1.0 提供程序配置身份验证支持。spring-doc.cadn.net.cn

<oauth2-login 的父元素>

<oauth2-login> 属性

  • authentication-success-handler-ref (身份验证成功处理程序引用)对AuthenticationSuccessHandler.spring-doc.cadn.net.cn

  • authentication-failure-handler-ref (身份验证失败处理程序引用)对AuthenticationFailureHandler.spring-doc.cadn.net.cn

  • jwt-decoder-factory-refJwtDecoderFactory使用者OidcAuthorizationCodeAuthenticationProvider.spring-doc.cadn.net.cn

<oauth2-client>

<oauth2-client 的父元素>

<oauth2-client> 属性

<oauth2-client 的子元素>

<授权代码授予>

<authorization-code-grant> 的父元素

<authorization-code-grant> 属性

<client-registrations>

向 OAuth 2.0 或 OpenID Connect 1.0 提供程序注册 (ClientRegistration) 的客户端的容器元素。spring-doc.cadn.net.cn

<客户端注册>

表示向 OAuth 2.0 或 OpenID Connect 1.0 提供程序注册的客户端。spring-doc.cadn.net.cn

<client-registration> 的父元素

<client-registration> 属性

  • 授权授予类型OAuth 2.0 授权框架定义了四种授权授权类型。 支持的值为authorization_code,client_credentials,password以及扩展授权类型urn:ietf:params:oauth:grant-type:jwt-bearer.spring-doc.cadn.net.cn

  • 重定向 URI客户端已注册的重定向 URI,在最终用户对客户端进行身份验证和授权访问后,授权服务器会将最终用户的用户代理重定向到该 URI。spring-doc.cadn.net.cn

  • 范围客户端在授权请求流程中请求的范围,例如 openid、email 或 profile。spring-doc.cadn.net.cn

  • 客户端名称用于客户端的描述性名称。 该名称可能在某些情况下使用,例如在自动生成的登录页面中显示客户端的名称时。spring-doc.cadn.net.cn

  • 提供商 ID对关联提供程序的引用。可以引用<provider>元素或使用常见提供程序之一(Google、GitHub、Facebook、Okta)。spring-doc.cadn.net.cn

<提供商>

OAuth 2.0 或 OpenID Connect 1.0 提供者的配置信息。spring-doc.cadn.net.cn

<provider> 属性

  • 用户信息-URI用于访问经过身份验证的最终用户的声明/属性的 UserInfo Endpoint URI。spring-doc.cadn.net.cn

  • 用户信息身份验证方法将访问Tokens发送到 UserInfo Endpoint 时使用的身份验证方法。 支持的值为 headerformqueryspring-doc.cadn.net.cn

  • 用户信息用户名属性UserInfo Response 中返回的属性的名称,该属性引用最终用户的 Name 或 Identifier。spring-doc.cadn.net.cn

<oauth2-resource-server>

添加BearerTokenAuthenticationFilter,BearerTokenAuthenticationEntryPointBearerTokenAccessDeniedHandler添加到配置中。 此外,要么<jwt><opaque-token>必须指定。spring-doc.cadn.net.cn

<oauth2-resource-server 的 Parents 元素>

<oauth2-resource-server> 属性

  • 身份验证管理器解析器引用AuthenticationManagerResolver这将解析AuthenticationManager请求时spring-doc.cadn.net.cn

  • bearer-token-resolver-ref (不记名Tokens解析器引用)对BearerTokenResolver它将从请求中检索不记名Tokensspring-doc.cadn.net.cn

<jwt>

表示将授权 JWT 的 OAuth 2.0 资源服务器spring-doc.cadn.net.cn

<jwt> 属性

<opaque-token>

表示将授权不透明Tokens的 OAuth 2.0 资源服务器spring-doc.cadn.net.cn

<opaque-token 的父元素>

<opaque-token> 属性

  • 内省器-参考OpaqueTokenIntrospector.这是一个更大的组件,它会覆盖introspection-uri,client-idclient-secret.spring-doc.cadn.net.cn

  • introspection-uriIntrospection Uri 用于内省不透明Tokens的详细信息。应附有client-idclient-secret.spring-doc.cadn.net.cn

  • 身份验证转换器引用OpaqueTokenAuthenticationConverter.负责将成功的自省结果转换为Authentication实例。spring-doc.cadn.net.cn

<依赖方注册>

向 SAML 2.0 身份提供程序注册 (ClientRegistration) 的信赖方的容器元素。spring-doc.cadn.net.cn

<依赖方注册>

表示向 SAML 2.0 身份提供程序注册的信赖方spring-doc.cadn.net.cn

<relying-party-registration 的父元素>

<relian-party-registration> 属性

  • assertion-consumer-service-location (断言使用者服务位置)AssertionConsumerService 位置。相当于<AssertionConsumerService Location="…​"/>在依赖方的<SPSSODescriptor>.spring-doc.cadn.net.cn

  • assertion-consumer-service-binding 的 AssertionConsumerService 绑定。相当于<AssertionConsumerService Binding="…​"/>在依赖方的<SPSSODescriptor>. 支持的值为 POSTREDIRECT。spring-doc.cadn.net.cn

  • 单点注销服务位置SingleLogoutService 位置。等效于 <SingleLogoutService Location=“...“/> 在依赖方的 <SPSSODescriptor>.spring-doc.cadn.net.cn

  • 单点注销服务响应位置SingleLogoutService ResponseLocation 的 ResponseLocation 中。等效于 <SingleLogoutService ResponseLocation=“...“/> 在依赖方的 <SPSSODescriptor>.spring-doc.cadn.net.cn

  • 单点注销服务绑定SingleLogoutService 绑定。等效于 <SingleLogoutService Binding=“...“/> 在依赖方的 <SPSSODescriptor>. 支持的值为 POSTREDIRECT。spring-doc.cadn.net.cn

<解密凭证>

与信赖方关联的解密凭证。spring-doc.cadn.net.cn

<decryption-credential> 属性

<签名凭据>

与信赖方关联的签名凭证。spring-doc.cadn.net.cn

<verification-credential> 属性

<asserting-party>

SAML 2.0 断言方的配置信息。spring-doc.cadn.net.cn

<asserting-party 的父元素>

<asserting-party> 属性

  • want-authn-requests-signed 请求这WantAuthnRequestsSigned设置,指示断言方希望依赖方应签署AuthnRequest在发送之前。spring-doc.cadn.net.cn

  • 签名算法的列表org.opensaml.saml.ext.saml2alg.SigningMethod此断言方的算法,按优先顺序排列。spring-doc.cadn.net.cn

  • 单点注销服务位置SingleLogoutService 位置。等效于 <SingleLogoutService Location=“...“/> 在断言方的 <IDPSSODescriptor> 中。spring-doc.cadn.net.cn

  • 单点注销服务响应位置SingleLogoutService ResponseLocation 的 ResponseLocation 中。等效于 <SingleLogoutService ResponseLocation=“...“/> 在断言方的 <IDPSSODescriptor> 中。spring-doc.cadn.net.cn

  • 单点注销服务绑定SingleLogoutService 绑定。等效于 <SingleLogoutService Binding=“...“/> 在断言方的 <IDPSSODescriptor> 中。 支持的值为 POSTREDIRECT。spring-doc.cadn.net.cn

<encryption-credential>

与断言方关联的加密凭证。spring-doc.cadn.net.cn

<encryption-credential 的父元素>

<encryption-credential> 属性

<验证凭证>

与断言方关联的验证凭证。spring-doc.cadn.net.cn

<verification-credential 的父元素>

<verification-credential> 属性

<http-basic>

添加BasicAuthenticationFilterBasicAuthenticationEntryPoint添加到配置中。 如果未启用基于表单的登录,则后者将仅用作配置入口点。spring-doc.cadn.net.cn

<http-basic 的父元素>

<http-basic> 属性

  • 身份验证详细信息源引用AuthenticationDetailsSource将由 Authentication 过滤器使用spring-doc.cadn.net.cn

<http-firewall> 元素

这是一个顶级元素,可用于注入HttpFirewallFilterChainProxy由 namespace 创建。 默认实现应适用于大多数应用程序。spring-doc.cadn.net.cn

<http-firewall> 属性

<拦截 url>

此元素用于定义应用程序感兴趣的 URL 模式集,并配置应如何处理这些模式。 它用于构造FilterInvocationSecurityMetadataSourceFilterSecurityInterceptor. 它还负责配置ChannelProcessingFilter例如,如果特定 URL 需要通过 HTTPS 访问。 将指定的模式与传入请求匹配时,将按照声明元素的顺序进行匹配。 因此,最具体的模式应该放在最前面,最通用的模式应该放在最后。spring-doc.cadn.net.cn

<intercept-url> 属性

  • 访问列出将存储在FilterInvocationSecurityMetadataSource对于定义的 URL 模式/方法组合。 这应该是安全配置属性(例如角色名称)的逗号分隔列表。spring-doc.cadn.net.cn

  • 方法HTTP 方法,将与模式和 servlet 路径(可选)结合使用,以匹配传入请求。 如果省略,则任何方法都将匹配。 如果指定了带和不带方法的相同模式,则特定于方法的匹配将优先。spring-doc.cadn.net.cn

  • 模式定义 URL 路径的模式。 内容将取决于request-matcher属性,因此如果 Spring MVC 在 Classpath 中,则默认为 MVC 匹配器。spring-doc.cadn.net.cn

  • 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 a ChannelProcessingFilter will be added to the filter stack and its additional dependencies added to the application context.spring-doc.cadn.net.cn

If a <port-mappings> configuration is added, this will be used to by the SecureChannelProcessorInsecureChannelProcessor beans to determine the ports used for redirecting to HTTP/HTTPS.spring-doc.cadn.net.cn

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 the ServletContext 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 '/'.spring-doc.cadn.net.cn

This property is invalid for filter-security-metadata-source

<jee>

Adds a J2eePreAuthenticatedProcessingFilter to the filter chain to provide integration with container authentication.spring-doc.cadn.net.cn

Parent Elements of <jee>

<jee> Attributes

  • mappable-roles A comma-separate list of roles to look for in the incoming HttpServletRequest.spring-doc.cadn.net.cn

<logout>

添加LogoutFilter to the filter stack. This is configured with a SecurityContextLogoutHandler.spring-doc.cadn.net.cn

Parent Elements of <logout>

<logout> Attributes

  • delete-cookies A comma-separated list of the names of cookies which should be deleted when the user logs out.spring-doc.cadn.net.cn

  • invalidate-session Maps to the invalidateHttpSessionSecurityContextLogoutHandler. Defaults to "true", so the session will be invalidated on logout.spring-doc.cadn.net.cn

  • 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)spring-doc.cadn.net.cn

    Setting this attribute will inject the SessionManagementFilter with a SimpleRedirectInvalidSessionStrategy configured with the attribute value. When an invalid session ID is submitted, the strategy will be invoked, redirecting to the configured URL.spring-doc.cadn.net.cn

  • logout-url The URL which will cause a logout (i.e. which will be processed by the filter). Defaults to "/logout".spring-doc.cadn.net.cn

  • success-handler-ref May be used to supply an instance of LogoutSuccessHandler which will be invoked to control the navigation after logging out.spring-doc.cadn.net.cn

<saml2-login>

The SAML 2.0 Login feature configures authentication support using an SAML 2.0 Service Provider.spring-doc.cadn.net.cn

Parent Elements of <saml2-login>

<saml2-login> Attributes

  • relying-party-registration-repository-ref Reference to the RelyingPartyRegistrationRepository.spring-doc.cadn.net.cn

  • authentication-request-repository-ref Reference to the Saml2AuthenticationRequestRepository.spring-doc.cadn.net.cn

  • authentication-request-context-resolver-ref Reference to the Saml2AuthenticationRequestResolver.spring-doc.cadn.net.cn

  • authentication-success-handler-ref (身份验证成功处理程序引用)对AuthenticationSuccessHandler.spring-doc.cadn.net.cn

  • authentication-failure-handler-ref (身份验证失败处理程序引用)对AuthenticationFailureHandler.spring-doc.cadn.net.cn

<saml2-logout>

The SAML 2.0 Single Logout feature configures support for RP- and AP-initiated SAML 2.0 Single Logout.spring-doc.cadn.net.cn

Parent Elements of <saml2-logout>

<saml2-logout> Attributes

  • logout-request-url The URL by which the asserting party can send a SAML 2.0 Logout Request.spring-doc.cadn.net.cn

  • logout-response-url The URL by which the asserting party can send a SAML 2.0 Logout Response.spring-doc.cadn.net.cn

  • relying-party-registration-repository-ref Reference to the RelyingPartyRegistrationRepository.spring-doc.cadn.net.cn

<password-management>

This element configures password management.spring-doc.cadn.net.cn

Parent Elements of <password-management>

<password-management> Attributes

<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.spring-doc.cadn.net.cn

Parent Elements of <port-mappings>

Child Elements of <port-mappings>

<port-mapping>

Provides a method to map http ports to https ports when forcing a redirect.spring-doc.cadn.net.cn

Parent Elements of <port-mapping>

<port-mapping> Attributes

<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.spring-doc.cadn.net.cn

Parent Elements of <remember-me>

<remember-me> Attributes

  • authentication-success-handler-ref Sets the authenticationSuccessHandler property on the RememberMeAuthenticationFilter if custom navigation is required. The value should be the name of a AuthenticationSuccessHandlerbean 中。spring-doc.cadn.net.cn

  • data-source-ref A reference to a DataSource bean. If this is set, PersistentTokenBasedRememberMeServices will be used and configured with a JdbcTokenRepositoryImpl实例。spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

  • services-alias Exports the internally defined RememberMeServices as a bean alias, allowing it to be used by other beans in the application context.spring-doc.cadn.net.cn

  • services-ref Allows complete control of the RememberMeServices implementation that will be used by the filter. The value should be the id of a bean in the application context which implements this interface. Should also implement LogoutHandler if a logout filter is in use.spring-doc.cadn.net.cn

  • token-repository-ref Configures a PersistentTokenBasedRememberMeServices but allows the use of a custom PersistentTokenRepository bean.spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

  • 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 bean id explicitly using this attribute.spring-doc.cadn.net.cn

<request-cache> Element

Sets the RequestCache instance which will be used by the ExceptionTranslationFilter to store request information before invoking an AuthenticationEntryPoint.spring-doc.cadn.net.cn

Parent Elements of <request-cache>

<request-cache> Attributes

<session-management>

Session-management related functionality is implemented by the addition of a SessionManagementFilter to the filter stack.spring-doc.cadn.net.cn

Parent Elements of <session-management>

<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.spring-doc.cadn.net.cn

  • invalid-session-url Setting this attribute will inject the SessionManagementFilter with a SimpleRedirectInvalidSessionStrategy configured with the attribute value. When an invalid session ID is submitted, the strategy will be invoked, redirecting to the configured URL.spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

  • session-authentication-strategy-ref Allows injection of the SessionAuthenticationStrategy instance used by the SessionManagementFilterspring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

    If session fixation protection is enabled, the SessionManagementFilter is injected with an appropriately configured DefaultSessionAuthenticationStrategy. See the Javadoc for this class for more details.spring-doc.cadn.net.cn

Child Elements of <session-management>

<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.spring-doc.cadn.net.cn

Parent Elements of <concurrency-control>

<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.spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

  • expired-url Allows injection of the ExpiredSessionStrategy instance used by the ConcurrentSessionFilterspring-doc.cadn.net.cn

  • max-sessions Maps to the maximumSessions的属性ConcurrentSessionControlAuthenticationStrategy. Specify -1 as the value to support unlimited sessions.spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

  • session-registry-ref The user can supply their own SessionRegistry implementation using the session-registry-ref attribute. The other concurrent session control beans will be wired up to use it.spring-doc.cadn.net.cn

<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.spring-doc.cadn.net.cn

Parent Elements of <x509>

<x509> Attributes

  • subject-principal-regex Defines a regular expression which will be used to extract the username from the certificate (for use with the UserDetailsService).spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

<filter-chain-map>

Used to explicitly configure a FilterChainProxy instance with a FilterChainMapspring-doc.cadn.net.cn

<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.spring-doc.cadn.net.cn

Child Elements of <filter-chain-map>

<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.spring-doc.cadn.net.cn

Parent Elements of <filter-chain>

<filter-chain> Attributes

  • filters A comma separated list of references to Spring beans that implement Filter. The value "none" means that no Filter should be used for this FilterChain.spring-doc.cadn.net.cn

  • 请求匹配器引用RequestMatcher that will be used to determine if any Filterfilters attribute should be invoked.spring-doc.cadn.net.cn

<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.spring-doc.cadn.net.cn

<filter-security-metadata-source> Attributes

  • 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.spring-doc.cadn.net.cn

  • 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.spring-doc.cadn.net.cn

Child Elements of <filter-security-metadata-source>


1. See the xref:servlet/configuration/xml-namespace.adoc#ns-web-xml[introductory chapter
2. This feature is really just provided for convenience and is not intended for production (where a view technology will have been chosen and can be used to render a customized login page). The class DefaultLoginPageGeneratingFilter is responsible for rendering the login page and will provide login forms for both normal form login and/or OIDC if required.
3. This doesn’t affect the use of PersistentTokenBasedRememberMeServices, where the tokens are stored on the server side.