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

Gaetan Boismal
25.11.2015 1bc6e4214cb328452836b2955a95c3d17a98cf79
OPENDJ-1901 PR-22 rest2ldap fix reference searchFilter

We documented that searchFilter is supported in attribute reference mapping but it was
actually not implemented.
This commit fixes the bug by doing a search on the entry instead of a read.
1 files modified
19 ■■■■■ changed files
opendj-sdk/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java 19 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java
@@ -319,9 +319,11 @@
                                           // Combine values into a single JSON array.
                                           final List<Object> result = new ArrayList<>(value.size());
                                           for (final JsonValue e : value) {
                                               result.add(e.getObject());
                                               if (e != null) {
                                                   result.add(e.getObject());
                                               }
                                           }
                                           return new JsonValue(result);
                                           return result.isEmpty() ? null : new JsonValue(result);
                                       }
                                   }
                               });
@@ -344,7 +346,11 @@
        return requestState.getConnection().thenAsync(new AsyncFunction<Connection, JsonValue, ResourceException>() {
            @Override
            public Promise<JsonValue, ResourceException> apply(Connection connection) throws ResourceException {
                return connection.readEntryAsync(dn, requestedLDAPAttributes)
                final Filter searchFilter = filter != null ? filter : Filter.alwaysTrue();
                final String[] attributes = requestedLDAPAttributes.toArray(new String[requestedLDAPAttributes.size()]);
                final SearchRequest request = newSearchRequest(dn, SearchScope.BASE_OBJECT, searchFilter, attributes);
                return connection.searchSingleEntryAsync(request)
                        .thenAsync(new AsyncFunction<SearchResultEntry, JsonValue, ResourceException>() {
                            @Override
                            public Promise<JsonValue, ResourceException> apply(final SearchResultEntry result) {
@@ -353,12 +359,11 @@
                        }, new AsyncFunction<LdapException, JsonValue, ResourceException>() {
                            @Override
                            public Promise<JsonValue, ResourceException> apply(final LdapException error) {
                                if (!(error instanceof EntryNotFoundException)) {
                                    return Promises.newExceptionPromise(asResourceException(error));
                                } else {
                                    // The referenced entry does not exist so ignore it since it cannot be mapped.
                                if (error instanceof EntryNotFoundException) {
                                    // Ignore missing entry since it cannot be mapped.
                                    return Promises.newResultPromise(null);
                                }
                                return Promises.newExceptionPromise(asResourceException(error));
                            }
                        });
            }