此版本仍在开发中,尚未被视为稳定版本。如需最新稳定版本,请使用 Spring Security 7.0.4spring-doc.cadn.net.cn

web应用安全

<debug>

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

<http>

如果在应用程序中使用了<http>元素,将会创建一个名为"springSecurityFilterChain"的FilterChainProxy bean,并且该元素内的配置将用于构建FilterChainProxy中的过滤器链。截至Spring Security 3。1, 额外的 http 元素可用于添加额外的过滤器链[1],以了解如何设置来自您的 web.xml 的映射。]某些核心过滤器总是会在过滤器链中创建,而其他过滤器则会根据存在的属性和子元素来添加到堆栈中。标准过滤器的位置是固定的(请参阅命名空间介绍中的过滤器顺序表),这消除了以往框架版本中用户必须在FilterChainProxy Bean 中显式配置过滤器链这一常见错误来源。您可以当然还可以这样做,如果您需要完全控制配置。spring-doc.cadn.net.cn

所有需要引用 AuthenticationManager 的过滤器,都将自动注入由命名空间配置创建的内部实例。spring-doc.cadn.net.cn

每个 <http> 命名空间块总是创建一个 SecurityContextPersistenceFilter,一个 ExceptionTranslationFilter 和一个 FilterSecurityInterceptor。 这些是固定的,不能用其他替代。spring-doc.cadn.net.cn

<http> 属性

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

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

  • authorization-manager-ref
    使用此AuthorizationManager,而不是从<intercept-url>元素派生一个
    spring-doc.cadn.net.cn

  • access-decision-manager-ref
    可选属性,指定应使用的AccessDecisionManager 实现的 ID,用于授权 HTTP 请求。
    默认情况下使用一个 AffirmativeBased 实现,并包含一个 RoleVoter 和一个 AuthenticatedVoterspring-doc.cadn.net.cn

  • authentication-manager-ref
    用于此http元素创建的AuthenticationManager所使用的FilterChain引用。spring-doc.cadn.net.cn

  • observation-registry-ref 一个对用于ObservationRegistry及相关组件的FilterChain的引用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 将不会创建会话,并且在获取 Spring Authentication 时忽略会话。spring-doc.cadn.net.cn

  • disable-url-rewriting
    防止会话ID被追加到应用程序中的URL。如果将此属性设置为true,客户端必须使用cookie。 默认值是truespring-doc.cadn.net.cn

  • entry-point-ref
    通常,根据已配置的认证机制,将会设置AuthenticationEntryPoint。此属性允许通过定义自定义的AuthenticationEntryPoint bean来覆盖这种行为,从而启动认证过程。spring-doc.cadn.net.cn

  • jaas-api-provision
    如果可用,将请求运行为从Subject获得的JaasAuthenticationToken。这可以通过向堆栈中添加一个JaasApiIntegrationFilter bean来实现。
    默认值为falsespring-doc.cadn.net.cn

  • once-per-request 对应于observeOncePerRequestFilterSecurityInterceptor属性。 默认值为false.spring-doc.cadn.net.cn

  • filter-all-dispatcher-types 对应于shouldFilterAllDispatcherTypesAuthorizationFilter属性。当use-authorization-manager=false时不生效。 默认值为true.spring-doc.cadn.net.cn

  • 模式 定义了 http 元素的模式控制了将通过其定义的过滤器列表进行过滤的请求。 该解释依赖于配置的 request-matcher。 如果没有定义模式,所有请求都将匹配,因此应首先声明最具体的模式。spring-doc.cadn.net.cn

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

  • redirect-to-https-request-matcher-ref 一个实现RequestMatcher接口的bean引用,用于确定哪些请求需要重定向到HTTPS。 这在例如希望本地运行HTTP而生产环境使用HTTPS时非常有帮助,可以通过请求头来判断。spring-doc.cadn.net.cn

  • request-matcher 定义了 RequestMatcher 策略,该策略用于 FilterChainProxy 以及由 intercept-url 创建的 Bean,以匹配传入的请求。 当前选项包括 mvcantregexciRegex,分别对应 Spring MVC、ant、正则表达式和不区分大小写的正则表达式。 每个 intercept-url 元素都会创建单独的实例,并使用其 patternmethodservlet-path 属性。 默认情况下,路径使用 PathPatternRequestMatcher 进行匹配;而正则表达式则使用 RegexRequestMatcher 进行匹配。 有关匹配的具体执行方式,请参阅这些类的 Javadoc 文档。 如果类路径中存在 Spring MVC,则 MVC 为默认策略;否则将使用 Ant 路径。spring-doc.cadn.net.cn

  • request-matcher-ref 一个实现RequestMatcher接口的bean引用,用于确定是否应该使用此FilterChain。 这比模式更强大的一种替代方案。spring-doc.cadn.net.cn

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

  • security-context-repository-ref
    允许将自定义的SecurityContextHolderStrategy注入到SecurityContextPersistenceFilterSecurityContextHolderFilterBasicAuthenticationFilterUsernamePasswordAuthenticationFilterExceptionTranslationFilterLogoutFilter以及其他过滤器中。spring-doc.cadn.net.cn

  • security-context-explicit-save 如果为 true,则使用 SecurityContextHolderFilter 而不是 SecurityContextPersistenceFilter。需要显式保存spring-doc.cadn.net.cn

  • security-context-repository-ref 允许将自定义的SecurityContextRepository注入到SecurityContextPersistenceFilter中。spring-doc.cadn.net.cn

  • servlet-api-provision 提供HttpServletRequest安全方法版本,例如isUserInRole()getPrincipal(),这些方法通过在堆栈中添加一个SecurityContextHolderAwareRequestFilter bean实现。 默认值为truespring-doc.cadn.net.cn

