| Frequently Asked Questions

## Names

> #### Why do I get an empty string as a name in my `SearchResult`?

> `getName()` always returns a name relative to the target context of the search. So, if the target context satisfies the search filter, then the name returned will be "" (the empty name) because that is the name relative to the target context. See the Searches lesson for details.

> #### Why do I get a URL string as a name in my `SearchResult`?

> The LDAP entry was retrieved by following either an alias or a referral, so its name is a URL. See the Searches lesson for details.

> #### Is the `Name` argument to the `Context` and `DirContext` methods a `CompoundName` or a `CompositeName`?

> The string forms accept the string representation of a composite name. That is, using a string name is equivalent to calling `new CompositeName(stringName)` and passing the results to the `Context`/`DirContext` method. The `Name` argument can be any object that implements the `Name` interface. If it is an instance of `CompositeName`, then the name is treated as a composite name; otherwise, it is treated as a compound name.

> #### Can I pass the name I got back from `NameParser` to `Context` methods?

> This is related to the previous question. Yes, you can. `NameParser.parse()` returns a compound name that implements the `Name` interface. This name can be passed to the `Context` methods, which will interpret it as a compound name.

> #### What's the relationship between the name I use for the `Context.SECURITY_PRINCIPAL` property and the directory?

> You can think of the principal name as coming from a different namespace than the directory. See RFC 2829 and the Security lesson for details on LDAP authentication mechanisms. Sun's LDAP service provider accepts a string principal name, which it passes directly to the LDAP server. Some LDAP servers accept DNs, whereas others support the schemes proposed by RFC 2829.

> #### Why are there strange quotation marks and escapes in the names that I read from the directory?

> Sun's LDAP name parser is conservative with respect to quoting rules, but it nevertheless produces "correct" names. Also, remember that the names of entries returned by `NamingEnumeration`s are composite names that can be passed back to the `Context` and `DirContext` methods. So, if the name contains a character that conflicts with the composite name syntax (such as the forward slash character "/"), then the LDAP provider will provide an encoding to ensure that the slash character will be treated as part of the LDAP name rather than as a composite name separator.

> #### How do I get an LDAP entry's full DN?

> You can use `Context.getNameInNamespace()`.

| Frequently Asked Questions