org.springframework.security.ldap.search.LdapUserSearch Java Examples
The following examples show how to use
org.springframework.security.ldap.search.LdapUserSearch.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapSecurityConfiguration.java From data-highway with Apache License 2.0 | 5 votes |
@Bean public LdapUserSearch userSearch( @Value("${ldap.searchBase}") String searchBase, @Value("${ldap.searchFilter}") String searchFilter, BaseLdapPathContextSource contextSource) { return new FilterBasedLdapUserSearch(searchBase, searchFilter, contextSource); }
Example #2
Source File: TokenAuthenticationService.java From heimdall with Apache License 2.0 | 5 votes |
private LdapAuthenticationProvider ldapProvider(Ldap ldap) { LdapContextSource contextSource = new LdapContextSource(); contextSource.setUrl(ldap.getUrl()); contextSource.setUserDn(ldap.getUserDn()); contextSource.setPassword(ldap.getPassword()); contextSource.setReferral("follow"); contextSource.afterPropertiesSet(); LdapUserSearch ldapUserSearch = new FilterBasedLdapUserSearch(ldap.getSearchBase(), ldap.getUserSearchFilter(), contextSource); BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource); bindAuthenticator.setUserSearch(ldapUserSearch); return new LdapAuthenticationProvider(bindAuthenticator, populator); }
Example #3
Source File: LdapAuthenticationProviderConfigurer.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
/** * Creates the {@link LdapAuthenticator} to use * * @param contextSource the {@link BaseLdapPathContextSource} to use * @return the {@link LdapAuthenticator} to use */ private LdapAuthenticator createLdapAuthenticator( BaseLdapPathContextSource contextSource) { AbstractLdapAuthenticator ldapAuthenticator = passwordEncoder == null ? createBindAuthenticator(contextSource) : createPasswordCompareAuthenticator(contextSource); LdapUserSearch userSearch = createUserSearch(); if (userSearch != null) { ldapAuthenticator.setUserSearch(userSearch); } if (userDnPatterns != null && userDnPatterns.length > 0) { ldapAuthenticator.setUserDnPatterns(userDnPatterns); } return postProcess(ldapAuthenticator); }
Example #4
Source File: LdapAuthenticationProviderConfigurer.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
private LdapUserSearch createUserSearch() { if (userSearchFilter == null) { return null; } return new FilterBasedLdapUserSearch(userSearchBase, userSearchFilter, contextSource); }
Example #5
Source File: LdapSecurityConfiguration.java From data-highway with Apache License 2.0 | 4 votes |
@Bean public BindAuthenticator bindAuthenticator(BaseLdapPathContextSource contextSource, LdapUserSearch userSearch) { BindAuthenticator authenticator = new BindAuthenticator(contextSource); authenticator.setUserSearch(userSearch); return authenticator; }
Example #6
Source File: LDAPAuthenticator.java From para with Apache License 2.0 | 4 votes |
/** * Default constructor. * @param ldapSettings LDAP config map for an app */ public LDAPAuthenticator(Map<String, String> ldapSettings) { if (ldapSettings != null && ldapSettings.containsKey("security.ldap.server_url")) { String serverUrl = ldapSettings.get("security.ldap.server_url"); String baseDN = ldapSettings.get("security.ldap.base_dn"); String bindDN = Utils.noSpaces(ldapSettings.get("security.ldap.bind_dn"), "%20"); String bindPass = ldapSettings.get("security.ldap.bind_pass"); String userSearchBase = ldapSettings.get("security.ldap.user_search_base"); String userSearchFilter = ldapSettings.get("security.ldap.user_search_filter"); String userDnPattern = ldapSettings.get("security.ldap.user_dn_pattern"); String passAttribute = ldapSettings.get("security.ldap.password_attribute"); boolean usePasswordComparison = ldapSettings.containsKey("security.ldap.compare_passwords"); DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(Arrays.asList(serverUrl), baseDN); contextSource.setAuthenticationSource(new SpringSecurityAuthenticationSource()); contextSource.setCacheEnvironmentProperties(false); if (!bindDN.isEmpty()) { // this is usually not required for authentication - leave blank contextSource.setUserDn(bindDN); } if (!bindPass.isEmpty()) { // this is usually not required for authentication - leave blank contextSource.setPassword(bindPass); } LdapUserSearch userSearch = new FilterBasedLdapUserSearch(userSearchBase, userSearchFilter, contextSource); if (usePasswordComparison) { PasswordComparisonAuthenticator p = new PasswordComparisonAuthenticator(contextSource); p.setPasswordAttributeName(passAttribute); p.setUserDnPatterns(getUserDnPatterns(userDnPattern)); p.setUserSearch(userSearch); authenticator = p; } else { BindAuthenticator b = new BindAuthenticator(contextSource); b.setUserDnPatterns(getUserDnPatterns(userDnPattern)); b.setUserSearch(userSearch); authenticator = b; } } }