(window.webpackJsonp=window.webpackJsonp||[]).push([[571],{1001:function(e,r,a){"use strict";a.r(r);var t=a(56),s=Object(t.a)({},(function(){var e=this,r=e.$createElement,a=e._self._c||r;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"认证服务"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#认证服务"}},[e._v("#")]),e._v(" 认证服务")]),e._v(" "),a("p",[e._v("这将创建 Spring Security 的"),a("code",[e._v("ProviderManager")]),e._v("类的实例,该实例需要配置一个或多个"),a("code",[e._v("AuthenticationProvider")]),e._v("实例的列表。这些可以使用名称空间提供的语法元素创建,也可以是标准 Bean 定义,标记为使用"),a("code",[e._v("authentication-provider")]),e._v("元素添加到列表中。")]),e._v(" "),a("h2",{attrs:{id:"authentication-manager"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#authentication-manager"}},[e._v("#")]),e._v(" ")]),e._v(" "),a("p",[e._v("每个使用命名空间的安全应用程序都必须在某个地方包含这个元素。它负责注册为应用程序提供身份验证服务的"),a("code",[e._v("AuthenticationManager")]),e._v("。所有创建"),a("code",[e._v("AuthenticationProvider")]),e._v("实例的元素都应该是这个元素的子元素。")]),e._v(" "),a("h3",{attrs:{id:"authentication-manager-属性"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#authentication-manager-属性"}},[e._v("#")]),e._v(" 属性")]),e._v(" "),a("ul",[a("li",[a("p",[a("strong",[e._v("别名")]),e._v("此属性允许你为内部实例定义别名,以便在你自己的配置中使用。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("擦除凭据")]),e._v("如果设置为 true,则一旦用户通过身份验证,身份验证管理器将尝试清除返回的身份验证对象中的任何凭据数据。从字面上看,它映射到["),a("code",[e._v("eraseCredentialsAfterAuthentication")]),e._v("]["),a("code",[e._v("ProviderManager")]),e._v("](.../authentication/architecture.html# Servlet-authentication-providermanager)的"),a("code",[e._v("eraseCredentialsAfterAuthentication")]),e._v("属性。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("身份证")]),e._v("此属性允许你为内部实例定义一个 ID,以便在你自己的配置中使用。它与 Alias 元素相同,但是对于使用 ID 属性的元素提供了更一致的体验。")])])]),e._v(" "),a("h3",{attrs:{id:"authentication-manager-的子元素"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#authentication-manager-的子元素"}},[e._v("#")]),e._v(" 的子元素")]),e._v(" "),a("ul",[a("li",[a("p",[a("a",{attrs:{href:"#nsa-authentication-provider"}},[e._v("身份验证提供者")])])]),e._v(" "),a("li",[a("p",[a("RouterLink",{attrs:{to:"/spring-security/ldap.html#nsa-ldap-authentication-provider"}},[e._v("LDAP-身份验证-提供者")])],1)])]),e._v(" "),a("h2",{attrs:{id:"authentication-provider"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#authentication-provider"}},[e._v("#")]),e._v(" ")]),e._v(" "),a("p",[e._v("除非与"),a("code",[e._v("ref")]),e._v("属性一起使用,否则此元素是用于配置"),a("code",[e._v("DaoAuthenticationProvider")]),e._v("的简写。"),a("code",[e._v("DaoAuthenticationProvider")]),e._v("从"),a("code",[e._v("UserDetailsService")]),e._v("加载用户信息,并将用户名/密码组合与登录时提供的值进行比较。"),a("code",[e._v("UserDetailsService")]),e._v("实例可以通过使用可用的名称空间元素("),a("code",[e._v("jdbc-user-service")]),e._v(")或通过使用"),a("code",[e._v("user-service-ref")]),e._v("属性指向应用程序上下文中其他地方定义的 Bean 来定义。")]),e._v(" "),a("h3",{attrs:{id:"authentication-provider-的父元素"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#authentication-provider-的父元素"}},[e._v("#")]),e._v(" 的父元素")]),e._v(" "),a("ul",[a("li",[a("a",{attrs:{href:"#nsa-authentication-manager"}},[e._v("身份验证管理器")])])]),e._v(" "),a("h3",{attrs:{id:"authentication-provider-属性"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#authentication-provider-属性"}},[e._v("#")]),e._v(" 属性")]),e._v(" "),a("ul",[a("li",[a("strong",[e._v("参考")]),e._v("定义了对实现"),a("code",[e._v("AuthenticationProvider")]),e._v("的 Spring Bean 的引用。")])]),e._v(" "),a("p",[e._v("如果你已经编写了自己的"),a("code",[e._v("AuthenticationProvider")]),e._v("实现(或者出于某种原因想将 Spring Security 自己的实现之一配置为传统的 Bean,那么你可以使用以下语法将其添加到"),a("code",[e._v("ProviderManager")]),e._v("的内部列表中:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n\n\n')])])]),a("ul",[a("li",[e._v("**user-service-ref **对实现可使用标准 Bean 元素或自定义用户服务元素创建的 UserDetailsService 的 Bean 的引用。")])]),e._v(" "),a("h3",{attrs:{id:"authentication-provider-的子元素"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#authentication-provider-的子元素"}},[e._v("#")]),e._v(" 的子元素")]),e._v(" "),a("ul",[a("li",[a("p",[a("a",{attrs:{href:"#nsa-jdbc-user-service"}},[e._v("JDBC-用户服务")])])]),e._v(" "),a("li",[a("p",[a("RouterLink",{attrs:{to:"/spring-security/ldap.html#nsa-ldap-user-service"}},[e._v("LDAP-用户服务")])],1)]),e._v(" "),a("li",[a("p",[a("a",{attrs:{href:"#nsa-password-encoder"}},[e._v("密码编码器")])])]),e._v(" "),a("li",[a("p",[a("a",{attrs:{href:"#nsa-user-service"}},[e._v("用户服务")])])])]),e._v(" "),a("h2",{attrs:{id:"jdbc-user-service"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#jdbc-user-service"}},[e._v("#")]),e._v(" ")]),e._v(" "),a("p",[e._v("导致创建基于 JDBC 的 UserDetailsService。")]),e._v(" "),a("h3",{attrs:{id:"jdbc-user-service-属性"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#jdbc-user-service-属性"}},[e._v("#")]),e._v(" 属性")]),e._v(" "),a("ul",[a("li",[a("strong",[e._v("权威用户名查询")]),e._v("一种 SQL 语句,用于查询给定用户名的用户授予的权限。")])]),e._v(" "),a("p",[e._v("默认值是")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("select username, authority from authorities where username = ?\n")])])]),a("ul",[a("li",[a("p",[e._v("**cache-ref **定义了对缓存的引用,以便与 UserDetailsService 一起使用。")])]),e._v(" "),a("li",[a("p",[e._v("**data-source-ref **提供所需表的数据源的 Bean ID。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("组-权限-按用户名-查询")]),e._v("一个 SQL 语句,用于查询给定用户名的用户组权限。默认值是")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("select\ng.id, g.group_name, ga.authority\nfrom\ngroups g, group_members gm, group_authorities ga\nwhere\ngm.username = ? and g.id = ga.group_id and g.id = gm.group_id\n")])])])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("身份证")]),e._v(" Bean 标识符,用于在上下文的其他地方引用 Bean。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("角色前缀")]),e._v("一个非空的字符串前缀,它将被添加到从持久存储加载的角色字符串中(默认为“role_”)。在默认值为非空的情况下,使用值“none”表示无前缀。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("用户按用户名查询")]),e._v("查询用户名、密码和给定用户名的已启用状态的 SQL 语句。默认值是")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("select username, password, enabled from users where username = ?\n")])])])])]),e._v(" "),a("h2",{attrs:{id:"password-encoder"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#password-encoder"}},[e._v("#")]),e._v(" ")]),e._v(" "),a("p",[e._v("身份验证提供者可以可选地被配置为使用"),a("RouterLink",{attrs:{to:"/features/authentication/password-storage.html#authentication-password-storage"}},[e._v("密码存储")]),e._v("中所述的密码编码器。这将导致 Bean 被注入适当的"),a("code",[e._v("PasswordEncoder")]),e._v("实例。")],1),e._v(" "),a("h3",{attrs:{id:"password-encoder-的父元素"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#password-encoder-的父元素"}},[e._v("#")]),e._v(" 的父元素")]),e._v(" "),a("ul",[a("li",[a("p",[a("a",{attrs:{href:"#nsa-authentication-provider"}},[e._v("身份验证提供者")])])]),e._v(" "),a("li",[a("p",[a("a",{attrs:{href:"#nsa-password-compare"}},[e._v("密码-比较")])])])]),e._v(" "),a("h3",{attrs:{id:"password-encoder-属性"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#password-encoder-属性"}},[e._v("#")]),e._v(" 属性")]),e._v(" "),a("ul",[a("li",[a("p",[a("strong",[e._v("散列")]),e._v("定义了用于用户密码的散列算法。我们强烈建议不要使用 MD4,因为它是一种非常弱的散列算法。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("参考")]),e._v("定义了对实现"),a("code",[e._v("PasswordEncoder")]),e._v("的 Spring Bean 的引用。")])])]),e._v(" "),a("h2",{attrs:{id:"user-service"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#user-service"}},[e._v("#")]),e._v(" ")]),e._v(" "),a("p",[e._v("从属性文件或“用户”子元素列表创建内存中的 UserDetailsService。用户名在内部被转换为小写字母,以允许不区分大小写的查找,因此如果需要区分大小写,则不应使用这种方法。")]),e._v(" "),a("h3",{attrs:{id:"user-service-属性"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#user-service-属性"}},[e._v("#")]),e._v(" 属性")]),e._v(" "),a("ul",[a("li",[a("p",[a("strong",[e._v("身份证")]),e._v("一个 Bean 标识符,用于在上下文的其他地方引用 Bean。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("属性")]),e._v("属性文件的位置,其中每行的格式为")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("username=password,grantedAuthority[,grantedAuthority][,enabled|disabled]\n")])])])])]),e._v(" "),a("h3",{attrs:{id:"user-service-的子元素"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#user-service-的子元素"}},[e._v("#")]),e._v(" 的子元素")]),e._v(" "),a("ul",[a("li",[a("a",{attrs:{href:"#nsa-user"}},[e._v("user")])])]),e._v(" "),a("h2",{attrs:{id:"user"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#user"}},[e._v("#")]),e._v(" ")]),e._v(" "),a("p",[e._v("表示应用程序中的用户。")]),e._v(" "),a("h3",{attrs:{id:"user-的父元素"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#user-的父元素"}},[e._v("#")]),e._v(" 的父元素")]),e._v(" "),a("ul",[a("li",[a("a",{attrs:{href:"#nsa-user-service"}},[e._v("用户服务")])])]),e._v(" "),a("h3",{attrs:{id:"user-属性"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#user-属性"}},[e._v("#")]),e._v(" 属性")]),e._v(" "),a("ul",[a("li",[a("p",[a("strong",[e._v("当局")]),e._v("授予用户的多个权限之一。用逗号(但没有空格)分隔权限。例如,“role_user,role_administrator”")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("已禁用")]),e._v("可以设置为“true”,以将帐户标记为禁用和不可用。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("锁定")]),e._v("可以设置为“true”,以标记帐户为锁定和不可用。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("姓名")]),e._v("分配给用户的用户名。")])]),e._v(" "),a("li",[a("p",[a("strong",[e._v("密码")]),e._v("分配给用户的密码。如果相应的身份验证提供程序支持散列(请记住设置“user-service”元素的“hash”属性),则可能会进行散列。如果数据不用于身份验证,而仅用于访问权限,则省略此属性。如果省略,命名空间将生成一个随机值,从而防止意外地将其用于身份验证。不能是空的。")])])]),e._v(" "),a("p",[a("RouterLink",{attrs:{to:"/spring-security/index.html"}},[e._v("XML 命名空间")]),a("RouterLink",{attrs:{to:"/spring-security/http.html"}},[e._v("网络安全")])],1)])}),[],!1,null,null,null);r.default=s.exports}}]);