mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Mark Craig
04.28.2012 e41f3472a5e929c9605376f108abd7c9c70f8c93
Another control covered in the LDAP controls chapter
2 files modified
78 ■■■■■ changed files
opendj3/opendj-ldap-sdk-examples/src/main/java/org/forgerock/opendj/examples/Controls.java 37 ●●●●● patch | view | raw | blame | history
opendj3/src/main/docbkx/dev-guide/chap-controls.xml 41 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk-examples/src/main/java/org/forgerock/opendj/examples/Controls.java
@@ -46,6 +46,7 @@
import org.forgerock.opendj.ldap.controls.EntryChangeNotificationResponseControl;
import org.forgerock.opendj.ldap.controls.GetEffectiveRightsRequestControl;
import org.forgerock.opendj.ldap.controls.ManageDsaITRequestControl;
import org.forgerock.opendj.ldap.controls.MatchedValuesRequestControl;
import org.forgerock.opendj.ldap.controls.PersistentSearchChangeType;
import org.forgerock.opendj.ldap.controls.PersistentSearchRequestControl;
import org.forgerock.opendj.ldap.requests.BindRequest;
@@ -104,7 +105,8 @@
            // usePersistentSearchRequestControl()
            //useGetEffectiveRightsRequestControl(connection);
            //usePersistentSearchRequestControl(connection);
            useManageDsaITRequestControl(connection);
            //useManageDsaITRequestControl(connection);
            useMatchedValuesRequestControl(connection);
            // TODO: The rest of the supported controls
        } catch (final ErrorResultException e) {
@@ -270,6 +272,39 @@
            }
        }
    }
    /**
     * Use the Matched Values Request Control to show read only one attribute
     * value.
     *
     * @param connection
     *            Active connection to LDAP server containing <a
     *            href="http://opendj.forgerock.org/Example.ldif"
     *            >Example.ldif</a> content.
     * @throws ErrorResultException
     *             Operation failed.
     */
    static void useMatchedValuesRequestControl(Connection connection) throws ErrorResultException {
        if (isSupported(MatchedValuesRequestControl.OID)) {
            final String dn = "uid=bjensen,ou=People,dc=example,dc=com";
            SearchRequest request =
                    Requests.newSearchRequest(dn, SearchScope.BASE_OBJECT,
                            "(objectclass=*)", "cn");
            final String filter = "cn=Babs Jensen";
            request.addControl(MatchedValuesRequestControl.newControl(true, filter));
            final SearchResultEntry entry = connection.searchSingleEntry(request);
            System.out.println("Reading entry with matched values request.");
            final LDIFEntryWriter writer = new LDIFEntryWriter(System.out);
            try {
                writer.writeEntry(entry);
                writer.close();
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
    }
    /**
     * Use the LDAP PersistentSearchRequestControl to set up a persistent
     * search. Also use the Entry Change Notification Response Control to get
opendj3/src/main/docbkx/dev-guide/chap-controls.xml
@@ -420,7 +420,46 @@
 
 <section xml:id="use-matched-values-request-control">
  <title>Matched Values Request Control</title>
  <para>TODO</para>
  <para>RFC 3876, <link xlink:href="http://tools.ietf.org/html/rfc3876"
  xlink:show="new"><citetitle>Returning Matched Values with the
  LDAPv3</citetitle></link>, describes a control that lets your application
  pass a filter in a search request getting a multivalued attribute such that
  the directory server only returns attribute values that match the
  filter.</para>
  <para>Barbara Jensen's entry contains two common name values,
  <literal>Barbara Jensen</literal> and <literal>Babs Jensen</literal>. The
  following excerpt retrieves only the latter.</para>
  <programlisting language="java">
if (isSupported(MatchedValuesRequestControl.OID)) {
    final String dn = "uid=bjensen,ou=People,dc=example,dc=com";
    SearchRequest request =
            Requests.newSearchRequest(dn, SearchScope.BASE_OBJECT,
                    "(objectclass=*)", "cn");
    final String filter = "cn=Babs Jensen";
    request.addControl(MatchedValuesRequestControl.newControl(true, filter));
    final SearchResultEntry entry = connection.searchSingleEntry(request);
    System.out.println("Reading entry with matched values request.");
    final LDIFEntryWriter writer = new LDIFEntryWriter(System.out);
    try {
        writer.writeEntry(entry);
        writer.close();
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
</programlisting>
  <para>OpenDJ directory server supports the matched values request
  control.</para>
  <programlisting language="ldif">Reading entry with matched values request.
dn: uid=bjensen,ou=People,dc=example,dc=com
cn: Babs Jensen
</programlisting>
 </section>
 
 <section xml:id="use-password-expired-control">