本文整理汇总了Java中com.unboundid.ldap.sdk.LDAPConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java LDAPConnection.close方法的具体用法?Java LDAPConnection.close怎么用?Java LDAPConnection.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.unboundid.ldap.sdk.LDAPConnection
的用法示例。
在下文中一共展示了LDAPConnection.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rolesFromDN
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
private Set<String> rolesFromDN(String userDN) throws LDAPException, GeneralSecurityException {
SearchRequest searchRequest = new SearchRequest(config.getRoleBaseDN(),
SearchScope.SUB, Filter.createEqualityFilter("uniqueMember", userDN));
Set<String> roles = Sets.newLinkedHashSet();
LDAPConnection connection = connectionFactory.getLDAPConnection();
try {
SearchResult sr = connection.search(searchRequest);
for (SearchResultEntry sre : sr.getSearchEntries()) {
X500Name x500Name = new X500Name(sre.getDN());
RDN[] rdns = x500Name.getRDNs(BCStyle.CN);
if (rdns.length == 0) {
logger.error("Could not create X500 Name for role:" + sre.getDN());
} else {
String commonName = IETFUtils.valueToString(rdns[0].getFirst().getValue());
roles.add(commonName);
}
}
} finally {
connection.close();
}
return roles;
}
示例2: modifyLdapEntry
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
/**
* Modify ldap entry.
*
* @param serverCon the server con
* @param dn the dn
* @param attr the attr
* @param add the add
*/
public static void modifyLdapEntry(final LDAPConnection serverCon, final String dn, final LdapAttribute attr,
final AttributeModificationType add) {
try {
final String address = "ldap://" + serverCon.getConnectedAddress() + ':' + serverCon.getConnectedPort();
try (Connection conn = DefaultConnectionFactory.getConnection(address)) {
try {
conn.open();
final ModifyOperation modify = new ModifyOperation(conn);
modify.execute(new ModifyRequest(dn, new AttributeModification(add, attr)));
} catch (final Exception e) {
LOGGER.debug(e.getMessage(), e);
}
}
} finally {
serverCon.close();
}
}
示例3: authenticate
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
public boolean authenticate(String username, String password) {
boolean success = false;
LDAPConnection ldapConnection = null;
String loginDn = getLoginDn(username);
if (loginDn != null) {
try {
ldapConnection = getUserConnection(loginDn, password);
if (ldapConnection != null) {
success = true;
}
}
catch (Exception e) {
LOG.error(e.getMessage(), e);
}
finally {
if (ldapConnection != null) {
ldapConnection.close();
}
}
}
return success;
}
示例4: serverDegradedTest
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
@Test
public void serverDegradedTest() throws Exception
{
ds.clear();
// Server is degraded, but 'available'.
addBaseEntry(new String[0],
new String[]{"low-disk-space-error"});
LDAPConnection connection = ds.getConnection();
try
{
StatusClient client = new StatusClient(connection);
Status status = client.getStatus();
assertFalse(status.isOK());
assertEquals(status.getServerStatus(), "degraded");
assertTrue(status.getServerAlerts().contains("low-disk-space-error"));
assertFalse(status.isOK());
}
finally
{
connection.close();
}
}
示例5: dnFromUsername
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
private String dnFromUsername(String username) throws LDAPException, GeneralSecurityException {
String baseDN = config.getUserBaseDN();
String lookup = String.format("(%s=%s)", config.getUserAttribute(), username);
SearchRequest searchRequest = new SearchRequest(baseDN, SearchScope.SUB, lookup);
LDAPConnection connection = connectionFactory.getLDAPConnection();
try {
SearchResult sr = connection.search(searchRequest);
if (sr.getEntryCount() == 0) {
throw new LDAPException(ResultCode.INVALID_CREDENTIALS);
}
return sr.getSearchEntries().get(0).getDN();
} finally {
connection.close();
}
}
示例6: getTree
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
private String getTree() throws LDAPException, ConfigurationException,
SenderException {
LDAPConnection connection = inMemoryDirectoryServer.getConnection();
LdapSender ldapSender = null;
try {
ldapSender = new LdapSender();
ldapSender.setLdapProviderURL("ldap://"
+ connection.getConnectedAddress() + ":"
+ connection.getConnectedPort());
ldapSender.setOperation("getTree");
Parameter parameter = new Parameter();
parameter.setName("entryName");
parameter.setValue(baseDNs);
ldapSender.addParameter(parameter);
ldapSender.configure();
ldapSender.open();
return ldapSender.sendMessage("dummy", "dummy");
} finally {
if (ldapSender != null) {
ldapSender.close();
}
if (connection != null) {
connection.close();
}
}
}
示例7: bootstrap
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
public static void bootstrap() throws Exception {
initDirectoryServer();
getDirectory().populateEntries(new ClassPathResource("ldif/users-x509.ldif").getInputStream());
/**
* Dynamically set the attribute value to the crl content.
* Encode it as base64 first. Doing this in the code rather
* than in the ldif file to ensure the attribute can be populated
* without dependencies on the classpath and or filesystem.
*/
final Collection<LdapEntry> col = getDirectory().getLdapEntries();
for (final LdapEntry ldapEntry : col) {
if (ldapEntry.getDn().equals(DN)) {
final LdapAttribute attr = new LdapAttribute(true);
byte[] value = new byte[1024];
IOUtils.read(new ClassPathResource("userCA-valid.crl").getInputStream(), value);
value = CompressionUtils.encodeBase64ToByteArray(value);
attr.setName("certificateRevocationList");
attr.addBinaryValue(value);
final LDAPConnection serverCon = getDirectory().getConnection();
final String address = "ldap://" + serverCon.getConnectedAddress() + ':' + serverCon.getConnectedPort();
final Connection conn = DefaultConnectionFactory.getConnection(address);
conn.open();
final ModifyOperation modify = new ModifyOperation(conn);
modify.execute(new ModifyRequest(ldapEntry.getDn(),
new AttributeModification(AttributeModificationType.ADD, attr)));
conn.close();
serverCon.close();
return;
}
}
}
示例8: bootstrap
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
public static void bootstrap() throws Exception {
initDirectoryServer();
getDirectory().populateEntries(new ClassPathResource("ldif/users-x509.ldif").getInputStream());
/**
* Dynamically set the attribute value to the crl content.
* Encode it as base64 first. Doing this in the code rather
* than in the ldif file to ensure the attribute can be populated
* without dependencies on the classpath and or filesystem.
*/
final Collection<LdapEntry> col = getDirectory().getLdapEntries();
for (final LdapEntry ldapEntry : col) {
if (ldapEntry.getDn().equals(DN)) {
final LdapAttribute attr = new LdapAttribute(true);
byte[] value = new byte[1024];
IOUtils.read(new ClassPathResource("userCA-valid.crl").getInputStream(), value);
value = CompressionUtils.encodeBase64ToByteArray(value);
attr.setName("certificateRevocationList");
attr.addBinaryValue(value);
final LDAPConnection serverCon = getDirectory().getConnection();
final String address = "ldap://" + serverCon.getConnectedAddress() + ":" + serverCon.getConnectedPort();
final Connection conn = DefaultConnectionFactory.getConnection(address);
conn.open();
final ModifyOperation modify = new ModifyOperation(conn);
modify.execute(new ModifyRequest(ldapEntry.getDn(),
new AttributeModification(AttributeModificationType.ADD, attr)));
conn.close();
serverCon.close();
return;
}
}
}
示例9: validateCredentials
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
@Override
public void validateCredentials(String username, String password, Handler<AsyncResult<Boolean>> resultHandler) {
try {
LDAPConnection conn = getConnection(username, password);
boolean isConn = conn.isConnected();
conn.close();
resultHandler.handle(Future.succeededFuture(isConn));
} catch (Throwable t) {
resultHandler.handle(Future.failedFuture(t));
}
}
示例10: serverUnavailableTest
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
@Test
public void serverUnavailableTest() throws Exception
{
ds.clear();
// Server is both unavailable and degraded.
addBaseEntry(new String[]{"server-shutting-down"},
new String[]{"low-disk-space-error"});
LDAPConnection connection = ds.getConnection();
try
{
StatusClient client =
new StatusClient(connection);
Status status = client.getStatus();
assertFalse(status.isOK());
assertEquals(status.getServerStatus(), "unavailable");
assertTrue(status.getServerAlerts().contains("server-shutting-down"));
assertTrue(status.getServerAlerts().contains("low-disk-space-error"));
assertFalse(status.isOK());
}
finally
{
connection.close();
}
}
示例11: getPasswordLastSet
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
private long getPasswordLastSet() {
long pwdLastSet = -1;
LDAPConnection ldapConnection = null;
try {
ldapConnection = getLdapConnection(userDn, getLdapPassword(), url);
String[] attributes = new String[] {Constants.AD_PWD_LAST_SET};
String filter = "(" + Constants.AD_SAM_ACCOUNT_NAME + "=" + username + ")";
SearchResult searchResult = ldapConnection.search(baseDn, SearchScope.SUB, filter, attributes);
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
Attribute pwdLastSetAttribute = searchResultEntry.getAttribute(Constants.AD_PWD_LAST_SET);
pwdLastSet = pwdLastSetAttribute.getValueAsLong();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (ldapConnection != null) {
ldapConnection.close();
}
}
return pwdLastSet;
}
示例12: getMaxPasswordAge
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
private long getMaxPasswordAge() {
long maxPwdAge = -1;
LDAPConnection ldapConnection = null;
try {
ldapConnection = getLdapConnection(userDn, getLdapPassword(), url);
String[] attributes = new String[] {Constants.AD_MAX_PWD_AGE};
String filter = "(" + Constants.AD_OBJECT_CLASS + "=" + Constants.AD_DOMAIN + ")";
SearchResult searchResult = ldapConnection.search(baseDn, SearchScope.BASE, filter, attributes);
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
Attribute maxPwdAgeAttribute = searchResultEntry.getAttribute(Constants.AD_MAX_PWD_AGE);
maxPwdAge = maxPwdAgeAttribute.getValueAsLong();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (ldapConnection != null) {
ldapConnection.close();
}
}
return maxPwdAge;
}
示例13: updateAttribute
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
@Test
public void updateAttribute() throws SAXException, IOException,
ConfigurationException, SenderException, LDAPException {
String result;
LDAPConnection connection = inMemoryDirectoryServer.getConnection();
LdapSender ldapSender = null;
try {
ldapSender = new LdapSender();
ldapSender.setLdapProviderURL("ldap://"
+ connection.getConnectedAddress() + ":"
+ connection.getConnectedPort());
ldapSender.setOperation("update");
Parameter parameter = new Parameter();
parameter.setName("entryName");
parameter.setValue("cn=LEA Administrator,ou=groups,ou=development,"
+ baseDNs);
ldapSender.addParameter(parameter);
ldapSender.configure();
ldapSender.open();
result = ldapSender
.sendMessage(
"dummy",
"<attributes><attribute name=\"mail\"><value>[email protected]</value></attribute></attributes>");
} finally {
if (ldapSender != null) {
ldapSender.close();
}
if (connection != null) {
connection.close();
}
}
assertEquals("<LdapResult>Success</LdapResult>", result);
compareXML("Ldap/expected/updateAttribute.xml", getTree());
}
示例14: updateNewEntry
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
@Test
public void updateNewEntry() throws SAXException, IOException,
ConfigurationException, SenderException, LDAPException {
String result;
LDAPConnection connection = inMemoryDirectoryServer.getConnection();
LdapSender ldapSender = null;
try {
ldapSender = new LdapSender();
ldapSender.setLdapProviderURL("ldap://"
+ connection.getConnectedAddress() + ":"
+ connection.getConnectedPort());
ldapSender.setOperation("update");
Parameter parameter = new Parameter();
parameter.setName("entryName");
parameter.setValue("cn=LEA Administrator,ou=groups,ou=development,"
+ baseDNs);
ldapSender.addParameter(parameter);
Parameter parameter2 = new Parameter();
parameter2.setName("newEntryName");
parameter2
.setValue("cn=LEA Administrator,ou=people,ou=development,"
+ baseDNs);
ldapSender.addParameter(parameter2);
ldapSender.configure();
ldapSender.open();
result = ldapSender.sendMessage("dummy", "<dummy/>");
} finally {
if (ldapSender != null) {
ldapSender.close();
}
if (connection != null) {
connection.close();
}
}
assertEquals("<LdapResult>Success</LdapResult>", result);
compareXML("Ldap/expected/updateNewEntry.xml", getTree());
}
示例15: deleteAttribute
import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
@Test
public void deleteAttribute() throws SAXException, IOException,
ConfigurationException, SenderException, LDAPException {
String result;
LDAPConnection connection = inMemoryDirectoryServer.getConnection();
LdapSender ldapSender = null;
try {
ldapSender = new LdapSender();
ldapSender.setLdapProviderURL("ldap://"
+ connection.getConnectedAddress() + ":"
+ connection.getConnectedPort());
ldapSender.setOperation("delete");
Parameter parameter = new Parameter();
parameter.setName("entryName");
parameter.setValue("cn=LEA Administrator,ou=groups,ou=development,"
+ baseDNs);
ldapSender.addParameter(parameter);
ldapSender.configure();
ldapSender.open();
result = ldapSender
.sendMessage(
"dummy",
"<attributes><attribute name=\"mail\"><value>[email protected]</value></attribute></attributes>");
} finally {
if (ldapSender != null) {
ldapSender.close();
}
if (connection != null) {
connection.close();
}
}
assertEquals("<LdapResult>Success</LdapResult>", result);
compareXML("Ldap/expected/delete.xml", getTree());
}