本文整理了Java中com.novell.ldap.LDAPConnection
类的一些代码示例,展示了LDAPConnection
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LDAPConnection
类的具体详情如下:
包路径:com.novell.ldap.LDAPConnection
类名称:LDAPConnection
[英]The central class that encapsulates the connection to a directory server through the LDAP protocol. LDAPConnection objects are used to perform common LDAP operations such as search, modify and add.
In addition, LDAPConnection objects allow you to bind to an LDAP server, set connection and search constraints, and perform several other tasks.
An LDAPConnection object is not connected on construction and can only be connected to one server at one port. Multiple threads may share this single connection, typically by cloning the connection object, one for each thread. An application may have more than one LDAPConnection object, connected to the same or different directory servers.
Sample Code: Search.java
[中]通过LDAP协议封装到目录服务器的连接的中心类。LDAPConnection对象用于执行常见的LDAP操作,如搜索、修改和添加。
此外,LDAPConnection对象允许您绑定到LDAP服务器、设置连接和搜索约束以及执行其他一些任务。
LDAPConnection对象在构造时未连接,只能在一个端口连接到一台服务器。多个线程可以共享这个单一连接,通常是通过克隆连接对象,每个线程一个。一个应用程序可能有多个LDAPConnection对象连接到相同或不同的目录服务器。
示例代码:Search.java
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
private LDAPConnection getConnection() throws LDAPException, UnsupportedEncodingException {
// LDAPSocketFactory ssf;
// Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// String path ="C:\\j2sdk1.4.2_09\\jre\\lib\\security\\cacerts";
//op("the trustStore: " + System.getProperty("javax.net.ssl.trustStore"));
// System.setProperty("javax.net.ssl.trustStore", path);
// op(" reading the strustStore: " + System.getProperty("javax.net.ssl.trustStore"));
// ssf = new LDAPJSSESecureSocketFactory();
// LDAPConnection.setSocketFactory(ssf);
LDAPConnection lc = new LDAPConnection();
lc.connect(ldapHost, ldapPort);
// bind to the server
lc.bind(ldapVersion, loginDN, password.getBytes("UTF8"));
// tbd
// LDAPConnection pooling here?
//
return lc;
}
代码示例来源:origin: glyptodon/guacamole-client
/**
* Disconnects the given LDAP connection, logging any failure to do so
* appropriately.
*
* @param ldapConnection
* The LDAP connection to disconnect.
*/
public void disconnect(LDAPConnection ldapConnection) {
// Attempt disconnect
try {
ldapConnection.disconnect();
}
// Warn if disconnect unexpectedly fails
catch (LDAPException e) {
logger.warn("Unable to disconnect from LDAP server: {}", e.getMessage());
logger.debug("LDAP disconnect failed.", e);
}
}
代码示例来源:origin: stackoverflow.com
public static List<SearchResultEntry> getResults(LDAPConnection connection, String baseDN, String filter) throws LDAPSearchException {
SearchResult searchResult;
if (connection.isConnected()) {
searchResult = connection.search(baseDN, SearchScope.ONE, filter);
return searchResult.getSearchEntries();
}
return null;
}
代码示例来源:origin: glyptodon/guacamole-client
LDAPConstraints ldapConstraints = ldapConnection.getConstraints();
if (ldapConstraints == null)
ldapConstraints = new LDAPConstraints();
ldapConnection.setConstraints(ldapConstraints);
ldapConnection.connect(
confService.getServerHostname(),
confService.getServerPort()
ldapConnection.startTLS();
ldapConnection.bind(LDAPConnection.LDAP_V3, userDN, passwordBytes);
代码示例来源:origin: stackoverflow.com
LDAPConnection conn = new LDAPConnection();
conn.connect("ldap.mycompany.com",389);
LDAPSearchResults searchResults = conn.search("ou=people,dc=mycompany,dc=com",
LDAPConnection.SCOPE_ONE, "cn=Surname Name", null, false);
LDAPEntry entry = searchResults.next();
LDAPConnection tmp = new LDAPConnection();
tmp.connect("ldap.mycompany.com", 389);
tmp.bind("suid=" + cnValue + "," + "ou=people,dc=mycompany,dc=com", "MYPASSWORD");
代码示例来源:origin: com.novell.ldap/jldap
rconn = new LDAPConnection( conn.getSocketFactory());
rconn.setConstraints( defSearchCons);
LDAPUrl url = new LDAPUrl(referrals[i]);
rconn.connect(url.getHost(),url.getPort());
if( rh != null) {
if( rh instanceof LDAPAuthHandler) {
rconn.bind( LDAP_V3, dn, pw);
ex = null;
refInfo = new ReferralInfo(rconn, referrals, url);
rconn.getConnection().setActiveReferral( refInfo);
break;
} catch( Throwable lex) {
rconn.disconnect();
rconn = null;
ex = lex;
"getReferralConnection: " +
"Compare host port " +
url.getHost() + "-" + rconn.getHost() +
" & " +
url.getPort() + "-" + rconn.getPort());
if( url.getHost().equalsIgnoreCase(rconn.getHost()) &&
(url.getPort() == rconn.getPort())) {
refInfo = new ReferralInfo(rconn, referrals, url);
break;
代码示例来源:origin: com.novell.ldap/jldap
Debug.trace( Debug.apiRequests, "read(" + toGet.toString() + ")");
LDAPConnection lconn = new LDAPConnection();
lconn.connect(toGet.getHost(),toGet.getPort());
LDAPEntry toReturn = lconn.read(toGet.getDN(),toGet.getAttributeArray());
if( Debug.LDAP_DEBUG) {
Debug.trace( Debug.apiRequests, "read: disconnect()");
lconn.disconnect();
return toReturn;
代码示例来源:origin: com.bbossgroups.pdp/pdp-ldap
public Map<String, String> validateUser(String userId, String password, String ldap) {
LDAPConnection lc = new LDAPConnection();
Map<String, String> response = null;
try {
lc.connect(ldapBean.getUrl(), ldapBean.getPort());
String dn = response.get("distinguishedName");
lc.bind(LDAPConnection.LDAP_V3, response.get("distinguishedName"), password);//如果口令为空,则会导致转化为匿名用户
if(lc.getAuthenticationDN() != null && lc.getAuthenticationDN().equals(dn))
response.put("successFlag", "1");
else
response.put("errMessage", new StringBuilder().append("Invalid credentials:required ").append(dn).append(",but reponse [").append(lc.getAuthenticationDN()).append("]").toString());
if (lc.isConnected()) {
try {
lc.disconnect();
} catch (LDAPException e) {
e.printStackTrace();
代码示例来源:origin: stackoverflow.com
LDAPConnection ld = new LDAPConnection();
ld.connect(LDAP_SERVER, LDAP_PORT);
LDAPSearchResults res = ld.search(BASE_DN, SEARCH_SCOPE, "(uid=" + THE_ID +")", null, false);
代码示例来源:origin: com.novell.ldap/jldap
"LDAPConnection.search(" + toGet.toString() + ")");
LDAPConnection lconn = new LDAPConnection();
lconn.connect(toGet.getHost(),toGet.getPort());
if( cons == null) {
cons = lconn.getSearchConstraints();
} else {
LDAPSearchResults toReturn = lconn.search(toGet.getDN(),
toGet.getScope(), toGet.getFilter(), toGet.getAttributeArray(),
false, cons);
lconn.disconnect();
return toReturn;
代码示例来源:origin: sakaiproject/sakai
public void bind(int i, String s, String s1, LDAPConstraints ldapconstraints) throws LDAPException {
bindAttempted = true;
super.bind(i, s, s1, ldapconstraints);
}
代码示例来源:origin: stackoverflow.com
import com.unboundid.ldap.sdk.Filter;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.SearchScope;
import com.unboundid.ldap.sdk.SearchResult;
public final class BSFilter {
public static void main(String... args) {
try {
Filter searchFilter =
Filter.create("cn=abc\"and'def");
LDAPConnection connection =
new LDAPConnection("localhost",1389);
SearchResult searchResult =
connection.search("dc=example,dc=com",SearchScope.ONE,
searchFilter,"1.1");
assert(searchResult.getSearchEntries().size() == 0);
} catch(LDAPException lex) {
lex.printStackTrace();
return;
}
}
}
代码示例来源:origin: stackoverflow.com
public static LDAPConnection getConnection() throws LDAPException {
// host, port, username and password
return new LDAPConnection("com.example.local", 389, "Administrator@com.example.local", "admin");
}
代码示例来源:origin: OpenNMS/opennms
/** {@inheritDoc} */
@Override
public void connect(final InetAddress address, final int port, final int timeout) throws IOException, Exception {
super.connect(address, port, timeout);
final LDAPConnection lc = new LDAPConnection(new TimeoutLDAPSocket(timeout));
lc.connect(InetAddressUtils.str(address), port);
}
}
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
LDAPSearchResults searchResults = null;
if (attributeList == null || attributeList.size() == 0) {
searchResults = lc.search(searchBase, searchScope, searchFilter, null, false, cons);
} else {
searchResults = lc.search(searchBase, searchScope, searchFilter, attributeList.toArray(new String[0]), false, cons);
代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core
this.connection = new LDAPConnection(ssf);
} else {
this.connection = new LDAPConnection();
LDAPConstraints constraints = this.connection.getConstraints();
constraints.setTimeLimit(1000);
constraints.setReferralFollowing(true);
constraints.setReferralHandler(new LDAPPluginReferralHandler(loginDN, password, context));
this.connection.setConstraints(constraints);
代码示例来源:origin: stackoverflow.com
LDAPConnection connection = new LDAPConnection( new LDAPJSSEStartTLSFactory() );
connection.connect(hostname, port);
connection.startTLS();
connection.bind(LDAPConnection.LDAP_V3, username+"@"+domain, password.getBytes());
代码示例来源:origin: stackoverflow.com
LDAPConnection connection = new LDAPConnection();
try
connection.connect("localhost", 10389);
try
compareResult = connection.compare(compareRequest);
if (compareResult.compareMatched())
代码示例来源:origin: stackoverflow.com
LDAPConnection ldc = new LDAPConnection()
ldc.connect(...);
if (ldc.isConnected())
{
do good stuff
}
else
{
getLDAPConnection(...);
}
代码示例来源:origin: stackoverflow.com
final String hostname = "the hostname";
final int port = PORT; // sometimes 389
try
{
final LDAPConnection connection = new LDAPConnection(hostname,port);
try
{
final SimpleBindRequest request = new SimpleBindRequest(bindDN,bindPassword);
final BindResult result = connection.bind(request);
}
finally
{
connection.close();
}
}
catch(final LDAPException ex)
{
handle the exception ...;
}
内容来源于网络,如有侵权,请联系作者删除!