<access-denied-handler>

此元素允许您通过errorPage属性为AccessDeniedHandler使用的默认ExceptionTranslationFilter设置#nsa-access-denied-handler-error-page属性,或者使用#nsa-access-denied-handler-ref属性提供自己的实现。 这在关于xref page(异常转换过滤器)的章节中进行了更详细的讨论。spring-doc.cadn.net.cn

<access-denied-handler> 的父元素

<access-denied-handler> 属性

  • error-page 未授权页面:如果已认证用户请求一个他们没有权限访问的页面时,将被重定向到的拒绝访问页面。spring-doc.cadn.net.cn

<cors>

此元素允许配置一个 CorsFilter。 必须指定一个 CorsFilter 或者一个 CorsConfigurationSource。 如果存在 Spring MVC,则会尝试查找其 CorsConfigurationSourcespring-doc.cadn.net.cn

<cors> 属性

The attributes on the <cors> element 控制 the headers element.spring-doc.cadn.net.cn

  • cors-configuration-source-ref 可选属性,用于指定要注入到由XML命名空间创建的中的 bean名称。spring-doc.cadn.net.cn

<cors> 的父元素

<headers>

此元素允许配置附加(安全)头,以便与响应一起发送。 它使得为多个头进行简单配置变得容易,并且还允许通过 header 元素设置自定义头。 有关更多信息,请参阅参考中的 Security Headers(安全标头) 部分。spring-doc.cadn.net.cn

<headers> 属性

The attributes on the <headers> element 控制 the headers element.spring-doc.cadn.net.cn

  • defaults-disabled 可选属性,用于禁用Spring Security的HTTP响应头。默认情况下为false(包含默认头部)。spring-doc.cadn.net.cn

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

<headers>的父元素

<cache-control>

添加Cache-ControlPragmaExpires 头部,以确保浏览器不会缓存您的安全页面。spring-doc.cadn.net.cn

<cache-control> 属性

<cache-control>的父元素

<hsts>

当启用时,会对任何安全请求添加 Strict-Transport-Security 头。 这允许服务器指示浏览器在未来请求中自动使用 HTTPS。spring-doc.cadn.net.cn

<hsts> 属性

  • max-age-seconds 指定主机应被视为已知的HSTS(HTTP严格传输安全)主机的最大时间长度。默认值为一年。spring-doc.cadn.net.cn

  • request-matcher-ref
    The RequestMatcher 实例,用于确定是否应该设置该头信息。
    默认情况下,如果 HttpServletRequest.isSecure() 为 true,则会设置该头信息。spring-doc.cadn.net.cn

<hsts>的父元素

<hpkp>

当启用时,会在任何安全请求的响应中添加 公共密钥锁定扩展(Public Key Pinning Extension for HTTP) 头部。 这允许 HTTPS 网站抵御使用误发或其它欺诈性证书进行的攻击者的假冒行为。spring-doc.cadn.net.cn

<hpkp> 属性

  • max-age-seconds 设置 Public-Key-Pins 头的 max-age 指令的值。 默认 60 天。spring-doc.cadn.net.cn

<hpkp>的父元素

<pins>

列出的所有钉子spring-doc.cadn.net.cn

<pins>的子元素

<pin>

使用base64编码的SPKI指纹作为值,并且使用加密哈希算法作为属性。spring-doc.cadn.net.cn

<pin> 属性

<pin>的父元素

<content-security-policy>

当启用时,会在响应中添加 内容安全策略(CSP) 头。 CSP 是一种机制,网页应用程序可以通过这种方式来减轻内容注入漏洞的风险,例如跨站脚本攻击(XSS)。spring-doc.cadn.net.cn

<content-security-policy> 属性

  • policy-directives 安全策略指令用于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>

启用时会在响应中添加 Feature Policy 头部。spring-doc.cadn.net.cn

<feature-policy> 属性

<feature-policy>的父元素

<frame-options>

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

<frame-options> 属性

  • policyspring-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-disabled 不包含用于反射/类型-1跨站脚本攻击(XSS)保护的标头。spring-doc.cadn.net.cn

<xss-protection> 的父元素

<content-type-options>

在响应中添加 X-Content-Type-Options 头,并将其值设置为 nosniff。 这 禁用IE8及以上版本和Chrome扩展程序的MIME-sniffingspring-doc.cadn.net.cn

<content-type-options> 属性

