| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.opendj.ldif.ChangeRecord; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.forgerock.util.promise.Promises; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | |
| | | import static java.util.Arrays.*; |
| | | |
| | |
| | | |
| | | @Override |
| | | public void handleError(ResourceException error) { |
| | | promise.handleError(error); |
| | | promise.handleException(error); |
| | | |
| | | } |
| | | |
| | |
| | | addRequest.addControl(PostReadRequestControl.newControl(false, attributes)); |
| | | } |
| | | c.getConnection().applyChangeAsync(addRequest) |
| | | .onSuccess(postUpdateSuccessHandler(c, h)) |
| | | .onFailure(postUpdateFailureHandler(h)); |
| | | .thenOnResult(postUpdateResultHandler(c, h)) |
| | | .thenOnException(postUpdateExceptionHandler(h)); |
| | | } |
| | | }); |
| | | } |
| | |
| | | deleteRequest.addControl(SubtreeDeleteRequestControl.newControl(true)); |
| | | } |
| | | addAssertionControl(deleteRequest, request.getRevision()); |
| | | c.getConnection().applyChangeAsync(deleteRequest).onSuccess(postUpdateSuccessHandler(c, h)) |
| | | .onFailure(postUpdateFailureHandler(h)); |
| | | c.getConnection().applyChangeAsync(deleteRequest).thenOnResult(postUpdateResultHandler(c, h)) |
| | | .thenOnException(postUpdateExceptionHandler(h)); |
| | | } catch (final Exception e) { |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | |
| | | final SearchRequest searchRequest = nameStrategy.createSearchRequest(c, getBaseDN(c), resourceId) |
| | | .addAttribute(attributes); |
| | | c.getConnection().searchSingleEntryAsync(searchRequest) |
| | | .onSuccess(postEmptyPatchSuccessHandler(c, request, h)) |
| | | .onFailure(postEmptyPatchFailureHandler(h)); |
| | | .thenOnResult(postEmptyPatchResultHandler(c, request, h)) |
| | | .thenOnException(postEmptyPatchExceptionHandler(h)); |
| | | } |
| | | }); |
| | | } else { |
| | |
| | | promises.add(handler.promise); |
| | | } |
| | | |
| | | Promises.when(promises).onSuccess(new SuccessHandler<List<List<Modification>>>() { |
| | | @Override |
| | | public void handleResult(final List<List<Modification>> result) { |
| | | // The patch operations have been converted successfully. |
| | | try { |
| | | final ModifyRequest modifyRequest = newModifyRequest(dn); |
| | | Promises.when(promises).thenOnResult( |
| | | new org.forgerock.util.promise.ResultHandler<List<List<Modification>>>() { |
| | | @Override |
| | | public void handleResult(final List<List<Modification>> result) { |
| | | // The patch operations have been converted successfully. |
| | | try { |
| | | final ModifyRequest modifyRequest = newModifyRequest(dn); |
| | | |
| | | // Add the modifications. |
| | | for (final List<Modification> modifications : result) { |
| | | if (modifications != null) { |
| | | modifyRequest.getModifications().addAll(modifications); |
| | | // Add the modifications. |
| | | for (final List<Modification> modifications : result) { |
| | | if (modifications != null) { |
| | | modifyRequest.getModifications().addAll(modifications); |
| | | } |
| | | } |
| | | } |
| | | |
| | | final List<String> attributes = asList(getLDAPAttributes(c, request.getFields())); |
| | | if (modifyRequest.getModifications().isEmpty()) { |
| | | /* |
| | | * This patch is a no-op so just read the entry and check its version. |
| | | */ |
| | | c.getConnection().readEntryAsync(dn, attributes) |
| | | .onSuccess(postEmptyPatchSuccessHandler(c, request, h)) |
| | | .onFailure(postEmptyPatchFailureHandler(h)); |
| | | } else { |
| | | // Add controls and perform the modify request. |
| | | if (config.readOnUpdatePolicy() == CONTROLS) { |
| | | modifyRequest.addControl(PostReadRequestControl.newControl(false, attributes)); |
| | | final List<String> attributes = asList(getLDAPAttributes(c, request.getFields())); |
| | | if (modifyRequest.getModifications().isEmpty()) { |
| | | /* |
| | | * This patch is a no-op so just read the entry and check its version. |
| | | */ |
| | | c.getConnection().readEntryAsync(dn, attributes) |
| | | .thenOnResult(postEmptyPatchResultHandler(c, request, h)) |
| | | .thenOnException(postEmptyPatchExceptionHandler(h)); |
| | | } else { |
| | | // Add controls and perform the modify request. |
| | | if (config.readOnUpdatePolicy() == CONTROLS) { |
| | | modifyRequest.addControl( |
| | | PostReadRequestControl.newControl(false, attributes)); |
| | | } |
| | | if (config.usePermissiveModify()) { |
| | | modifyRequest.addControl(PermissiveModifyRequestControl.newControl(true)); |
| | | } |
| | | addAssertionControl(modifyRequest, request.getRevision()); |
| | | c.getConnection().applyChangeAsync(modifyRequest) |
| | | .thenOnResult(postUpdateResultHandler(c, h)) |
| | | .thenOnException(postUpdateExceptionHandler(h)); |
| | | } |
| | | if (config.usePermissiveModify()) { |
| | | modifyRequest.addControl(PermissiveModifyRequestControl.newControl(true)); |
| | | } |
| | | addAssertionControl(modifyRequest, request.getRevision()); |
| | | c.getConnection().applyChangeAsync(modifyRequest) |
| | | .onSuccess(postUpdateSuccessHandler(c, h)) |
| | | .onFailure(postUpdateFailureHandler(h)); |
| | | } catch (final Exception e) { |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | | } catch (final Exception e) { |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<ResourceException>() { |
| | | @Override |
| | | public void handleError(ResourceException error) { |
| | | h.handleError(asResourceException(error)); |
| | | } |
| | | }); |
| | | }).thenOnException(new ExceptionHandler<ResourceException>() { |
| | | @Override |
| | | public void handleException(ResourceException exception) { |
| | | h.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | } |
| | | })); |
| | | } |
| | |
| | | return true; |
| | | } |
| | | |
| | | }).onSuccess(new SuccessHandler<Result>() { |
| | | }).thenOnResult(new org.forgerock.util.promise.ResultHandler<Result>() { |
| | | @Override |
| | | public void handleResult(Result result) { |
| | | synchronized (sequenceLock) { |
| | |
| | | completeIfNecessary(SUCCESS); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | public void handleException(LdapException exception) { |
| | | synchronized (sequenceLock) { |
| | | completeIfNecessary(asResourceException(error)); |
| | | completeIfNecessary(asResourceException(exception)); |
| | | } |
| | | } |
| | | }); |
| | |
| | | final SearchRequest request = |
| | | nameStrategy.createSearchRequest(c, getBaseDN(c), resourceId).addAttribute(attributes); |
| | | |
| | | c.getConnection().searchSingleEntryAsync(request).onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | adaptEntry(c, entry, h); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | } |
| | | }); |
| | | |
| | | c.getConnection().searchSingleEntryAsync(request).thenOnResult( |
| | | new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | adaptEntry(c, entry, h); |
| | | } |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleException(final LdapException exception) { |
| | | h.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | }; |
| | | }); |
| | | } |
| | |
| | | .addAttribute(attributes); |
| | | |
| | | c.getConnection().searchSingleEntryAsync(searchRequest) |
| | | .onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | .thenOnResult(new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | try { |
| | |
| | | } else { |
| | | modifyRequest.getModifications().addAll(result); |
| | | c.getConnection().applyChangeAsync(modifyRequest) |
| | | .onSuccess(postUpdateSuccessHandler(c, h)) |
| | | .onFailure(postUpdateFailureHandler(h)); |
| | | .thenOnResult(postUpdateResultHandler(c, h)) |
| | | .thenOnException(postUpdateExceptionHandler(h)); |
| | | } |
| | | } |
| | | }); |
| | |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | h.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | } |
| | |
| | | updateHandler.handleResult(searchRequest.getName()); |
| | | } else { |
| | | c.getConnection().searchSingleEntryAsync(searchRequest) |
| | | .onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | .thenOnResult(new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | try { |
| | |
| | | updateHandler.handleError(asResourceException(e)); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | updateHandler.handleError(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | updateHandler.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | } |
| | |
| | | } |
| | | |
| | | Promises.when(promises) |
| | | .then(new org.forgerock.util.promise.Function<List<Filter>, Filter, |
| | | ResourceException>() { |
| | | .then(new org.forgerock.util.Function<List<Filter>, Filter, ResourceException>() { |
| | | @Override |
| | | public Filter apply(final List<Filter> value) { |
| | | // Check for unmapped filter components and optimize. |
| | |
| | | return Filter.and(value); |
| | | } |
| | | } |
| | | }).onSuccess(new SuccessHandler<Filter>() { |
| | | }).thenOnResult(new org.forgerock.util.promise.ResultHandler<Filter>() { |
| | | @Override |
| | | public void handleResult(Filter result) { |
| | | p.handleResult(result); |
| | | } |
| | | }).onFailure(new FailureHandler<ResourceException>() { |
| | | }).thenOnException(new ExceptionHandler<ResourceException>() { |
| | | @Override |
| | | public void handleError(ResourceException error) { |
| | | p.handleError(error); |
| | | public void handleException(ResourceException exception) { |
| | | p.handleError(exception); |
| | | } |
| | | }); |
| | | |
| | |
| | | } |
| | | |
| | | Promises.when(promises) |
| | | .then(new org.forgerock.util.promise.Function<List<Filter>, Filter, |
| | | ResourceException>() { |
| | | .then(new org.forgerock.util.Function<List<Filter>, Filter, ResourceException>() { |
| | | @Override |
| | | public Filter apply(final List<Filter> value) { |
| | | // Check for unmapped filter components and optimize. |
| | |
| | | return Filter.or(value); |
| | | } |
| | | } |
| | | }).onSuccess(new SuccessHandler<Filter>() { |
| | | }).thenOnResult(new org.forgerock.util.promise.ResultHandler<Filter>() { |
| | | @Override |
| | | public void handleResult(Filter result) { |
| | | p.handleResult(result); |
| | | } |
| | | }).onFailure(new FailureHandler<ResourceException>() { |
| | | }).thenOnException(new ExceptionHandler<ResourceException>() { |
| | | @Override |
| | | public void handleError(ResourceException error) { |
| | | p.handleError(error); |
| | | public void handleException(ResourceException exception) { |
| | | p.handleError(exception); |
| | | } |
| | | }); |
| | | |
| | |
| | | return etagAttribute != null ? entry.parseAttribute(etagAttribute).asString() : null; |
| | | } |
| | | |
| | | private SuccessHandler<SearchResultEntry> postEmptyPatchSuccessHandler(final Context c, |
| | | final PatchRequest request, final ResultHandler<Resource> h) { |
| | | return new SuccessHandler<SearchResultEntry>() { |
| | | private org.forgerock.util.promise.ResultHandler<SearchResultEntry> postEmptyPatchResultHandler( |
| | | final Context c, final PatchRequest request, final ResultHandler<Resource> h) { |
| | | return new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | try { |
| | |
| | | }; |
| | | } |
| | | |
| | | private FailureHandler<LdapException> postEmptyPatchFailureHandler(final ResultHandler<Resource> h) { |
| | | return new FailureHandler<LdapException>() { |
| | | private ExceptionHandler<LdapException> postEmptyPatchExceptionHandler(final ResultHandler<Resource> h) { |
| | | return new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | h.handleError(asResourceException(exception)); |
| | | } |
| | | }; |
| | | } |
| | | |
| | | private SuccessHandler<Result> postUpdateSuccessHandler(final Context c, final ResultHandler<Resource> handler) { |
| | | private org.forgerock.util.promise.ResultHandler<Result> postUpdateResultHandler( |
| | | final Context c, final ResultHandler<Resource> handler) { |
| | | // The handler which will be invoked for the LDAP add result. |
| | | return new SuccessHandler<Result>() { |
| | | return new org.forgerock.util.promise.ResultHandler<Result>() { |
| | | @Override |
| | | public void handleResult(final Result result) { |
| | | // FIXME: handle USE_SEARCH policy. |
| | |
| | | }; |
| | | } |
| | | |
| | | private FailureHandler<LdapException> postUpdateFailureHandler(final ResultHandler<Resource> handler) { |
| | | private ExceptionHandler<LdapException> postUpdateExceptionHandler(final ResultHandler<Resource> handler) { |
| | | // The handler which will be invoked for the LDAP add result. |
| | | return new FailureHandler<LdapException>() { |
| | | return new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | handler.handleError(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | handler.handleError(asResourceException(exception)); |
| | | } |
| | | }; |
| | | } |