@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(); }
@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); } }
/** * Retrieves the parsed DN for this entry. * * @return The parsed DN for this entry. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public DN getParsedDN() throws LDAPException { return new DN(dn); }
/** * Retrieves the parsed DN for this entry. * * @return The parsed DN for this entry. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public DN getParsedDN() throws LDAPException { return new DN(dn); }
public DefaultLdapDn(String dn) throws LDAPException { this.dn = new DN(dn); }
public DefaultLdapDn(String dn) throws LDAPException { this.dn = new DN(dn); }
/** * Retrieves the parsed DN for this entry. * * @return The parsed DN for this entry. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public final DN getParsedDN() throws LDAPException { if (parsedDN == null) { parsedDN = new DN(dn, schema); } return parsedDN; }
/** * Retrieves the parsed DN for this LDIF change record. * * @return The DN for this LDIF change record. * * @throws LDAPException If a problem occurs while trying to parse the DN. */ public final DN getParsedDN() throws LDAPException { if (parsedDN == null) { parsedDN = new DN(dn); } return parsedDN; }
@Override public DN resolve(final String attribute) throws DNResolveException { if (attribute == null || attribute.isEmpty()) throw new IllegalArgumentException("Bad attribute value: must not be null or empty string"); final String dnString = template.replaceAll("%u", attribute); try { return new DN(dnString); } catch (LDAPException e) { throw new DNResolveException("The syntax of the resolved DN is invalid"); } } }
/** * Retrieves a read-only representation the entry with the specified DN, if * it exists. * * @param dn The DN of the entry to retrieve. * * @return The requested entry, or {@code null} if no entry exists with the * given DN. * * @throws LDAPException If the provided DN is malformed. */ public ReadOnlyEntry getEntry(final String dn) throws LDAPException { return getEntry(new DN(dn, schemaRef.get())); }
/** * Retrieves the parent DN for this entry. * * @return The parent DN for this entry, or {@code null} if there is no * parent. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public final DN getParentDN() throws LDAPException { if (parsedDN == null) { parsedDN = new DN(dn, schema); } return parsedDN.getParent(); }
/** * Retrieves the set of RDNs that comprise the DN with the provided string * representation. * * @param s The string representation of the DN for which to retrieve the * RDNs. It must not be {@code null}. * * @return The set of RDNs that comprise the DN with the provided string * representation. * * @throws LDAPException If the provided string cannot be parsed as a DN. */ public static RDN[] getRDNs(final String s) throws LDAPException { return new DN(s).getRDNs(); }
/** * Retrieves the set of string representations of the RDNs that comprise this * DN. * * @param s The string representation of the DN for which to retrieve the * RDN strings. It must not be {@code null}. * * @return The set of string representations of the RDNs that comprise this * DN. * * @throws LDAPException If the provided string cannot be parsed as a DN. */ public static String[] getRDNStrings(final String s) throws LDAPException { return new DN(s).getRDNStrings(); }
/** * Retrieves the parent DN for this entry. * * @return The parent DN for this entry, or {@code null} if there is no * parent. * * @throws LDAPException If the DN string cannot be parsed as a valid DN. */ public final DN getParentDN() throws LDAPException { if (parsedDN == null) { parsedDN = new DN(dn, schema); } return parsedDN.getParent(); }
@Override public boolean delete(final Object key) { // The CacheWriter should remove from the external storage the entry identified by the specified key. // Note that keys will be in the cache's native format, which means that if the cache is being used by a remoting protocol // such as HotRod or REST and compatibility mode has not been enabled, then they will be encoded in a byte[]. Loggers.LDAP_LOG.trace("[IL0252] LDAP store: Deleting {} entry with key {}", getCacheName(), key); DN dn = new DN(ldapEntryTransformer.resolveRDN(resolveKey(key)), config.ldapDirectory.baseDN); return ldapConnector.deleteEntry(dn); }
@Override public boolean delete(final Object key) { // The CacheWriter should remove from the external storage the entry identified by the specified key. // Note that keys will be in the cache's native format, which means that if the cache is being used by a remoting protocol // such as HotRod or REST and compatibility mode has not been enabled, then they will be encoded in a byte[]. Loggers.LDAP_LOG.trace("[IL0252] LDAP store: Deleting {} entry with key {}", getCacheName(), key); DN dn = new DN(ldapEntryTransformer.resolveRDN(resolveKey(key)), config.ldapDirectory.baseDN); return ldapConnector.deleteEntry(dn); }
@Override public boolean contains(final Object key) { // This method will be invoked by the PersistenceManager to determine if the loader contains the specified key. // The implementation should be as fast as possible, e.g. it should strive to transfer the least amount of data possible // from the external storage to perform the check. Also, if possible, make sure the field is indexed on the external storage // so that its existence can be determined as quickly as possible. // // Note that keys will be in the cache's native format, which means that if the cache is being used by a remoting protocol // such as HotRod or REST and compatibility mode has not been enabled, then they will be encoded in a byte[]. Loggers.LDAP_LOG.trace("[IL0250] LDAP store: Checking {} cache key {}", getCacheName(), key); DN dn = new DN(ldapEntryTransformer.resolveRDN(resolveKey(key)), config.ldapDirectory.baseDN); return ldapConnector.entryExists(dn); }
@Override public boolean contains(final Object key) { // This method will be invoked by the PersistenceManager to determine if the loader contains the specified key. // The implementation should be as fast as possible, e.g. it should strive to transfer the least amount of data possible // from the external storage to perform the check. Also, if possible, make sure the field is indexed on the external storage // so that its existence can be determined as quickly as possible. // // Note that keys will be in the cache's native format, which means that if the cache is being used by a remoting protocol // such as HotRod or REST and compatibility mode has not been enabled, then they will be encoded in a byte[]. Loggers.LDAP_LOG.trace("[IL0250] LDAP store: Checking {} cache key {}", getCacheName(), key); DN dn = new DN(ldapEntryTransformer.resolveRDN(resolveKey(key)), config.ldapDirectory.baseDN); return ldapConnector.entryExists(dn); }
private EmbeddedDirectoryServer(@NotNull String dn, @NotNull URL ldifStream) throws Exception { baseDn = new DN(dn); final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(dn); server = new InMemoryDirectoryServer(config); try (InputStream in = ldifStream.openStream()) { server.importFromLDIF(false, new LDIFReader(in)); } server.startListening(); }
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName, String defaultPartitionSuffix, int port) throws Exception { InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig( defaultPartitionSuffix); config.addAdditionalBindCredentials("uid=admin,ou=system", "secret"); config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", port)); config.setEnforceSingleStructuralObjectClass(false); config.setEnforceAttributeSyntaxCompliance(true); Entry entry = new Entry(new DN(defaultPartitionSuffix)); entry.addAttribute("objectClass", "top", "domain", "extensibleObject"); entry.addAttribute("dc", defaultPartitionName); InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config); directoryServer.add(entry); directoryServer.startListening(); return new EmbeddedLdapServer(directoryServer); }