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; }
@Override public void start() { if (isRunning()) { return; } try { InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(this.defaultPartitionSuffix); config.addAdditionalBindCredentials("uid=admin,ou=system", "secret"); config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", this.port)); config.setEnforceSingleStructuralObjectClass(false); config.setEnforceAttributeSyntaxCompliance(true); DN dn = new DN(this.defaultPartitionSuffix); Entry entry = new Entry(dn); entry.addAttribute("objectClass", "top", "domain", "extensibleObject"); entry.addAttribute("dc", dn.getRDN().getAttributeValues()[0]); InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config); directoryServer.add(entry); importLdif(directoryServer); directoryServer.startListening(); this.port = directoryServer.getListenPort(); this.directoryServer = directoryServer; this.running = true; } catch (LDAPException ex) { throw new RuntimeException("Server startup failed", ex); } }
@Before public void startDirectoryServer() throws LDAPException { InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", PORT); InMemoryDirectoryServerConfig serverConfig = new InMemoryDirectoryServerConfig(new DN(BASE_DN)); serverConfig.setListenerConfigs(listenerConfig); serverConfig.addAdditionalBindCredentials(USER_DN, PASSWORD); serverConfig.setSchema(null); server = new InMemoryDirectoryServer(serverConfig); server.importFromLDIF(false, "src/test/resources/ldap-config.ldif"); server.startListening(); }
/** * Creates a compact attribute from the provided attribute. * * @param attribute The attribute to use to create this compact attribute. */ CompactAttribute(final Attribute attribute) { name = internName(attribute.getName()); values = attribute.getValueByteArrays(); }
/** * Creates a search request containing the base DN, scope, filter, and * requested attributes from this LDAP URL. * * @return The search request created from the base DN, scope, filter, and * requested attributes from this LDAP URL. */ public SearchRequest toSearchRequest() { return new SearchRequest(baseDN.toString(), scope, filter, attributes); }
/** * Indicates whether the compare operation matched the target entry. * * @return {@code true} if the compare operation matched the target entry, * or {@code false} if not. */ public boolean compareMatched() { return (getResultCode().equals(ResultCode.COMPARE_TRUE)); } }
/** * Retrieves the RDN for this entry. * * @return The RDN for this entry, or {@code null} if the DN is the null DN. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public final RDN getRDN() throws LDAPException { return getParsedDN().getRDN(); }
/** * Retrieves the RDN for this entry. * * @return The RDN for this entry, or {@code null} if the DN is the null DN. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public RDN getRDN() throws LDAPException { return getParsedDN().getRDN(); }
public static void releaseConnection(LDAPConnection connection) { if (connection != null && connection.getConnectionPool() != null) connection.getConnectionPool().releaseConnection(connection); }
/** * Appends an LDIF representation of this entry to the provided buffer. * * @param buffer The buffer to which the LDIF representation of this * entry should be written. * @param wrapColumn The column at which long lines should be wrapped. A * value less than or equal to two indicates that no * wrapping should be performed. */ public void toLDIF(final ByteStringBuffer buffer, final int wrapColumn) { toEntry().toLDIF(buffer, wrapColumn); }
/** * {@inheritDoc} */ @Override() public void releaseDefunctConnection(final LDAPConnection connection) { if (connection == null) { return; } connection.setConnectionPoolName(connectionPoolName); poolStatistics.incrementNumConnectionsClosedDefunct(); handleDefunctConnection(connection); }
public static void releaseDefunct(LDAPConnection connection) { if (connection != null && connection.getConnectionPool() != null) connection.getConnectionPool().releaseDefunctConnection(connection); }
public static void releaseConnectionAfterException(LDAPConnection connection, LDAPException e) { if (connection != null && connection.getConnectionPool() != null) connection.getConnectionPool().releaseConnectionAfterException(connection, e); }
@Override public boolean hasAttribute(String name) { return rdn.hasAttribute(name); } }
/** * Creates a compact attribute from the provided attribute. * * @param attribute The attribute to use to create this compact attribute. */ CompactAttribute(final Attribute attribute) { name = internName(attribute.getName()); values = attribute.getValueByteArrays(); }
/** * Retrieves the RDN for this entry. * * @return The RDN for this entry, or {@code null} if the DN is the null DN. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public final RDN getRDN() throws LDAPException { return getParsedDN().getRDN(); }
/** * Retrieves the RDN for this entry. * * @return The RDN for this entry, or {@code null} if the DN is the null DN. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public RDN getRDN() throws LDAPException { return getParsedDN().getRDN(); }
public static void releaseConnection(LDAPConnection connection) { if (connection != null && connection.getConnectionPool() != null) connection.getConnectionPool().releaseConnection(connection); }
/** * Appends an LDIF representation of this entry to the provided buffer. * * @param buffer The buffer to which the LDIF representation of this * entry should be written. * @param wrapColumn The column at which long lines should be wrapped. A * value less than or equal to two indicates that no * wrapping should be performed. */ public void toLDIF(final ByteStringBuffer buffer, final int wrapColumn) { toEntry().toLDIF(buffer, wrapColumn); }