本文介紹了帶Linux客戶端的401 SPNEGO SSO的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我無法在Spnego下的Spring Security Web應用程序上將我的Ubuntu VM配置為單點登錄。我做錯了什么嗎?還是我錯過了什么?
我已經在Windows 7虛擬機上進行了SSO,所以我相信它是特定于Linux的。
下面詳細介紹了我的配置。
基礎設施
我有四臺計算機,它們在兩個不同的硬件上運行:
WIN-SRV2008.company.local:運行Windows Server 2008的VM KDC(硬件A)TOMCAT.company.local:運行Tomcat 7Web應用程序(硬件A)W7-CLIENT.company.local:運行SSO的VM Windows 7客戶端(硬件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 '[email protected]' -v
直到我使用以下命令生成Kerberos票證:
kinit [email protected]
我實際使用klist檢查了緩存,結果是:
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: [email protected]
Valid starting Expires Service principal
30/10/2018 17:25:47 31/10/2018 03:25:47 krbtgt/[email protected]
renew until 31/10/2018 17:25:43
最后,我使用:
成功進行了身份驗證
sudo su [email protected]
SSO-問題
當我嘗試使用Firefox(使用受信任站點配置)訪問我的應用程序主頁時,就像我在Windows 7客戶端上所做的那樣,我只得到the 401 Negotiate header,并且不發送響應令牌。
這意味著,當我向SpnegoEntryPoint構造函數輸入實際的url時,我會被重定向到此回退。
提前謝謝您
推薦答案
多虧了Samson的評論,我才能讓它工作。
我確實通過執行sudo su [email protected]切換到空緩存,這使我的應用程序登錄響應401。
這篇關于帶Linux客戶端的401 SPNEGO SSO的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,






