spring-security-kerberos icon indicating copy to clipboard operation
spring-security-kerberos copied to clipboard

Migrate samples to spring-security 6.x

Open StephMirabel opened this issue 1 year ago • 0 comments

It would be nice to have the spring-security-kerberos-samples working with spring-security version 6.x. Some adaptations are required. E.g. in WebSecurityConfig.filterChain() the following changes worked for me in the sec-server-spnego-form-auth sample:

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
	KerberosAuthenticationProvider kerberosAuthenticationProvider = kerberosAuthenticationProvider();
	KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider = kerberosServiceAuthenticationProvider();
	ProviderManager providerManager = new ProviderManager(kerberosAuthenticationProvider,
				kerberosServiceAuthenticationProvider);

	http
		.authorizeHttpRequests((authz) -> authz
			.requestMatchers("/", "/home").permitAll()
			.anyRequest().authenticated()
		)
		.exceptionHandling(Customizer.withDefaults())
                .httpBasic(httpSecurityHttpBasicConfigurer ->
                        httpSecurityHttpBasicConfigurer.authenticationEntryPoint(spnegoEntryPoint()))
                .formLogin()
                        .loginPage("/login").permitAll()
		        .and()
		.logout()
		       .permitAll()
		       .and()
		.authenticationProvider(kerberosAuthenticationProvider())
		.authenticationProvider(kerberosServiceAuthenticationProvider())
		.addFilterBefore(spnegoAuthenticationProcessingFilter(providerManager),
					BasicAuthenticationFilter.class);
	return http.build();
}

StephMirabel avatar Feb 09 '24 16:02 StephMirabel