本文整理汇总了Java中org.springframework.security.ldap.search.FilterBasedLdapUserSearch类的典型用法代码示例。如果您正苦于以下问题:Java FilterBasedLdapUserSearch类的具体用法?Java FilterBasedLdapUserSearch怎么用?Java FilterBasedLdapUserSearch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FilterBasedLdapUserSearch类属于org.springframework.security.ldap.search包,在下文中一共展示了FilterBasedLdapUserSearch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJndiSpring
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
@Test
public void testJndiSpring() throws Exception {
DefaultSpringSecurityContextSource ctxSrc = new DefaultSpringSecurityContextSource(
"ldap://ldap.xxx:389/OU=xxx");
ctxSrc.setUserDn(USER_LDAP);
ctxSrc.setPassword(PASSWORD_LDAP);
ctxSrc.afterPropertiesSet();
logger.info("Base LDAP Path: " + ctxSrc.getBaseLdapPath());
logger.info("Principal: "
+ ctxSrc.getAuthenticationSource().getPrincipal().toString());
logger.info("Credentials: "
+ ctxSrc.getAuthenticationSource().getCredentials());
Authentication bob = new UsernamePasswordAuthenticationToken("bob",
"bob");
BindAuthenticator authenticator = new BindAuthenticator(ctxSrc);
authenticator.setUserSearch(new FilterBasedLdapUserSearch("",
"(&(objectCategory=Person)(sAMAccountName={0}))", ctxSrc));
authenticator.afterPropertiesSet();
authenticator.authenticate(bob);
DirContextOperations user = authenticator.authenticate(bob);
logger.info("User: {}", user);
}
示例2: bindAuthenticator
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
@Bean
public BindAuthenticator bindAuthenticator(FilterBasedLdapUserSearch userSearch){
return new BindAuthenticator(contextSource()){{
setUserSearch(userSearch);
}};
}
示例3: createUserSearch
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
private LdapUserSearch createUserSearch() {
if (userSearchFilter == null) {
return null;
}
return new FilterBasedLdapUserSearch(userSearchBase, userSearchFilter,
contextSource);
}
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:8,代码来源:LdapAuthenticationProviderConfigurer.java
示例4: getBindAuthenticator
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
private BindAuthenticator getBindAuthenticator(
FilterBasedLdapUserSearch userSearch,
LdapContextSource ldapContextSource) throws Exception {
BindAuthenticator bindAuthenticator = new BindAuthenticator(
ldapContextSource);
bindAuthenticator.setUserSearch(userSearch);
String[] userDnPatterns = new String[] { ldapUserDNPattern };
bindAuthenticator.setUserDnPatterns(userDnPatterns);
bindAuthenticator.afterPropertiesSet();
return bindAuthenticator;
}
示例5: getLdapUserSearches
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
@Override
public List<FilterBasedLdapUserSearch> getLdapUserSearches(ContextSource ctx, LdapSetting settings) {
SearchPattern searchPattern = settings.getSearch();
String searchBase = searchPattern.getSearchBase();
if (searchBase == null) {
searchBase = "";
}
ArrayList<FilterBasedLdapUserSearch> result = new ArrayList<>();
FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(searchBase,
searchPattern.getSearchFilter(), (BaseLdapPathContextSource) ctx);
userSearch.setSearchSubtree(searchPattern.isSearchSubTree());
result.add(userSearch);
return result;
}
示例6: userSearch
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
@ConditionalOnProperty("auth.ldap.search.pattern")
@Bean
public FilterBasedLdapUserSearch userSearch() {
FilterBasedLdapUserSearch search = new FilterBasedLdapUserSearch("", ldapSearchPattern, contextSource());
search.setSearchSubtree(searchSubtree);
return search;
}
示例7: loadProvider
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
private LdapAuthenticationProvider loadProvider() {
LDAPSettings settings = cachedSettingsService.getCachedSettings(LDAPSettings.class);
if (settings.isEnabled()) {
// LDAP context
DefaultSpringSecurityContextSource ldapContextSource = new DefaultSpringSecurityContextSource(settings.getUrl());
ldapContextSource.setUserDn(settings.getUser());
ldapContextSource.setPassword(settings.getPassword());
try {
ldapContextSource.afterPropertiesSet();
} catch (Exception e) {
throw new CannotInitializeLDAPException(e);
}
// User search
FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(
settings.getSearchBase(),
settings.getSearchFilter(),
ldapContextSource);
userSearch.setSearchSubtree(true);
// Bind authenticator
BindAuthenticator bindAuthenticator = new BindAuthenticator(ldapContextSource);
bindAuthenticator.setUserSearch(userSearch);
// Provider
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator, authoritiesPopulator);
ldapAuthenticationProvider.setUserDetailsContextMapper(new ConfigurableUserDetailsContextMapper(settings));
// OK
return ldapAuthenticationProvider;
}
// LDAP not enabled
else {
return null;
}
}
示例8: LDAPAuthenticator
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
/**
* 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 = ldapSettings.get("security.ldap.bind_dn");
String basePass = ldapSettings.get("security.ldap.bind_pass");
String searchBase = ldapSettings.get("security.ldap.user_search_base");
String searchFilter = ldapSettings.get("security.ldap.user_search_filter");
String dnPattern = 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()) {
contextSource.setUserDn(bindDN);
}
if (!basePass.isEmpty()) {
contextSource.setPassword(basePass);
}
LdapUserSearch userSearch = new FilterBasedLdapUserSearch(searchBase, searchFilter, contextSource);
if (usePasswordComparison) {
PasswordComparisonAuthenticator p = new PasswordComparisonAuthenticator(contextSource);
p.setPasswordAttributeName(passAttribute);
p.setPasswordEncoder(new LdapShaPasswordEncoder());
p.setUserDnPatterns(new String[]{dnPattern});
p.setUserSearch(userSearch);
authenticator = p;
} else {
BindAuthenticator b = new BindAuthenticator(contextSource);
b.setUserDnPatterns(new String[]{dnPattern});
b.setUserSearch(userSearch);
authenticator = b;
}
}
}
示例9: loadLdapAuthenticationProvider
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
/**
* Reloads LDAP Context Source and depending objects if properties were changed
* @return corresponding LDAP authentication provider
*/
LdapAuthenticationProvider loadLdapAuthenticationProvider() {
if (reloadLdapServerProperties()) {
LOG.info("LDAP Properties changed - rebuilding Context");
LdapContextSource springSecurityContextSource = new LdapContextSource();
List<String> ldapUrls = ldapServerProperties.get().getLdapUrls();
springSecurityContextSource.setUrls(ldapUrls.toArray(new String[ldapUrls.size()]));
springSecurityContextSource.setBase(ldapServerProperties.get().getBaseDN());
if (!ldapServerProperties.get().isAnonymousBind()) {
springSecurityContextSource.setUserDn(ldapServerProperties.get().getManagerDn());
springSecurityContextSource.setPassword(ldapServerProperties.get().getManagerPassword());
}
try {
springSecurityContextSource.afterPropertiesSet();
} catch (Exception e) {
LOG.error("LDAP Context Source not loaded ", e);
throw new UsernameNotFoundException("LDAP Context Source not loaded", e);
}
//TODO change properties
String userSearchBase = ldapServerProperties.get().getUserSearchBase();
String userSearchFilter = ldapServerProperties.get().getUserSearchFilter();
FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(userSearchBase, userSearchFilter, springSecurityContextSource);
AmbariLdapBindAuthenticator bindAuthenticator = new AmbariLdapBindAuthenticator(springSecurityContextSource, configuration);
bindAuthenticator.setUserSearch(userSearch);
LdapAuthenticationProvider authenticationProvider = new LdapAuthenticationProvider(bindAuthenticator, authoritiesPopulator);
providerThreadLocal.set(authenticationProvider);
}
return providerThreadLocal.get();
}
示例10: ldapAuthenticator
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
@Bean
public LdapAuthenticator ldapAuthenticator() {
BindAuthenticator authenticator = new BindAuthenticator(ldapContextSource());
authenticator.setUserAttributes(new String[] {ldapUserIdAttr});
if (!"".equals(ldapSearchFilter)) {
logger.debug("ldapSearch: {} {}", ldapSearchBase, ldapSearchFilter);
authenticator.setUserSearch(new FilterBasedLdapUserSearch(ldapSearchBase, ldapSearchFilter, ldapContextSource()));
} else {
logger.debug("ldapUserDn: {}", ldapUserDn);
authenticator.setUserDnPatterns(new String[] {ldapUserDn});
}
return authenticator;
}
示例11: ldapFilteredUserSearch
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
private static LdapUserSearch ldapFilteredUserSearch(UserProperties properties, LdapContextSource source) {
return new FilterBasedLdapUserSearch(
properties.getSearchBase(), properties.getFilter(), source
);
}
示例12: filterBasedLdapUserSearch
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
@Bean
public FilterBasedLdapUserSearch filterBasedLdapUserSearch(){
return new FilterBasedLdapUserSearch("CN=Users", //user-search-base
"(sAMAccountName={0})", //user-search-filter
contextSource()); //ldapServer
}
示例13: filterBasedLdapUserSearch
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
@Bean
public FilterBasedLdapUserSearch filterBasedLdapUserSearch(){
return new FilterBasedLdapUserSearch("", //user-search-base
"(uid={0})", //user-search-filter
contextSource()); //ldapServer
}
示例14: userSearch
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
@Bean
public LdapUserSearch userSearch() {
return new FilterBasedLdapUserSearch(
configuration.getUserSearchBase(), configuration.getUserSearchFilter(),
contextSource());
}
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:7,代码来源:LdapAuthenticationProviderConfiguration.java
示例15: getADBindAuthentication
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch; //导入依赖的package包/类
private Authentication getADBindAuthentication (Authentication authentication) {
try {
String userName = authentication.getName();
String userPassword = "";
if (authentication.getCredentials() != null) {
userPassword = authentication.getCredentials().toString();
}
LdapContextSource ldapContextSource = new DefaultSpringSecurityContextSource(adURL);
ldapContextSource.setUserDn(adBindDN);
ldapContextSource.setPassword(adBindPassword);
ldapContextSource.setReferral(adReferral);
ldapContextSource.setCacheEnvironmentProperties(true);
ldapContextSource.setAnonymousReadOnly(false);
ldapContextSource.setPooled(true);
ldapContextSource.afterPropertiesSet();
if (adUserSearchFilter==null || adUserSearchFilter.trim().isEmpty()) {
adUserSearchFilter="(sAMAccountName={0})";
}
FilterBasedLdapUserSearch userSearch=new FilterBasedLdapUserSearch(adBase, adUserSearchFilter,ldapContextSource);
userSearch.setSearchSubtree(true);
BindAuthenticator bindAuthenticator = new BindAuthenticator(ldapContextSource);
bindAuthenticator.setUserSearch(userSearch);
bindAuthenticator.afterPropertiesSet();
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator);
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("AD Authentication Failed userName or userPassword is null or empty");
return null;
}
} catch (Exception e) {
LOG.error("AD Authentication Failed:", e);
return null;
}
}