本文介紹了帶Linux客戶端的401 SPNEGO SSO的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我無(wú)法在Spnego下的Spring Security Web應(yīng)用程序上將我的Ubuntu VM配置為單點(diǎn)登錄。我做錯(cuò)了什么嗎?還是我錯(cuò)過(guò)了什么?
我已經(jīng)在Windows 7虛擬機(jī)上進(jìn)行了SSO,所以我相信它是特定于Linux的。
下面詳細(xì)介紹了我的配置。
基礎(chǔ)設(shè)施
我有四臺(tái)計(jì)算機(jī),它們?cè)趦蓚€(gè)不同的硬件上運(yùn)行:
WIN-SRV2008.company.local
:運(yùn)行Windows Server 2008的VM KDC(硬件A)TOMCAT.company.local
:運(yùn)行Tomcat 7
Web應(yīng)用程序(硬件A)W7-CLIENT.company.local
:運(yùn)行SSO的VM Windows 7客戶端(硬件B)U-CLIENT.company.local
:SSO無(wú)法工作的VM Ubuntu 17.10.1客戶端(硬件B)
SPN
我的SPN、krb5.ini
和login.conf
基于this thread’s description。
Spnego
我基本上遵循Spring Security Kerberos – Reference Documentation,只是去掉表單登錄,結(jié)果是:
@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客戶端
要加入域,我執(zhí)行了以下步驟:
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
我實(shí)際使用klist
檢查了緩存,結(jié)果是:
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
最后,我使用:
成功進(jìn)行了身份驗(yàn)證
sudo su my_ubuntu_user@COMPANY.local
SSO-問(wèn)題
當(dāng)我嘗試使用Firefox(使用受信任站點(diǎn)配置)訪問(wèn)我的應(yīng)用程序主頁(yè)時(shí),就像我在Windows 7客戶端上所做的那樣,我只得到the 401 Negotiate header,并且不發(fā)送響應(yīng)令牌。
這意味著,當(dāng)我向SpnegoEntryPoint
構(gòu)造函數(shù)輸入實(shí)際的url時(shí),我會(huì)被重定向到此回退。
提前謝謝您
推薦答案
多虧了Samson的評(píng)論,我才能讓它工作。
我確實(shí)通過(guò)執(zhí)行sudo su my_ubuntu_user@COMPANY.local
切換到空緩存,這使我的應(yīng)用程序登錄響應(yīng)401。
這篇關(guān)于帶Linux客戶端的401 SPNEGO SSO的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,