@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(); }
/** * 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(); }
@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 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(); }
/** * Indicates whether the two provided strings represent the same DN. * * @param s1 The string representation of the first DN for which to make the * determination. It must not be {@code null}. * @param s2 The string representation of the second DN for which to make * the determination. It must not be {@code null}. * * @return {@code true} if the provided strings represent the same DN, or * {@code false} if not. * * @throws LDAPException If either of the provided strings cannot be parsed * as a DN. */ public static boolean equals(final String s1, final String s2) throws LDAPException { return new DN(s1).equals(new DN(s2)); }
/** * Retrieves a normalized representation of the DN with the provided string * representation. * * @param s The string representation of the DN to normalize. It must * not be {@code null}. * @param schema The schema to use to generate the normalized string * representation of the DN. It may be {@code null} if no * schema is available. * * @return The normalized representation of the DN with the provided string * representation. * * @throws LDAPException If the provided string cannot be parsed as a DN. */ public static String normalize(final String s, final Schema schema) throws LDAPException { return new DN(s, schema).toNormalizedString(); }
/** * Appends a string representation of this DN to the provided buffer. * * @param buffer The buffer to which to append the string representation of * this DN. */ public void toString(final StringBuilder buffer) { toString(buffer, false); }
/** * 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 string representation of the DN that is the parent for the * DN with the provided string representation. Note that neither the null DN * nor DNs consisting of a single RDN component will be considered to have * parent DNs. * * @param s The string representation of the DN for which to retrieve the * parent. It must not be {@code null}. * * @return The DN that is the parent for this DN, or {@code null} if there * is no parent. * * @throws LDAPException If the provided string cannot be parsed as a DN. */ public static String getParentString(final String s) throws LDAPException { return new DN(s).getParentString(); }
/** * Indicates whether this DN falls within the range of the provided search * base DN and scope. * * @param baseDN The base DN for which to make the determination. It must * not be {@code null}. * @param scope The scope for which to make the determination. It must not * be {@code null}. * * @return {@code true} if this DN is within the range of the provided base * and scope, or {@code false} if not. * * @throws LDAPException If a problem occurs while making the determination. */ public boolean matchesBaseAndScope(final String baseDN, final SearchScope scope) throws LDAPException { return matchesBaseAndScope(new DN(baseDN), scope); }
/** * Creates a new move subtree transformation with the provided information. * * @param sourceDN The source base DN to be replaced with the target base * DN. It must not be {@code null}. * @param targetDN The target base DN to use to replace the source base DN. * It must not be {@code null}. */ public MoveSubtreeTransformation(final DN sourceDN, final DN targetDN) { this.sourceDN = sourceDN; targetRDNs = Arrays.asList(targetDN.getRDNs()); }
/** * 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(); }
/** * Returns the authzId string representation of the specified * distinguished name (DN). * * @param dn The distinguished name (DN). Must not be {@code null}. * * @return The authzId string. */ private static String toAuthzIdString(final DN dn) { if (dn == null) throw new IllegalArgumentException("The authzId DN must not be null"); if (dn.equals(DN.NULL_DN)) return "dn:"; else return "dn:" + dn.toNormalizedString(); }
/** * Logs the configuration details at INFO level. */ @Override public void log() { Logger log = LogManager.getLogger(LOG_CATEGORY); if (dn.equals(DN.NULL_DN)) log.info("[CM1050] Directory user DN: [anonymous]"); else log.info("[CM1050] Directory user DN: {}", dn); } }
/** * Indicates whether the DN with the provided string representation is equal * to this DN. * * @param s The string representation of the DN to compare with this DN. * * @return {@code true} if the DN with the provided string representation is * equal to this DN, or {@code false} if not. * * @throws LDAPException If the provided string cannot be parsed as a DN. */ public boolean equals(final String s) throws LDAPException { if (s == null) { return false; } return equals(new DN(s)); }
/** * 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 a normalized representation of the DN with the provided string * representation. * * @param s The string representation of the DN to normalize. It must * not be {@code null}. * @param schema The schema to use to generate the normalized string * representation of the DN. It may be {@code null} if no * schema is available. * * @return The normalized representation of the DN with the provided string * representation. * * @throws LDAPException If the provided string cannot be parsed as a DN. */ public static String normalize(final String s, final Schema schema) throws LDAPException { return new DN(s, schema).toNormalizedString(); }
/** * Creates a new distinguished name (DN) identity. * * @param dn The DN, must not be {@code null}. */ public DNIdentity(final DN dn) { super(dn.toString()); this.dn = dn; }