|
|
@ -3,6 +3,7 @@ package com.example.camel;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
|
|
|
|
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.config.Customizer;
|
|
|
|
import org.springframework.security.config.Customizer;
|
|
|
@ -17,13 +18,16 @@ import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider;
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
public class SecurityConfig {
|
|
|
|
public class SecurityConfig {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String ROLE_BACKEND = "ROLE_BACKEND";
|
|
|
|
|
|
|
|
public static final String ROLE_SERVER = "ROLE_SERVER";
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${app.group-search-base:ou=groups}")
|
|
|
|
@Value("${app.group-search-base:ou=groups}")
|
|
|
|
private String groupSearchBase;
|
|
|
|
private String groupSearchBase;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${app.group-search-filter:(member={0})}")
|
|
|
|
@Value("${app.group-search-filter:(member={0})}")
|
|
|
|
private String groupSearchFilter;
|
|
|
|
private String groupSearchFilter;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${app.user-search-base:ou=people}")
|
|
|
|
@Value("${app.user-search-base:ou=users}")
|
|
|
|
private String userSearchBase;
|
|
|
|
private String userSearchBase;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${app.user-search-filter:(uid={0})}")
|
|
|
|
@Value("${app.user-search-filter:(uid={0})}")
|
|
|
@ -31,9 +35,10 @@ public class SecurityConfig {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
http.authorizeHttpRequests((authorize) -> authorize.anyRequest().fullyAuthenticated())
|
|
|
|
http.authorizeHttpRequests(
|
|
|
|
|
|
|
|
(authorize) -> authorize.requestMatchers(HttpMethod.GET, "/**").hasAuthority(ROLE_BACKEND)
|
|
|
|
|
|
|
|
.requestMatchers(HttpMethod.POST, "/**").hasAuthority(ROLE_SERVER))
|
|
|
|
.httpBasic(Customizer.withDefaults());
|
|
|
|
.httpBasic(Customizer.withDefaults());
|
|
|
|
|
|
|
|
|
|
|
|
return http.build();
|
|
|
|
return http.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -51,6 +56,7 @@ public class SecurityConfig {
|
|
|
|
LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource);
|
|
|
|
LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource);
|
|
|
|
factory.setUserSearchBase(userSearchBase);
|
|
|
|
factory.setUserSearchBase(userSearchBase);
|
|
|
|
factory.setUserSearchFilter(userSearchFilter);
|
|
|
|
factory.setUserSearchFilter(userSearchFilter);
|
|
|
|
|
|
|
|
factory.setLdapAuthoritiesPopulator(authorities);
|
|
|
|
return factory.createAuthenticationManager();
|
|
|
|
return factory.createAuthenticationManager();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|