嗯!
我在项目中使用 Spring Security 5 和 Kerberos 进行 SSO 身份验证。
在WebSecurityConfig
中我注册了两个AuthenticationProvider
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(msfUserDetailsService).passwordEncoder(passwordEncoder());
assertThatUnlimitedCryptographyEnabled();
// Two providers
auth.authenticationProvider(kerberosAuthenticationProvider());
auth.authenticationProvider(kerberosServiceAuthenticationProvider());
}
这似乎就是这两个示例中所示的完成方式:
- https://docs.spring.io/spring-security-kerberos/docs/current/reference/html/ssk-spnego.html
- https://www.ebayinc.com/stories/blogs/tech/customizing-spring-security-with-multiple-authentications/
但是我不明白为什么我需要它们。在身份验证期间,KerberosServiceAuthenticationProvider
负责验证 Kerberos 票证(请参阅 JavaDoc)
但是 KerberosAuthenticationProvider
的用途是什么? JavaDoc在这种情况下只是说
AuthenticationProvider for kerberos.
最佳答案
正如您所说:KerberosServiceAuthenticationProvider
用于验证 SSO 身份验证中的票证,而 KerberosAuthenticationProvider
用于基于表单的身份验证,通常在 SSO 时用作后备客户端不支持(例如 Linux 系统上的浏览器)。这种类型的身份验证由在 WebSecurityConfigurerAdapter
中应用的 UsernamePasswordAuthenticationFilter
处理:
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
...
.formLogin()
...
}
...
}
如果您不使用表单登录,那么您可以按照评论中的指示省略此提供程序。
关于java - KerberosAuthenticationProvider 与 KerberosServiceAuthenticationProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56152842/