Skip to content

Commit

Permalink
[AD-77] utilities use internal search to look for object to update (#28)
Browse files Browse the repository at this point in the history
andrea-patricelli authored Jun 20, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
jsnel Joris Snellenburg
1 parent 2e6229c commit 1a127c6
Showing 2 changed files with 32 additions and 32 deletions.
15 changes: 15 additions & 0 deletions src/main/java/net/tirasa/connid/bundles/ad/search/ADSearch.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import javax.naming.InvalidNameException;
import javax.naming.NamingException;
@@ -41,6 +42,7 @@
import net.tirasa.connid.bundles.ldap.search.LdapSearchResultsHandler;
import net.tirasa.connid.bundles.ldap.search.LdapSearchStrategy;
import org.identityconnectors.common.logging.Log;
import org.identityconnectors.framework.common.objects.ConnectorObject;
import org.identityconnectors.framework.common.objects.ObjectClass;
import org.identityconnectors.framework.common.objects.OperationOptions;
import org.identityconnectors.framework.common.objects.ResultsHandler;
@@ -81,6 +83,19 @@ public ADSearch(
: ((ADConfiguration) conn.getConfiguration()).getBaseContexts());
}

public final void execute(final BiFunction<SearchResult, Set<String>, ConnectorObject> connObjSupplier) {
final String[] attrsToGetOption = options.getAttributesToGet();
final Set<String> attrsToGet = utils.getAttributesToGet(attrsToGetOption, oclass);

getInternalSearch(attrsToGet).execute(new LdapSearchResultsHandler() {

@Override
public boolean handle(final String baseDN, final SearchResult result) {
return handler.handle(connObjSupplier.apply(result, attrsToGet));
}
});
}

@Override
public final void execute() {
final String[] attrsToGetOption = options.getAttributesToGet();
49 changes: 17 additions & 32 deletions src/main/java/net/tirasa/connid/bundles/ad/util/ADUtilities.java
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@
import net.tirasa.connid.bundles.ad.ADConfiguration;
import net.tirasa.connid.bundles.ad.ADConnection;
import net.tirasa.connid.bundles.ad.ADConnector;
import net.tirasa.connid.bundles.ad.search.ADSearch;
import net.tirasa.connid.bundles.ldap.LdapConnection;
import net.tirasa.connid.bundles.ldap.commons.GroupHelper;
import net.tirasa.connid.bundles.ldap.commons.LdapConstants;
@@ -64,7 +65,6 @@
import net.tirasa.connid.bundles.ldap.schema.LdapSchema;
import net.tirasa.connid.bundles.ldap.search.LdapFilter;
import net.tirasa.connid.bundles.ldap.search.LdapInternalSearch;
import net.tirasa.connid.bundles.ldap.search.LdapSearch;
import net.tirasa.connid.bundles.ldap.search.LdapSearches;
import org.identityconnectors.common.CollectionUtil;
import org.identityconnectors.common.StringUtil;
@@ -528,41 +528,30 @@ public LdapEntry getEntryToBeUpdated(final String entryDN) {
return obj;
}

private String getEntryToBeUpdatedQuery(final Uid uid, final ObjectClass oclass) {
return connection.getSchema().getLdapUidAttribute(oclass) + "="
+ (OBJECTGUID.equals(connection.getSchema().getLdapUidAttribute(oclass))
? getEscapedGUID(uid.getUidValue())
: uid.getUidValue());
}

public ConnectorObject getEntryToBeUpdated(final Uid uid, final ObjectClass oclass) {
OperationOptionsBuilder builder = new OperationOptionsBuilder();
builder.setAttributesToGet(Arrays.asList(UACCONTROL_ATTR, SDDL_ATTR, OBJECTSID, PRIMARYGROUPID));

LdapFilter filter = LdapFilter.forNativeFilter(getEntryToBeUpdatedQuery(uid, oclass));
final String filter = connection.getSchema().getLdapUidAttribute(oclass) + "=" + uid.getUidValue();

LOG.ok("Searching for object of class {0} with filter {1}", oclass.getObjectClassValue(), filter);

final ConnectorObject obj = new LdapSearch(connection, oclass, filter, null, builder.build()) {

@Override
protected ConnectorObject createConnectorObject(final String baseDN,
final SearchResult result,
final Set<String> attrsToGet,
final boolean emptyAttrWhenNotFound) {

try {
// cannot use default createConnectorObject, since payload may contain Active Directory binary
// and/or special attributes
return createMinimalConnectorObject(result.getNameInNamespace(),
result.getAttributes(),
attrsToGet,
oclass);
} catch (NamingException e) {
throw new ConnectorException("Error while creating connector object", e);
}
final ConnectorObject[] results = new ConnectorObject[] { null };
new ADSearch(connection, oclass, LdapFilter.forNativeFilter(filter), connectorObject -> {
results[0] = connectorObject;
return false;
}, builder.build()).execute((result, attrsToGet) -> {
try {
return createMinimalConnectorObject(result.getNameInNamespace(),
result.getAttributes(),
attrsToGet,
oclass);
} catch (NamingException e) {
throw new ConnectorException("Error while creating connector object", e);
}
}.getSingleResult();
});

ConnectorObject obj = results[0];

if (obj == null) {
throw new ConnectorException("Entry not found");
@@ -659,10 +648,6 @@ public Set<String> getGroups(final String entryDN, final String... baseContexts)
return ldapGroups;
}

private static String getEscapedGUID(final String unescapedGUID) {
return Hex.getEscaped(GUID.getGuidAsByteArray(unescapedGUID));
}

private Attribute manageUACAttribute(final Attributes profile,
final ObjectClass oclass,
final LdapEntry entry,

0 comments on commit 1a127c6

Please sign in to comment.