v2.0.0 Attempt to use spring ldap

experiment
Yan 2 weeks ago
parent 1297458c60
commit f1d0456ec5

@ -19,6 +19,7 @@
<pattern>%-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.springframework.security" level="DEBUG" />
<logger name="com.example.camel" level="DEBUG" />
<root level="INFO">
<appender-ref ref="STDOUT" />

@ -1,10 +1,18 @@
server:
port: 9090
camel:
springboot:
main-run-controller: true
spring:
activemq:
broker-url: "tcp://localhost:61616"
ldap:
urls: ldap://localhost:10389
base: dc=vidconnect,dc=cyou
username: cn=admin,dc=vidconnect,dc=cyou
password: xxx
app:
queue-name: "UserServiceQueue"
queue-name: "UserServiceQueue"

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>camel-springboot-activemq6-example</artifactId>
<version>1.0.1</version>
<version>2.0.0</version>
<name>camel-springboot-activemq6-example</name>
<parent>
<groupId>org.springframework.boot</groupId>
@ -44,6 +44,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<!-- Camel -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>

@ -1,15 +0,0 @@
package com.example.camel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider;
@Configuration
public class CxfConfig {
@Bean
public JacksonJsonProvider jaxrsProvider() {
return new JacksonJsonProvider();
}
}

@ -0,0 +1,61 @@
package com.example.camel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.ldap.LdapBindAuthenticationManagerFactory;
import org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator;
import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator;
import org.springframework.security.web.SecurityFilterChain;
import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider;
@Configuration
public class SecurityConfig {
@Value("${app.group-search-base:ou=groups}")
private String groupSearchBase;
@Value("${app.group-search-filter:(member={0})}")
private String groupSearchFilter;
@Value("${app.user-search-base:ou=people}")
private String userSearchBase;
@Value("${app.user-search-filter:(uid={0})}")
private String userSearchFilter;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((authorize) -> authorize.anyRequest().fullyAuthenticated())
.httpBasic(Customizer.withDefaults());
return http.build();
}
@Bean
public LdapAuthoritiesPopulator authorities(BaseLdapPathContextSource contextSource) {
DefaultLdapAuthoritiesPopulator authorities = new DefaultLdapAuthoritiesPopulator(contextSource,
groupSearchBase);
authorities.setGroupSearchFilter(groupSearchFilter);
return authorities;
}
@Bean
public AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSource,
LdapAuthoritiesPopulator authorities) {
LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource);
factory.setUserSearchBase(userSearchBase);
factory.setUserSearchFilter(userSearchFilter);
return factory.createAuthenticationManager();
}
@Bean
public JacksonJsonProvider jaxrsProvider() {
return new JacksonJsonProvider();
}
}
Loading…
Cancel
Save