All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.chutneytesting.security.infra.ldap.LdapTls1_1Configuration Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.chutneytesting.security.infra.ldap;

import com.chutneytesting.security.api.UserDto;
import com.chutneytesting.security.domain.AuthenticationService;
import com.chutneytesting.security.infra.ldap.ssl.ChutneyDirContextAuthenticationStrategy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.DirContextAuthenticationStrategy;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.security.ldap.userdetails.UserDetailsContextMapper;

@Configuration
@Profile("ldap-auth-tls1-1")
public class LdapTls1_1Configuration {

    @Bean
    @ConfigurationProperties("ldap.source")
    public LdapContextSource contextSource(DirContextAuthenticationStrategy strategy) {
        LdapContextSource contextSource = new LdapContextSource();
        contextSource.setAuthenticationStrategy(strategy);
        return contextSource;
    }

    @Bean
    public DirContextAuthenticationStrategy strategy() {
        return new ChutneyDirContextAuthenticationStrategy();
    }

    @Bean
    @ConfigurationProperties("ldap.attributes")
    public LdapAttributesProperties ldapAttributesProperties() {
        return new LdapAttributesProperties();
    }

    @Bean
    public LdapTemplate ldapTemplate(LdapContextSource contextSource) {
        return new LdapTemplate(contextSource);
    }

    @Bean
    public AttributesMapper attributesMapper(LdapAttributesProperties ldapAttributesProperties,
                                                      @Value("${ldap.groups-pattern}") String ldapGroupsPattern,
                                                      AuthenticationService authenticationService) {
        return new LdapAttributesMapper(ldapAttributesProperties, ldapGroupsPattern, authenticationService);
    }

    @Bean
    public LdapUserDetailsService ldapUserDetailsService(LdapTemplate ldapTemplate, LdapAttributesProperties ldapAttributesProperties, AttributesMapper attributesMapper) {
        return new LdapUserDetailsService(ldapTemplate, ldapAttributesProperties, attributesMapper);
    }

    @Bean
    public UserDetailsContextMapper userDetailsContextMapper(LdapUserDetailsService ldapUserDetailsService) {
        return new LdapUserDetailsContextMapper(ldapUserDetailsService);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy