【发布时间】:2018-05-19 03:53:21
【问题描述】:
我正在研究如何使用 LDAP 对客户端 ID 和客户端密码进行身份验证。
注意:这个 Kotlin 代码...
@Configuration
@EnableAuthorizationServer
class OAuth2AuthorizationServerConfig() : AuthorizationServerConfigurerAdapter() {
我对 Spring 比较陌生,看来这不是我应该尝试的事情?但是,这似乎是一个有用的选择。为什么?因为它允许我将客户端机密管理委托给 LDAP 目录,并且有效地允许我的运维团队更改机密(以某种托管方式)。有了这个,我的应用程序不需要知道秘密。这看起来很整洁?
oauth 端点是基本身份验证——这似乎是 Spring 通过 @EnableAuthorizationServer 注释给我的。对http://somehost/oauth/token 的请求指定grant_type:client_credentials。
我创建了代码来获取任意令牌(沙盒)...而我只想指定适用于该客户端的客户端和范围,不指定秘密.. .
@Throws(Exception::class)
override fun configure(
clients: ClientDetailsServiceConfigurer
) {
// Inlining will create a store per credential entry
val serviceBuilder = clients.inMemory()
serviceBuilder.withClient("user").secret("test").scopes("XXX")
}
我尝试了很多不同的想法来将LDAP Authentication Provider 添加到ProviderManager 中的托管提供程序集中,但到目前为止都失败了。如果我在运行时调试authenticate 方法,我总是只有AnonymousAuthenticationProvider 和DaoAuthenticationProvider
以下可能表明我缺乏经验,但这是一个示例,请阅读可能的疯狂 - 只是想看看我是否可以注入 LDAPAuthenticationProvider...
@Autowired
lateinit var providerMan: AuthenticationManager
@Throws(Exception::class)
override fun configure(endpoints: AuthorizationServerEndpointsConfigurer) {
(providerMan as ProviderManager).providers.add(0,
LdapAuthenticationProvider(
PasswordComparisonAuthenticator(PasswordPolicyAwareContextSource("ldap://something"))
)
)
}
因此问题相当简单...
有没有办法添加 LdapAuthenticationProvider 以便我可以使用 LDAP 来验证客户端 ID 和客户端密码?
【问题讨论】:
标签: spring-security spring-oauth2