本文整理汇总了Java中org.springframework.ldap.core.support.LdapContextSource.setBaseEnvironmentProperties方法的典型用法代码示例。如果您正苦于以下问题:Java LdapContextSource.setBaseEnvironmentProperties方法的具体用法?Java LdapContextSource.setBaseEnvironmentProperties怎么用?Java LdapContextSource.setBaseEnvironmentProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.ldap.core.support.LdapContextSource
的用法示例。
在下文中一共展示了LdapContextSource.setBaseEnvironmentProperties方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLdapContextSource
import org.springframework.ldap.core.support.LdapContextSource; //导入方法依赖的package包/类
private LdapContextSource getLdapContextSource() throws Exception {
LdapContextSource cs = new LdapContextSource();
cs.setUrl(Config.getLdapUrl());
cs.setBase(Config.getLDAPBase());
cs.setUserDn(Config.getUserDN());
//cs.setAnonymousReadOnly(true);
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.REFERRAL, "follow");
cs.setBaseEnvironmentProperties(env);
cs.setPassword(Config.getLdapPassword());
cs.afterPropertiesSet();
return cs;
}
示例2: configureGlobal
import org.springframework.ldap.core.support.LdapContextSource; //导入方法依赖的package包/类
public static void configureGlobal(AuthenticationManagerBuilder auth, LdapAuthServerConfig authCfg, PasswordEncoder passwordEncoder) throws Exception {
if (authCfg != null) {
LdapContextSource ldapCtx = new LdapContextSource();
ldapCtx.setUrl(authCfg.getLdapUrl());
ldapCtx.setUserDn(authCfg.getBindDn());
ldapCtx.setPassword(authCfg.getBindPassword());
Map<String, Object> baseEnv = new HashMap<String, Object>();
baseEnv.put(CONNECT_TIMEOUT_ENV, "" + authCfg.getConnectTimeout());
baseEnv.put(READ_TIMEOUT_ENV, "" + authCfg.getReadTimeout());
ldapCtx.setBaseEnvironmentProperties(baseEnv);
ldapCtx.afterPropertiesSet();
/** Have connections to LDAP be pooled */
LdapPoolingContextSourceAdapter pooling = new LdapPoolingContextSourceAdapter();
pooling.setDirContextValidator(new DefaultDirContextValidator());
pooling.setContextSource(ldapCtx);
pooling.setTestOnBorrow(true);
pooling.setTestWhileIdle(true);
auth
.ldapAuthentication()
.passwordEncoder(passwordEncoder)
.contextSource(pooling)
.userDnPatterns(authCfg.getUserDnPatterns())
.groupSearchBase(authCfg.getGroupSearchBase())
.groupSearchFilter(authCfg.getGroupFilter())
.and()
.eraseCredentials(false);
}
}
示例3: getLdapContextSource
import org.springframework.ldap.core.support.LdapContextSource; //导入方法依赖的package包/类
private LdapContextSource getLdapContextSource() throws Exception {
LdapContextSource cs = new LdapContextSource();
cs.setUrl(Config.getLdapUrl());
cs.setBase("DC=nexus,DC=csiro,DC=au");
cs.setUserDn(Config.getUserDN());
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.REFERRAL, "follow");
cs.setBaseEnvironmentProperties(env);
cs.setPassword(Config.getLdapPassword());
cs.afterPropertiesSet();
return cs;
}
示例4: createLdapContext
import org.springframework.ldap.core.support.LdapContextSource; //导入方法依赖的package包/类
/**
* @param config
* the ldap configuration
* @param binaryAttributes
* optional array of attributes to be returned as binary. This argument need not to
* be provided if the context is not intended to retrieve entries.
* @return the context factory
* @throws NamingException
* Exception
*/
public static LdapContextSource createLdapContext(LdapConfiguration config,
String[] binaryAttributes) throws NamingException {
String[] urls = getServerUrls(config);
// create initial context factory
for (String url : urls) {
LdapContextSource context = new DefaultSpringSecurityContextSource(url);
if (StringUtils.isNotEmpty(config.getManagerDN())) {
context.setUserDn(config.getManagerDN());
// manager password cannot be null
if (config.getManagerPassword() == null) {
context.setPassword(StringUtils.EMPTY);
} else {
context.setPassword(config.getManagerPassword());
}
}
/*
* This property helps to avoid PartialResultExceptions see
* http://java.sun.com/products/jndi/tutorial/ldap/referral/jndi.html
*/
Map<String, String> map = new HashMap<String, String>();
map.put(Context.REFERRAL, FOLLOW);
if (binaryAttributes != null && binaryAttributes.length > 0) {
map.put("java.naming.ldap.attributes.binary",
StringHelper.toString(binaryAttributes, " "));
}
if (config.getSaslMode() != null) {
map.put(Context.SECURITY_AUTHENTICATION, config.getSaslMode());
}
context.setBaseEnvironmentProperties(map);
try {
context.afterPropertiesSet();
} catch (Exception e) {
LOGGER.error("There was an error configuring the LDAP context source.", e);
continue;
}
return context;
}
return null;
}
示例5: createLdapContextForAD
import org.springframework.ldap.core.support.LdapContextSource; //导入方法依赖的package包/类
/**
* Creates a context source for the AD.
*
* @param config
* the ldap configuration
* @param binaryAttributes
* optional array of attributes to be returned as binary. This argument need not to
* be provided if the context is not intended to retrieve entries.
* @return the context factory
* @throws NamingException
* Exception
*/
private LdapContextSource createLdapContextForAD(LdapConfiguration config,
String[] binaryAttributes) throws NamingException {
List<String> urls = Arrays.asList(LdapSearchUtils.getServerUrls(config));
String lastUsedUrl = pluginProperties
.getClientProperty(PROPERTY_KEY_AD_LAST_USED_SERVER);
// Move to front, only if it is contained, else the servers might have changed.
if (lastUsedUrl != null && urls.indexOf(lastUsedUrl) > 0) {
urls.remove(lastUsedUrl);
urls.add(0, lastUsedUrl);
}
for (String url : urls) {
LdapContextSource targetContextSource = new DefaultSpringSecurityContextSource(url);
targetContextSource.setUserDn(ldapConfiguration.getManagerDN());
targetContextSource.setPassword(ldapConfiguration.getManagerPassword());
try {
Map<String, String> map = new HashMap<String, String>();
map.put(Context.REFERRAL, "follow");
if (binaryAttributes != null && binaryAttributes.length > 0) {
map.put("java.naming.ldap.attributes.binary",
StringHelper.toString(binaryAttributes,
" "));
}
if (config.getSaslMode() != null) {
map.put(Context.SECURITY_AUTHENTICATION, config.getSaslMode());
}
targetContextSource.setBaseEnvironmentProperties(map);
targetContextSource.afterPropertiesSet();
targetContextSource.getReadOnlyContext().close();
if (lastUsedUrl != null && !url.equals(lastUsedUrl)) {
pluginProperties.setClientProperty(
PROPERTY_KEY_ACTIVE_DIRECTORY_TRACKING_USER_SEQUENCE_NUMBER,
null);
}
pluginProperties.setClientProperty(PROPERTY_KEY_AD_LAST_USED_SERVER, url);
return targetContextSource;
} catch (Exception e) {
LOGGER.error("There was an error configuring the LDAP context source.", e);
}
}
return null;
}
开发者ID:Communote,项目名称:communote-server,代码行数:54,代码来源:ADTrackingIncrementalRepositoryChangeTracker.java
示例6: setUp
import org.springframework.ldap.core.support.LdapContextSource; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
// Create some basic converters and a converter manager
converterManager = new ConverterManagerImpl();
Converter ptc = new FromStringConverter();
converterManager.addConverter(String.class, "", Byte.class, ptc);
converterManager.addConverter(String.class, "", Short.class, ptc);
converterManager.addConverter(String.class, "", Integer.class, ptc);
converterManager.addConverter(String.class, "", Long.class, ptc);
converterManager.addConverter(String.class, "", Double.class, ptc);
converterManager.addConverter(String.class, "", Float.class, ptc);
converterManager.addConverter(String.class, "", Boolean.class, ptc);
Converter tsc = new ToStringConverter();
converterManager.addConverter(Byte.class, "", String.class, tsc);
converterManager.addConverter(Short.class, "", String.class, tsc);
converterManager.addConverter(Integer.class, "", String.class, tsc);
converterManager.addConverter(Long.class, "", String.class, tsc);
converterManager.addConverter(Double.class, "", String.class, tsc);
converterManager.addConverter(Float.class, "", String.class, tsc);
converterManager.addConverter(Boolean.class, "", String.class, tsc);
// Bind to the directory
contextSource = new LdapContextSource();
contextSource.setUrl("ldaps://127.0.0.1:" + port);
contextSource.setUserDn(USER_DN);
contextSource.setPassword(PASSWORD);
contextSource.setPooled(false);
contextSource.setBase("dc=261consulting,dc=local");
HashMap<String, Object> baseEnvironment = new HashMap<String, Object>() {{
put("java.naming.ldap.attributes.binary", "thumbnailLogo replPropertyMetaData partialAttributeSet registeredAddress userPassword telexNumber partialAttributeDeletionList mS-DS-ConsistencyGuid attributeCertificateAttribute thumbnailPhoto teletexTerminalIdentifier replUpToDateVector dSASignature objectGUID");
}};
contextSource.setBaseEnvironmentProperties(baseEnvironment);
contextSource.afterPropertiesSet();
ldapTemplate = new LdapTemplate(contextSource);
cleanup();
DirContextAdapter ctx = new DirContextAdapter("cn=William Hartnell,cn=Users");
ctx.setAttributeValues("objectclass", new String[]{"person","inetorgperson","organizationalperson","top"});
ctx.setAttributeValue("cn", "William Hartnell");
ctx.addAttributeValue("description", "First Doctor");
ctx.addAttributeValue("description", "Grumpy");
ctx.addAttributeValue("sn", "Hartnell");
ctx.addAttributeValue("telephonenumber", "1");
ldapTemplate.bind(ctx);
}