Search in sources :

Example 6 with LdapContextSource

use of org.springframework.ldap.core.support.LdapContextSource in project av-service by dvoraka.

the class LdapUserConfig method contextSource.

@Bean
public ContextSource contextSource() {
    LdapContextSource ldapContextSource = new LdapContextSource();
    ldapContextSource.setUrl("");
    return ldapContextSource;
}
Also used : LdapContextSource(org.springframework.ldap.core.support.LdapContextSource) Bean(org.springframework.context.annotation.Bean)

Example 7 with LdapContextSource

use of org.springframework.ldap.core.support.LdapContextSource in project spring-boot by spring-projects.

the class LdapAutoConfiguration method ldapContextSource.

@Bean
@ConditionalOnMissingBean
public ContextSource ldapContextSource() {
    LdapContextSource source = new LdapContextSource();
    source.setUserDn(this.properties.getUsername());
    source.setPassword(this.properties.getPassword());
    source.setBase(this.properties.getBase());
    source.setUrls(this.properties.determineUrls(this.environment));
    source.setBaseEnvironmentProperties(Collections.<String, Object>unmodifiableMap(this.properties.getBaseEnvironment()));
    return source;
}
Also used : LdapContextSource(org.springframework.ldap.core.support.LdapContextSource) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with LdapContextSource

use of org.springframework.ldap.core.support.LdapContextSource in project jBPM5-Developer-Guide by Salaboy.

the class ProcessAndHumanTasksTest method setUp.

@Before
public void setUp() throws Exception {
    container = new ApacheDSContainer("o=mojo", "classpath:identity-repository.ldif");
    container.setPort(9898);
    container.afterPropertiesSet();
    LdapContextSource cs = new LdapContextSource();
    cs.setUrl("ldap://localhost:9898/");
    cs.setBase("o=mojo");
    cs.setUserDn("uid=admin,ou=system");
    cs.setPassword("secret");
    cs.afterPropertiesSet();
    LdapTemplate ldapTemplate = new LdapTemplate(cs);
    ldapTemplate.afterPropertiesSet();
    ldapQuery = new LdapQueryHelper(ldapTemplate);
    // By Setting the jbpm.usergroup.callback property with the call
    // back class full name, task service will use this to validate the
    // user/group exists and its permissions are ok.
    System.setProperty("jbpm.usergroup.callback", "org.jbpm.task.identity.LDAPUserGroupCallbackImpl");
//        LdapUserGroupCallback callback = (LdapUserGroupCallback) UserGroupCallbackManager.getInstance().getCallback();
//        callback.setQuery(ldapQuery);
}
Also used : LdapContextSource(org.springframework.ldap.core.support.LdapContextSource) ApacheDSContainer(org.springframework.security.ldap.server.ApacheDSContainer) LdapTemplate(org.springframework.ldap.core.LdapTemplate) Before(org.junit.Before)

Example 9 with LdapContextSource

use of org.springframework.ldap.core.support.LdapContextSource in project incubator-atlas by apache.

the class AtlasLdapAuthenticationProvider method getLdapBindAuthentication.

private Authentication getLdapBindAuthentication(Authentication authentication) {
    try {
        if (isDebugEnabled) {
            LOG.debug("==> AtlasLdapAuthenticationProvider getLdapBindAuthentication");
        }
        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }
        LdapContextSource ldapContextSource = getLdapContextSource();
        DefaultLdapAuthoritiesPopulator defaultLdapAuthoritiesPopulator = getDefaultLdapAuthoritiesPopulator(ldapContextSource);
        if (ldapUserSearchFilter == null || ldapUserSearchFilter.trim().isEmpty()) {
            ldapUserSearchFilter = "(uid={0})";
        }
        FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(ldapBase, ldapUserSearchFilter, ldapContextSource);
        userSearch.setSearchSubtree(true);
        BindAuthenticator bindAuthenticator = getBindAuthenticator(userSearch, ldapContextSource);
        LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator, defaultLdapAuthoritiesPopulator);
        if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) {
            final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
            final UserDetails principal = new User(userName, userPassword, grantedAuths);
            final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths);
            authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
            if (groupsFromUGI) {
                authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
            }
            return authentication;
        } else {
            LOG.error("LDAP Authentication::userName or userPassword is null or empty for userName " + userName);
        }
    } catch (Exception e) {
        LOG.error(" getLdapBindAuthentication LDAP Authentication Failed:", e);
    }
    if (isDebugEnabled) {
        LOG.debug("<== AtlasLdapAuthenticationProvider getLdapBindAuthentication");
    }
    return authentication;
}
Also used : BindAuthenticator(org.springframework.security.ldap.authentication.BindAuthenticator) User(org.apache.atlas.web.model.User) LdapContextSource(org.springframework.ldap.core.support.LdapContextSource) DefaultLdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthenticationException(org.springframework.security.core.AuthenticationException) UserDetails(org.springframework.security.core.userdetails.UserDetails) Authentication(org.springframework.security.core.Authentication) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider)

Aggregations

LdapContextSource (org.springframework.ldap.core.support.LdapContextSource)9 User (org.apache.atlas.web.model.User)3 Bean (org.springframework.context.annotation.Bean)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 Authentication (org.springframework.security.core.Authentication)3 GrantedAuthority (org.springframework.security.core.GrantedAuthority)3 UserDetails (org.springframework.security.core.userdetails.UserDetails)3 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)3 BindAuthenticator (org.springframework.security.ldap.authentication.BindAuthenticator)3 LdapAuthenticationProvider (org.springframework.security.ldap.authentication.LdapAuthenticationProvider)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)2 DefaultLdapAuthoritiesPopulator (org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator)2 Before (org.junit.Before)1 DependsOn (org.springframework.context.annotation.DependsOn)1 LdapTemplate (org.springframework.ldap.core.LdapTemplate)1 ActiveDirectoryLdapAuthenticationProvider (org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider)1 ApacheDSContainer (org.springframework.security.ldap.server.ApacheDSContainer)1