<content-type-options>的父元素

<cross-origin-embedder-policy>

当启用时,会在响应中添加 Cross-Origin-Embedder-Policy 头。spring-doc.cadn.net.cn

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

<cross-origin-opener-policy>

当启用时,在响应中添加 Cross-Origin-Opener-Policy 头。spring-doc.cadn.net.cn

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

<cross-origin-resource-policy>

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

<header>

在响应中添加额外的标头,名称和值都需要指定。spring-doc.cadn.net.cn

<header-attributes> 属性

<header>的父元素

<anonymous>

添加一个 AnonymousAuthenticationFilter 到栈中,并且添加一个 AnonymousAuthenticationProvider。 如果使用了 IS_AUTHENTICATED_ANONYMOUSLY 属性,则必需这样做。spring-doc.cadn.net.cn

<anonymous>的父元素

<anonymous> 属性

  • 启用 在默认命名空间设置下,匿名的“身份验证”功能会自动启用。您可以使用此属性禁用它。spring-doc.cadn.net.cn

  • 授予的权限
    The granted authority that should be assigned to the anonymous request. Commonly this is used to assign the anonymous request particular roles, which can subsequently be used in authorization decisions. If unset, defaults to ROLE_ANONYMOUS.spring-doc.cadn.net.cn

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

  • 用户名 The username that should be assigned to the anonymous request. This allows the principal to be identified, which may be important for logging and auditing. If unset, defaults to anonymousUser.spring-doc.cadn.net.cn

<csrf>

此元素将为应用程序添加跨站请求伪造(CSRF)保护。 它还会更新默认的RequestCache,仅在成功身份验证后重播"GET"请求。 有关更多信息,请参阅参考中的跨站请求伪造(CSRF)部分。spring-doc.cadn.net.cn

<csrf>的父元素

<csrf> 属性

  • 禁用
    可选属性,指定是否禁用Spring Security的CSRF保护。默认情况下是禁用状态(即CSRF保护启用)。强烈建议保留CSRF保护功能。spring-doc.cadn.net.cn

  • token-repository-ref 使用的身份验证Tokens存储库。 默认值是HttpSessionCsrfTokenRepositoryspring-doc.cadn.net.cn

  • request-handler-ref 使用此可选的CsrfTokenRequestHandler。默认值是CsrfTokenRequestAttributeHandlerspring-doc.cadn.net.cn

  • request-matcher-ref
    The RequestMatcher 实例,用于确定是否应用 CSRF 保护。
    默认情况下,除了spring-doc.cadn.net.cn

<custom-filter>

此元素用于向过滤器链中添加一个过滤器。 它不会创建任何额外的bean,而是从应用程序上下文中选择一个类型为jakarta.servlet.Filter的bean,并在Spring Security维护的过滤器链中的特定位置添加该过滤器。 有关更多信息,请参阅命名空间章节spring-doc.cadn.net.cn

<custom-filter>的父元素

<custom-filter> 属性

  • after 在该自定义过滤器之后立即放置的过滤器。 只有高级用户才可能需要将自己的过滤器混入安全过滤链中,并且对标准Spring Security过滤器有一定的了解。 过滤器名称对应于特定的Spring Security实现过滤器。spring-doc.cadn.net.cn

  • 位置 在过滤器链中显式指定自定义过滤器应放置的位置。如果您正在替换标准过滤器,请使用此选项。spring-doc.cadn.net.cn

<expression-handler>

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

<expression-handler> 属性

  • ref 定义了一个引用Spring Bean的元素,该Bean实现了SecurityExpressionHandler接口。spring-doc.cadn.net.cn

<form-login>

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

<form-login>的父元素

<form-login> 属性

  • always-use-default-target
    如果设置为true,用户将始终从default-target-url指定的值开始,无论他们是如何到达登录页面的。
    映射到#nsa-form-login-default-target-urlalwaysUseDefaultTargetUrl属性。
    默认值为UsernamePasswordAuthenticationFilterspring-doc.cadn.net.cn

  • authentication-details-source-ref 参考一个AuthenticationDetailsSource,该对象将被认证过滤器使用spring-doc.cadn.net.cn

  • authentication-failure-handler-ref 可以作为authentication-failure-url的替代方案,让您在认证失败后完全控制导航流程。 该值应该是应用程序上下文中一个#nsa-form-login-authentication-failure-url bean 的名称。spring-doc.cadn.net.cn

  • authentication-failure-url
    映射到authenticationFailureUrlUsernamePasswordAuthenticationFilter属性。
    定义在登录失败时浏览器将被重定向到的URL。
    默认值为/login?error,这将会自动由自动登录页面生成器处理,重新渲染登录页面并显示错误消息。spring-doc.cadn.net.cn

  • authentication-success-handler-ref
    此属性可以作为替代方案,用于default-target-urlalways-use-default-target,从而在成功认证后为您提供完整的导航流程控制。 值应该为应用程序上下文中一个#nsa-form-login-default-target-url bean 的名称。
    默认情况下,会使用并注入default-target-url#nsa-form-login-always-use-default-target 实现。spring-doc.cadn.net.cn

  • default-target-url 映射到defaultTargetUrlUsernamePasswordAuthenticationFilter属性。 如果没有设置,默认值是“/”(应用程序根目录)。 用户在登录后会被重定向到这个URL,前提是他们在尝试访问受保护资源时没有被要求进行登录;如果他们试图访问一个受保护的资源而需要登录,则会被重定向到原始请求的URL。spring-doc.cadn.net.cn

  • login-processing-url
    映射到filterProcessesUrlUsernamePasswordAuthenticationFilter属性。
    默认值是"/login".
    spring-doc.cadn.net.cn

  • 认证成功转发URL
    将一个ForwardAuthenticationSuccessHandler映射到authenticationSuccessHandlerUsernamePasswordAuthenticationFilter属性。spring-doc.cadn.net.cn

  • authentication-failure-forward-url 将一个ForwardAuthenticationFailureHandler映射到authenticationFailureHandlerUsernamePasswordAuthenticationFilter属性。spring-doc.cadn.net.cn

