本文整理汇总了Java中com.sun.jndi.ldap.LdapCtx类的典型用法代码示例。如果您正苦于以下问题:Java LdapCtx类的具体用法?Java LdapCtx怎么用?Java LdapCtx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LdapCtx类属于com.sun.jndi.ldap包,在下文中一共展示了LdapCtx类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUsingURLIgnoreRootDN
import com.sun.jndi.ldap.LdapCtx; //导入依赖的package包/类
static ResolveResult getUsingURLIgnoreRootDN(String url, Hashtable<?,?> env)
throws NamingException {
LdapURL ldapUrl = new LdapURL(url);
DirContext ctx = new LdapCtx("", ldapUrl.getHost(), ldapUrl.getPort(),
env, ldapUrl.useSsl());
String dn = (ldapUrl.getDN() != null ? ldapUrl.getDN() : "");
// Represent DN as empty or single-component composite name.
CompositeName remaining = new CompositeName();
if (!"".equals(dn)) {
// if nonempty, add component
remaining.add(dn);
}
return new ResolveResult(ctx, remaining);
}
示例2: ldapInjectionSunApi
import com.sun.jndi.ldap.LdapCtx; //导入依赖的package包/类
public void ldapInjectionSunApi(String input) throws NamingException {
//Stub instances
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, "ldap://ldap.example.com");
props.put(Context.REFERRAL, "ignore");
SearchControls ctrls = new SearchControls();
ctrls.setReturningAttributes(new String[]{"givenName", "sn"});
ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//Two context instances mostly usable with sun specific API
LdapCtx context5 = null;
EventDirContext context6 = null; //LdapCtx is the only known class to implements to this interface
NamingEnumeration<SearchResult> answers;
answers = context5.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
answers = context5.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
answers = context5.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
answers = context5.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);
answers = context6.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
answers = context6.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
answers = context6.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
answers = context6.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);
}
示例3: getUsingURLIgnoreRootDN
import com.sun.jndi.ldap.LdapCtx; //导入依赖的package包/类
static ResolveResult getUsingURLIgnoreRootDN(String url, Hashtable env)
throws NamingException {
LdapURL ldapUrl = new LdapURL(url);
DirContext ctx = new LdapCtx("", ldapUrl.getHost(), ldapUrl.getPort(),
env, ldapUrl.useSsl());
String dn = (ldapUrl.getDN() != null ? ldapUrl.getDN() : "");
// Represent DN as empty or single-component composite name.
CompositeName remaining = new CompositeName();
if (!"".equals(dn)) {
// if nonempty, add component
remaining.add(dn);
}
return new ResolveResult(ctx, remaining);
}
示例4: retrieve
import com.sun.jndi.ldap.LdapCtx; //导入依赖的package包/类
@Override
public User retrieve(String id) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person"));
filter.and(new EqualsFilter(identifierAttribute, id));
LdapQuery ldapQuery = LdapQueryBuilder
.query()
.base(baseDn)
.countLimit(1)
.timeLimit(5000)
.searchScope(SearchScope.SUBTREE)
.attributes(identifierAttribute, "givenname", "sn", "mail")
.filter(filter);
List<User> users = ldapTemplate.search(ldapQuery, new UserAttributesMapper());
if (users != null && ! users.isEmpty()) {
LdapUser user = (LdapUser) users.iterator().next();
List<String> result = ldapTemplate.search(
baseDn, filter.encode(),
(ContextMapper<String>) o -> ((LdapCtx) o).getNameInNamespace());
user.setDn(result.iterator().next());
return user;
} else {
return null;
}
}
示例5: getException
import com.sun.jndi.ldap.LdapCtx; //导入依赖的package包/类
/**
* Retrieves the NamingException appropriate for the result code.
*
* @return A NamingException or null if the result code indicates
* success.
*/
public NamingException getException() {
return LdapCtx.mapErrorCode(resultCode, null);
}