我无法在Spnego下将Ubuntu VM配置为在Spring Security Web应用程序上单点登录。我做错了什么还是错过了什么?
我已经在Windows 7 VM上使用SSO,所以我认为它特定于Linux。
我的配置在下面详细说明。
下
我有四台运行在两种不同硬件上的机器:
WIN-SRV2008.company.local
:运行Windows Server 2008(硬件A )的VM KDC TOMCAT.company.local
:运行Tomcat 7
Web应用程序(硬件A )W7-CLIENT.company.local
:SSO 工作(硬件B )U-CLIENT.company.local
:SSO 不起作用的VM Ubuntu 17.10.1客户端(硬件B )SPN
我的SPN krb5.ini
和login.conf
基于this thread's description。
Spnego
除了删除表单登录信息外,我基本上遵循Spring Security Kerberos - Reference Documentation,
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${kerberos.service-principal}")
private String servicePrincipal;
@Value("${kerberos.keytab-location}")
private String keytabLocation;
@Override
protected void configure(HttpSecurity http) throws Exception {
AffirmativeBased affirmativeBased = new AffirmativeBased(Arrays.asList(new RoleVoter(),new WebExpressionVoter()));
http
.authorizeRequests().accessDecisionManager(affirmativeBased)
.anyRequest().authenticated()
.and()
.httpBasic()
.authenticationEntryPoint(entryPoint())
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.and()
.addFilterBefore(
spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
BasicAuthenticationFilter.class)
.sessionManagement()
.invalidSessionUrl("/login")
.maximumSessions(1)
.maxSessionsPreventsLogin(true)
.sessionRegistry(sessionRegistry());
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.authenticationProvider(kerberosAuthenticationProvider())
.authenticationProvider(kerberosServiceAuthenticationProvider());
}
@Bean
public SpnegoEntryPoint entryPoint() {
return new SpnegoEntryPoint();
}
@Bean
public KerberosAuthenticationProvider kerberosAuthenticationProvider() {
LoginKerberosAuthentication provider = new LoginKerberosAuthentication();
SunJaasKerberosClient client = new SunJaasKerberosClient();
client.setDebug(true);
provider.setKerberosClient(client);
provider.setUserDetailsService(usuarioDetailsService());
return provider;
}
@Bean
public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
AuthenticationManager authenticationManager) {
SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
filter.setAuthenticationManager(authenticationManager);
return filter;
}
@Bean
public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
provider.setTicketValidator(sunJaasKerberosTicketValidator());
provider.setUserDetailsService(usuarioDetailsService());
return provider;
}
@Bean
public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
ticketValidator.setServicePrincipal(servicePrincipal);
ticketValidator.setKeyTabLocation(new FileSystemResource(keytabLocation));
ticketValidator.setDebug(true);
return ticketValidator;
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public UsuarioDetailsService usuarioDetailsService() {
return new UsuarioDetailsService();
}
Ubuntu客户
要加入域,请按照以下步骤操作:
sudo apt-get install realmd krb5-user software-properties-common python-software-properties packagekit
sudo realm join COMPANY.local -U 'administrator@COMPANY.LOCAL' -v
直到我必须生成带有以下内容的kerberos票证:
kinit my_ubuntu_user@COMPANY.local
我实际上用klist
检查了缓存,该缓存输出:
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: my_ubuntu_user@COMPANY.local
Valid starting Expires Service principal
30/10/2018 17:25:47 31/10/2018 03:25:47 krbtgt/COMPANY.local@COMPANY.local
renew until 31/10/2018 17:25:43
最后,我成功使用以下方法进行了身份验证:
sudo su my_ubuntu_user@COMPANY.local
SSO-问题
当我尝试像使用Windows 7客户端一样使用Firefox(具有受信任的站点配置)访问我的应用程序主页时,我只得到the 401 Negotiate header,并且没有发送响应令牌。
这意味着,当我向SpnegoEntryPoint
构造函数输入实际的url时,我将重定向到此后备。
提前谢谢
答案 0 :(得分:0)
感谢参孙的评论,我得以使它生效。
我确实通过执行sudo su my_ubuntu_user@COMPANY.local
切换到空缓存,这使我的应用程序登录响应401。