<oauth2-login>

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

<oauth2-login>的父元素

<oauth2-login> 属性

  • jwt-decoder-factory-ref
    JwtDecoderFactory 的引用,该引用被 OidcAuthorizationCodeAuthenticationProvider 使用。spring-doc.cadn.net.cn

<oauth2-client>

oauth2-client 的父元素

<oauth2-client> 属性

<authorization-code-grant>

<authorization-code-grant>的父元素

<authorization-code-grant> 属性

<client-registrations>

一个容器元素,用于包含已注册(ClientRegistration)的客户端,这些客户端与OAuth 2.0或OpenID Connect 1.0提供者进行了注册。spring-doc.cadn.net.cn

<client-registration>

代表已注册到OAuth 2.0或OpenID Connect 1.0提供者的客户端。spring-doc.cadn.net.cn

<client-registration>的父元素

<client-registration> 属性

  • client-authentication-method
    客户端与提供者进行身份验证的方法。支持的值包括 client_secret_basic, client_secret_post, private_key_jwt, client_secret_jwtnone公开客户端)。spring-doc.cadn.net.cn

  • 授权许可类型
    The OAuth 2.0 授权框架定义了四种 授权许可 类型。
    支持的值包括 authorization_codeclient_credentialspassword,以及扩展许可类型 urn:ietf:params:oauth:grant-type:jwt-bearerspring-doc.cadn.net.cn

  • redirect-uri
    The client’s registered redirect URI that the 授权服务器在终端用户完成身份验证并授权访问客户端后,将终端用户的用户代理重定向到的地址。spring-doc.cadn.net.cn

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

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

  • provider-id 对相关提供者的引用。可以引用一个<provider>元素或使用其中一个通用提供者(google、github、facebook、okta)。spring-doc.cadn.net.cn

<provider>

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

<provider> 属性

  • 用户信息端点URI 用于访问已认证终端用户的声明/属性的UserInfo端点URI。spring-doc.cadn.net.cn

  • user-info-authentication-method
    发送访问Tokens到UserInfo Endpoint时使用的身份验证方法。支持的值是 header, formqueryspring-doc.cadn.net.cn

  • user-info-user-name-attribute 该属性名称在UserInfo响应中引用最终用户的姓名或标识。spring-doc.cadn.net.cn

<oauth2-resource-server>

添加一个BearerTokenAuthenticationFilterBearerTokenAuthenticationEntryPointBearerTokenAccessDeniedHandler到配置中。
此外,必须指定<jwt><opaque-token>spring-doc.cadn.net.cn

oauth2-resource-server 的父元素

<oauth2-resource-server> 属性

  • authentication-manager-resolver-ref
    参考一个AuthenticationManagerResolver,它将在请求时间解析AuthenticationManagerspring-doc.cadn.net.cn

  • bearer-token-resolver-ref
    引用一个BearerTokenResolver,用于从请求中检索bearerTokens。这不能与authentication-converter-ref同时使用。spring-doc.cadn.net.cn

  • authentication-converter-ref
    引用一个AuthenticationConverter,用于将请求转换为认证。此配置不能与bearer-token-resolver-ref同时使用。spring-doc.cadn.net.cn

<jwt>

代表一个OAuth 2.0资源服务器,该服务器将授权JWTspring-doc.cadn.net.cn

<jwt> 属性

  • jwt-authentication-converter-ref 参考一个Converter<Jwt, AbstractAuthenticationToken>spring-doc.cadn.net.cn

  • jwt-decoder-ref 参考一个 JwtDecoder。这是一个较大的组件,会覆盖 jwk-set-urispring-doc.cadn.net.cn

  • jwk-set-uri 用于从 OAuth 2.0 授权服务器加载签名验证密钥的 JWK 集合 Urispring-doc.cadn.net.cn

<opaque-token>

代表一个OAuth 2.0资源服务器,该服务器将授权密Tokensspring-doc.cadn.net.cn

