JAVA-39: Moved article from spring-security kerberos module to
spring-security-sso/spring-security-sso-kerberos
This commit is contained in:
parent
89ea700e24
commit
97fa800bbd
@ -1,3 +1,4 @@
|
|||||||
## Relevant articles:
|
## Relevant articles:
|
||||||
|
|
||||||
- [Spring Security Kerberos Integration](https://www.baeldung.com/spring-security-kerberos-integration)
|
- [Spring Security Kerberos Integration](https://www.baeldung.com/spring-security-kerberos-integration)
|
||||||
|
- [Introduction to SPNEGO/Kerberos Authentication in Spring](https://www.baeldung.com/spring-security-kerberos)
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.intro;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package com.baeldung.intro.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
|
||||||
|
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
|
||||||
|
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
||||||
|
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
|
||||||
|
import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
|
||||||
|
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
||||||
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||||
|
|
||||||
|
import com.baeldung.intro.security.DummyUserDetailsService;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
http.authorizeRequests()
|
||||||
|
.anyRequest()
|
||||||
|
.authenticated()
|
||||||
|
.and()
|
||||||
|
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Bean
|
||||||
|
public AuthenticationManager authenticationManagerBean() throws Exception {
|
||||||
|
return super.authenticationManagerBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
|
auth.authenticationProvider(kerberosAuthenticationProvider())
|
||||||
|
.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public KerberosAuthenticationProvider kerberosAuthenticationProvider() {
|
||||||
|
KerberosAuthenticationProvider provider = new KerberosAuthenticationProvider();
|
||||||
|
SunJaasKerberosClient client = new SunJaasKerberosClient();
|
||||||
|
client.setDebug(true);
|
||||||
|
provider.setKerberosClient(client);
|
||||||
|
provider.setUserDetailsService(dummyUserDetailsService());
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SpnegoEntryPoint spnegoEntryPoint() {
|
||||||
|
return new SpnegoEntryPoint("/login");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(dummyUserDetailsService());
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
|
||||||
|
SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||||
|
ticketValidator.setServicePrincipal("HTTP/demo.kerberos.bealdung.com@baeldung.com");
|
||||||
|
ticketValidator.setKeyTabLocation(new FileSystemResource("baeldung.keytab"));
|
||||||
|
ticketValidator.setDebug(true);
|
||||||
|
return ticketValidator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DummyUserDetailsService dummyUserDetailsService() {
|
||||||
|
return new DummyUserDetailsService();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.baeldung.intro.security;
|
||||||
|
|
||||||
|
import org.springframework.security.core.authority.AuthorityUtils;
|
||||||
|
import org.springframework.security.core.userdetails.User;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
|
||||||
|
public class DummyUserDetailsService implements UserDetailsService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
|
return new User(username, "notUsed", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user