<opaque-token> 属性

  • introspector-ref
    参考一个OpaqueTokenIntrospector。这是一个较大的组件,会覆盖introspection-uriclient-idclient-secretspring-doc.cadn.net.cn

  • introspection-uri 用于反向查询不透明Tokens详细信息的 Introspection Uri。应与 client-idclient-secret 配合使用。spring-doc.cadn.net.cn

  • 客户端ID
    The Client Id to use for client authentication against the provided introspection-uri.spring-doc.cadn.net.cn

  • 客户端密钥 用于根据提供的 introspection-uri 进行客户端身份验证的客户端密钥。spring-doc.cadn.net.cn

  • authentication-converter-ref
    参考一个OpaqueTokenAuthenticationConverter。负责将成功的introspection结果转换为一个Authentication实例。spring-doc.cadn.net.cn

<relying-party-registrations>

依靠方(一个或多个)已注册(ClientRegistration)并使用 SAML 2.0 身份提供者的容器元素。spring-doc.cadn.net.cn

<relying-party-registrations> 属性

<relying-party-registration>

代表已注册于SAML 2.0 身份提供者的一方依赖方spring-doc.cadn.net.cn

<relying-party-registration>的父元素

<relying-party-registration> 属性

  • assertion-consumer-service-location AssertionConsumerService Location。等同于在依赖方的<AssertionConsumerService Location="…​"/>中找到的<SPSSODescriptor>的值。spring-doc.cadn.net.cn

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

  • single-logout-service-location 单.logout服务位置。等同于在依赖方的<SPSSODescriptor>中找到的<SingleLogoutService Location=spring-doc.cadn.net.cn

  • single-logout-service-response-location 单点注销服务响应位置。等同于在依赖方的<SPSSODescriptor>中找到的<SingleLogoutService ResponseLocation=spring-doc.cadn.net.cn

  • single-logout-service-binding SingleLogoutService 绑定。等同于在依赖方的 <SPSSODescriptor> 中找到的 <SingleLogoutService Binding=spring-doc.cadn.net.cn

  • asserting-party-id
    一个关联授权方的引用。必须引用一个<asserting-party>元素。spring-doc.cadn.net.cn

<decryption-credential>

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

<decryption-credential>的父元素

<decryption-credential> 属性

<signing-credential>

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

<verification-credential>的父元素

<verification-credential> 属性

<asserting-party>

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

<asserting-party> 属性

  • want-authn-requests-signedWantAuthnRequestsSigned设置表示声明方希望认证方在发送前对AuthnRequest进行签名。spring-doc.cadn.net.cn

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

  • single-logout-service-location 单点注销服务位置。等同于断言方的<IDPSSODescriptor>中<SingleLogoutService Location=spring-doc.cadn.net.cn

  • single-logout-service-response-location SingleLogoutService 响应位置。相当于在认证方的 中找到的 <SingleLogoutService ResponseLocation=spring-doc.cadn.net.cn

<encryption-credential>

与声明方关联的加密凭据。spring-doc.cadn.net.cn

<encryption-credential>的父元素

<encryption-credential> 属性

<verification-credential>

与声明方相关的验证凭据。spring-doc.cadn.net.cn

<verification-credential>的父元素

<verification-credential> 属性

<http-basic>

添加一个BasicAuthenticationFilterBasicAuthenticationEntryPoint到配置中。 后者仅在不启用表单登录时作为配置入口点使用。spring-doc.cadn.net.cn

<http-basic> 的父元素

<http-basic> 属性

  • authentication-details-source-ref 参考一个AuthenticationDetailsSource,该对象将被认证过滤器使用spring-doc.cadn.net.cn

  • entry-point-ref 设置 AuthenticationEntryPoint 使用的 BasicAuthenticationFilterspring-doc.cadn.net.cn

<http-firewall> 元素

这是一项顶级元素,可以用于向由命名空间创建的HttpFirewall注入自定义实现的FilterChainProxy。 默认实现对于大多数应用程序来说通常是合适的。spring-doc.cadn.net.cn

<http-firewall> 属性

<intercept-url>

此元素用于定义应用程序感兴趣的 URL 模式集合,并配置它们应如何处理。 它用于构建由 FilterInvocationSecurityMetadataSource 使用的 FilterSecurityInterceptor。 它还负责在某些 URL 需要通过 HTTPS 访问时配置一个 ChannelProcessingFilter,例如。 当将指定模式与传入请求进行匹配时,匹配顺序是按照该元素声明的顺序进行的。 因此,最具体的模式应首先出现,而最通用的模式应最后出现。spring-doc.cadn.net.cn

<intercept-url> 属性

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

  • method 该 HTTP 方法将与模式和 servlet 路径(可选)一起用于匹配传入请求。 如果未省略,任何方法都将匹配。 如果指定了具有相同模式但没有方法的配置,则具体到方法的匹配将优先。spring-doc.cadn.net.cn

  • 模式 定义URL路径的模式。内容将取决于包含的 request-matcher 属性,因此如果没有在类路径中找到 Spring MVC,则会默认使用 MVC 匹配器。spring-doc.cadn.net.cn

  • request-matcher-ref 一个引用,用于确定此<intercept-url>是否被使用。 其中RequestMatcher<intercept-url>需要根据具体上下文进行替换。spring-doc.cadn.net.cn

  • requires-channel
    可以是 "http" 或 "https",具体取决于某个 URL 模式应通过 HTTP 还是 HTTPS 访问。
    或者当没有偏好时可以使用值 "any"。
    如果在任何 <intercept-url> 元素上存在此属性,则会在过滤器堆栈中添加一个 ChannelProcessingFilter,并将其附加依赖项添加到应用程序上下文中。spring-doc.cadn.net.cn

如果添加了<port-mappings>配置,这将被SecureChannelProcessorInsecureChannelProcessor bean用于确定重定向到HTTP/HTTPS所使用的端口。spring-doc.cadn.net.cn

  • servlet-path 该servlet路径将与模式和HTTP方法一起用于匹配传入请求。 此属性仅在request-matcher为'mvc'时适用。 此外,当且仅当存在以下两种情况之一时才需要设置值:1)在#nsa-http-request-matcher中注册了两个或多个具有以HttpServlet开头的映射关系的不同ServletContext;2)模式以已注册的'/'路径中的相同值开始(不包括默认根路径HttpServlet)。spring-doc.cadn.net.cn

<jee>

添加一个J2eePreAuthenticatedProcessingFilter到过滤器链中,以实现与容器认证的集成。spring-doc.cadn.net.cn

<jee> 的父元素

<jee> 属性

  • mappable-roles
    逗号分隔的角色列表,在传入的HttpServletRequest中查找。spring-doc.cadn.net.cn

<logout>

向过滤器堆栈添加一个LogoutFilter。这使用了一个SecurityContextLogoutHandler进行配置。spring-doc.cadn.net.cn

<logout>的父元素

<logout> 属性

  • 删除cookie
    逗号分隔的列表,表示应在用户注销时被删除的cookie名称。spring-doc.cadn.net.cn

  • invalidate-session 映射到invalidateHttpSessionSecurityContextLogoutHandler。 默认值为"true",因此在注销时将失效会话。spring-doc.cadn.net.cn

  • logout-success-url 用户登出后将被重定向到的目的URL。 默认值为 <form-login-login-page>/?logout(即 /login?logout)spring-doc.cadn.net.cn

    设置此属性将注入SessionManagementFilter,并配置一个SimpleRedirectInvalidSessionStrategy,其行为由该属性值决定。 当提交无效的会话ID时,该策略会被调用,并重定向到配置的URL。spring-doc.cadn.net.cn

  • 注销URL 该URL将导致用户退出登录(即,该URL将被过滤器处理)。 默认值为“/logout”。spring-doc.cadn.net.cn

  • success-handler-ref
    可以用于提供一个LogoutSuccessHandler的实例,该实例将在注销后被调用来控制导航。spring-doc.cadn.net.cn

<saml2-login>

The SAML 2.0 登录 功能配置了使用 SAML 2.0 服务提供商的支持身份验证。spring-doc.cadn.net.cn

<saml2-login>的父元素

<saml2-login> 属性

  • relying-party-registration-repository-ref
    参考 RelyingPartyRegistrationRepositoryspring-doc.cadn.net.cn

  • authentication-request-repository-ref
    对应的 Saml2AuthenticationRequestRepository 的引用。spring-doc.cadn.net.cn

  • authentication-request-context-resolver-ref
    参考 Saml2AuthenticationRequestResolverspring-doc.cadn.net.cn

<saml2-logout>

The SAML 2.0 单点注销 功能配置支持 RP-和 AP 初始化的 SAML 2.0 单点注销。spring-doc.cadn.net.cn

<saml2-logout> 的父元素

<saml2-logout> 属性

  • relying-party-registration-repository-ref
    参考 RelyingPartyRegistrationRepositoryspring-doc.cadn.net.cn

<password-management>

此元素配置密码管理。spring-doc.cadn.net.cn

<password-management>的父元素

<password-management> 属性

<port-mappings>

默认情况下,将会为重定向到安全和非安全URL而配置一个PortMapperImpl实例。 此元素可选地用于覆盖该类定义的默认映射。 每个<port-mapping>子元素定义了一对HTTP:HTTPS端口。 默认映射是80:443和8080:8443。 有关如何覆盖这些默认映射的一个示例可以在重定向到HTTPS中找到。spring-doc.cadn.net.cn

<port-mappings>的父元素

<port-mappings>的子元素

<port-mapping>

提供一个方法将 HTTP 端口映射到 HTTPS 端口,以强制重定向。spring-doc.cadn.net.cn

<port-mapping>的父元素

<port-mapping> 属性

<remember-me>

RememberMeAuthenticationFilter添加到过滤器栈中。 这将会根据属性设置,配置为TokenBasedRememberMeServicesPersistentTokenBasedRememberMeServices或一个用户指定的实现RememberMeServices的bean。spring-doc.cadn.net.cn

<remember-me> 的父元素

<remember-me> 属性

  • authentication-success-handler-ref 设置 authenticationSuccessHandlerRememberMeAuthenticationFilter 属性,如果需要自定义导航。 该值应该是应用程序上下文中一个 AuthenticationSuccessHandler bean 的名称。spring-doc.cadn.net.cn

  • data-source-ref 一个对 DataSource bean 的引用。如果设置了此属性,PersistentTokenBasedRememberMeServices 将被使用,并配置为使用一个 JdbcTokenRepositoryImpl 实例。spring-doc.cadn.net.cn

  • remember-me-parameter
    The name of the request parameter which toggles remember-me authentication.
    Defaults tospring-doc.cadn.net.cn

  • key 映射到 AbstractRememberMeServices 的“key”属性。 应设置为唯一值,以确保记住我的 Cookie 仅在单一应用程序内有效[3]。 如果未设置此值,将生成一个安全的随机值。 由于生成安全随机值可能需要一些时间,显式设置此值有助于在使用记住我的功能时提高启动速度。spring-doc.cadn.net.cn

  • services-alias 导出了内部定义的 RememberMeServices 作为别名bean,允许其他应用上下文中的bean使用它。spring-doc.cadn.net.cn

  • services-ref
    允许对将由过滤器使用的RememberMeServices实现进行完全控制。
    The value should be the id of a bean in the application context which implements this interface.
    如果使用了注销过滤器,还应该实现LogoutHandler接口。spring-doc.cadn.net.cn

  • token-repository-ref
    配置一个PersistentTokenBasedRememberMeServices,但允许使用自定义的PersistentTokenRepository bean。spring-doc.cadn.net.cn

  • token-validity-seconds
    映射到tokenValiditySecondsAbstractRememberMeServices属性。
    指定记住我cookie的有效期(以秒为单位)。
    默认情况下,它的有效期为14天。spring-doc.cadn.net.cn

  • user-service-ref 记住我服务的实现需要访问一个UserDetailsService,因此必须在应用程序上下文中定义一个。 如果只有一个,它将被命名空间配置自动选择和使用。 如果有多个实例,您可以使用此属性显式指定一个beanidspring-doc.cadn.net.cn

<request-cache> 元素

设置RequestCache实例,该实例将被ExceptionTranslationFilter用于在调用AuthenticationEntryPoint之前存储请求信息。spring-doc.cadn.net.cn

<request-cache> 的父元素

<request-cache> 属性

<session-management>

会话管理相关的功能通过在过滤器栈中添加一个SessionManagementFilter实现。spring-doc.cadn.net.cn

<session-management>的父元素

<session-management> 属性

  • authentication-strategy-explicit-invocation 将此属性设置为 true 将意味着 SessionManagementFilter 不会被注入,需要显式调用 SessionAuthenticationStrategy。spring-doc.cadn.net.cn

  • invalid-session-url 设置此属性将注入SessionManagementFilter一个配置了属性值的SimpleRedirectInvalidSessionStrategy。 当提交无效会话ID时,策略将会被调用,重定向到配置的URL。spring-doc.cadn.net.cn

  • 无效会话URL 允许注入由SessionManagementFilter使用的InvalidSessionStrategy实例。 请使用此选项或invalid-session-url属性之一,但不能同时使用两者。spring-doc.cadn.net.cn

  • session-authentication-error-url 定义了当会话认证策略抛出异常时应显示的错误页面URL。 如果没有设置该属性,将会向客户端返回未授权(401)错误代码。 注意,如果错误发生在基于表单的登录过程中,则此属性不会生效,并且将优先使用验证失败时的URL。spring-doc.cadn.net.cn

  • session-authentication-strategy-ref 允许注入由SessionManagementFilter使用的SessionAuthenticationStrategy实例spring-doc.cadn.net.cn

  • session-fixation-protection
    表示在用户认证时将如何应用会话固定保护。 如果设置为"none",则不会应用任何保护措施。
    "newSession" 将创建一个新的空会话,并仅迁移与 Spring Security 相关的属性。
    "migrateSession" 将创建一个新的会话并复制所有会话属性到新会话。
    在 Servlet 3.1 (Java EE 7) 及更新版本的容器中,指定 "changeSessionId" 将保留现有会话,并使用容器提供的会话固定保护(HttpServletRequest#changeSessionId())。 默认情况下,在 Servlet 3.1 及更新版本的容器中设置为 "changeSessionId",在较旧的容器中设置为 "migrateSession"。
    如果在较旧的容器中使用 "changeSessionId" 将抛出异常。spring-doc.cadn.net.cn

    如果启用了会话固定保护,SessionManagementFilter 将注入一个适当配置的 DefaultSessionAuthenticationStrategy。 请参阅此类的 Javadoc 获取更多详细信息。spring-doc.cadn.net.cn

<session-management>的子元素

<concurrency-control>

添加对并发会话控制的支持,允许为用户可以拥有的活动会话数量设置限制。 一个 ConcurrentSessionFilter 将被创建,并且使用 ConcurrentSessionControlAuthenticationStrategySessionManagementFilter。 如果声明了 form-login 元素,策略对象也将注入到创建的认证过滤器中。 将为策略创建一个 SessionRegistry 实例(除非用户希望使用自定义 bean,默认为 SessionRegistryImpl 实例)。spring-doc.cadn.net.cn

<concurrency-control>的父元素

<concurrency-control> 属性

  • expired-url
    允许注入由会话过滤器(ConcurrentSessionFilter)使用的已过期会话策略实例(ExpiredSessionStrategy)。spring-doc.cadn.net.cn

  • max-sessions
    映射到maximumSessionsConcurrentSessionControlAuthenticationStrategy属性。
    将值指定为-1以支持无限会话。spring-doc.cadn.net.cn

  • max-sessions-ref
    允许注入由并发会话控制认证策略(ConcurrentSessionControlAuthenticationStrategy)使用的 SessionLimit 实例。spring-doc.cadn.net.cn

  • session-registry-alias
    它也可以在自己的bean或管理界面中使用时对内部会话注册表进行引用很有用。
    您可以使用session-registry-alias属性暴露内部bean,并为其指定一个名称,以便您可以在配置的其他地方使用此名称。spring-doc.cadn.net.cn

  • session-registry-ref 用户可以使用SessionRegistry属性提供自己的session-registry-ref实现。其他并发会话控制bean将会被配置为使用它。spring-doc.cadn.net.cn

<x509>

添加对X.509认证的支持。 将会在栈中增加一个X509AuthenticationFilter,并且会创建一个Http403ForbiddenEntryPoint bean。 仅当没有其他认证机制在使用时才会使用后者(它的唯一功能是返回HTTP 403错误代码)。 还会创建一个PreAuthenticatedAuthenticationProvider,该提供程序将用户权限的加载委托给一个UserDetailsServicespring-doc.cadn.net.cn

<x509>的父元素

<x509> 属性

  • principal-extractor-ref 参考一个的引用,该引用将被认证过滤器使用。spring-doc.cadn.net.cn

  • subject-principal-regex 定义一个正则表达式,用于从证书中提取用户名(与UserDetailsService配合使用)。spring-doc.cadn.net.cn

  • user-service-ref 允许在配置了多个实例的情况下,使用特定的 UserDetailsService 与 X.509 结合。如果未设置,则会尝试自动定位一个合适的实例并使用该实例。spring-doc.cadn.net.cn

<filter-chain-map>

用于显式配置一个FilterChainProxy实例与一个FilterChainMapspring-doc.cadn.net.cn

<filter-chain-map> 属性

  • request-matcher 定义用于匹配传入请求的策略。 当前可用选项包括 'ant'(用于 ant 路径模式)、'regex' 用于正则表达式和 'ciRegex' 用于大小写不敏感的正则表达式。spring-doc.cadn.net.cn

<filter-chain-map>的子元素

<filter-chain>

用于定义特定的URL模式以及适用该模式URL的过滤器列表。 在配置FilterChainProxy时,当多个filter-chain元素被按顺序排列成一个列表时,最具体的模式应放在列表顶部,而最通用的模式则放在底部。spring-doc.cadn.net.cn

<filter-chain>的父元素

<filter-chain> 属性

  • 过滤器 一个逗号分隔的 Spring bean 引用列表,这些 bean 实现了 Filter。 值为 \"none\" 表示此 FilterChain 不应使用任何 Filterspring-doc.cadn.net.cn

  • request-matcher-ref
    一个用于确定是否应该调用RequestMatcher属性中的任何Filterfilters引用。spring-doc.cadn.net.cn

<filter-security-metadata-source>

用于显式配置 FilterSecurityMetadataSource bean,以便与 FilterSecurityInterceptor 配合使用。 通常只有在您显式配置 FilterChainProxy 而不是使用 <http> 元素时才需要这样做。 使用的 intercept-url 元素应仅包含 pattern、method 和 access 属性。 任何其他属性都可能导致配置错误。spring-doc.cadn.net.cn

<filter-security-metadata-source> 属性

  • request-matcher 定义了用于匹配传入请求的策略。 目前可选的方式有 'ant'(适用于 ant 路径模式)、'regex' 用于正则表达式和 'ciRegex' 用于大小写不敏感的正则表达式。spring-doc.cadn.net.cn

  • use-expressions
    启用在<intercept-url>元素的'access'属性中使用表达式,而不是传统的配置属性。
    默认值为'true'。
    如果启用,每个属性应该包含一个单一的布尔表达式。
    如果该表达式评估为'true',则将授予访问权限。spring-doc.cadn.net.cn

<filter-security-metadata-source> 的子元素


1. 查看入门章节 [使用 XML 配置的 Servlet 容器设置]
2. 此功能仅用于方便,不建议在生产环境中使用(因为在生产环境中会选择并使用视图技术来渲染自定义登录页面)。类 DefaultLoginPageGeneratingFilter 负责渲染登录页面,并将为需要时提供常规表单登录和/或 OIDC 的登录表单。
3. 这不影响PersistentTokenBasedRememberMeServices的使用,其中Tokens存储在服务器端。