Skip to content

Commit

Permalink
[AD-77] adding full support for objectGUID as key
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-patricelli authored and ilgrosso committed Jun 19, 2024
1 parent 1716806 commit 2e6229c
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 105 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
.idea
*.iml
19 changes: 16 additions & 3 deletions src/main/java/net/tirasa/connid/bundles/ad/crud/ADUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static net.tirasa.connid.bundles.ad.util.ADUtilities.getPrimaryGroupSID;
import static org.identityconnectors.common.CollectionUtil.isEmpty;
import static org.identityconnectors.common.CollectionUtil.newSet;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand All @@ -39,6 +40,7 @@
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import net.tirasa.adsddl.ntsd.SID;
import net.tirasa.adsddl.ntsd.utils.GUID;
import net.tirasa.adsddl.ntsd.utils.Hex;
import net.tirasa.adsddl.ntsd.utils.NumberFacility;
import net.tirasa.connid.bundles.ad.ADConfiguration;
Expand Down Expand Up @@ -166,7 +168,18 @@ public Uid update(final Set<Attribute> attrs) {
modifyMemberships(entryDN, attrsToBeUpdated);
modifyPrimaryGroupID(entryDN, attrsToBeUpdated);

return conn.getSchema().createUid(oclass, entryDN);
if (OBJECTGUID.equals(conn.getSchema().getLdapUidAttribute(oclass))) {
final Attributes profile;
try {
profile = conn.getInitialContext().getAttributes(entryDN, new String[] { OBJECTGUID });
return new Uid(GUID.getGuidAsString((byte[]) profile.get(OBJECTGUID).get()));
} catch (NamingException e) {
LOG.error("Error managing objectGUID after update", e);
throw new ConnectorException("Error managing objectGUID after update", e);
}
} else {
return conn.getSchema().createUid(oclass, entryDN);
}
}

@Override
Expand Down Expand Up @@ -231,8 +244,8 @@ protected Pair<Attributes, GuardedPasswordAttribute> getAttributesToModify(
} else if (attr.is(ADConfiguration.UCCP_FLAG)) {
final List<Object> value = attr.getValue();
if (value != null && !value.isEmpty()) {
javax.naming.directory.Attribute ntSecurityDescriptor
= utils.userCannotChangePassword(obj, (Boolean) value.get(0));
javax.naming.directory.Attribute ntSecurityDescriptor =
utils.userCannotChangePassword(obj, (Boolean) value.get(0));
if (ntSecurityDescriptor != null) {
ldapAttrs.put(ntSecurityDescriptor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected LdapInternalSearch getInternalSearch(final Set<String> attrsToGet) {
final SearchControls controls = LdapInternalSearch.createDefaultSearchControls();
final Set<String> ldapAttrsToGet = utils.getLdapAttributesToGet(attrsToGet, oclass);

controls.setReturningAttributes(ldapAttrsToGet.toArray(new String[ldapAttrsToGet.size()]));
controls.setReturningAttributes(ldapAttrsToGet.toArray(new String[0]));
controls.setSearchScope(searchScope);

final String optionsFilter = LdapConstants.getSearchFilter(options);
Expand Down Expand Up @@ -177,7 +177,7 @@ protected LdapInternalSearch getInternalSearch(final Set<String> attrsToGet) {
}

final String membershipSearchFilter = oclass.equals(ObjectClass.ACCOUNT)
? utils.getMembershipSearchFilter(((ADConfiguration) conn.getConfiguration()))
? ADUtilities.getMembershipSearchFilter(((ADConfiguration) conn.getConfiguration()))
: null;

if (LOG.isOk()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class USNSyncStrategy extends ADSyncStrategy {

private static final Log LOG = Log.getLog(USNSyncStrategy.class);

private static String USN = "uSNChanged";
private static final String USN = "uSNChanged";

private String deleteTokenValue;

Expand Down Expand Up @@ -132,9 +132,13 @@ public void sync(
// get lastest sync token before start pulling objects
latestSyncToken = token;

if ((oclass.is(ObjectClass.ACCOUNT_NAME) && ((ADConfiguration) conn.getConfiguration()).isRetrieveDeletedUser())
|| (oclass.is(ObjectClass.GROUP_NAME) && ((ADConfiguration) conn.getConfiguration()).isRetrieveDeletedGroup())
|| (oclass.is(LdapSchema.ANY_OBJECT_NAME) && ((ADConfiguration) conn.getConfiguration()).isRetrieveDeletedAnyObject())) {
if ((oclass.is(ObjectClass.ACCOUNT_NAME)
&& ((ADConfiguration) conn.getConfiguration()).isRetrieveDeletedUser())
|| (oclass.is(ObjectClass.GROUP_NAME)
&& ((ADConfiguration) conn.getConfiguration()).isRetrieveDeletedGroup())
|| (oclass.is(LdapSchema.ANY_OBJECT_NAME)
&& ((ADConfiguration) conn.getConfiguration()).isRetrieveDeletedAnyObject())) {

syncDeletedObjects(token, handler, options, oclass);
}

Expand Down Expand Up @@ -299,7 +303,7 @@ private void syncCurrentObjects(
// -----------------------------------
String filter = oclass.is(ObjectClass.ACCOUNT_NAME)
? // get user filter
createDirSyncUFilter((ADConfiguration) conn.getConfiguration(), utils)
createDirSyncUFilter((ADConfiguration) conn.getConfiguration())
: oclass.is(ObjectClass.GROUP_NAME) // get group filter
? createDirSyncGFilter()
: DirSyncUtils.createDirSyncAOFilter((ADConfiguration) conn.getConfiguration(), false);
Expand Down Expand Up @@ -502,10 +506,10 @@ protected void handleSyncGDelta(
}
}

private static String createDirSyncUFilter(final ADConfiguration conf, final ADUtilities utils) {
private static String createDirSyncUFilter(final ADConfiguration conf) {
StringBuilder filter = new StringBuilder();

filter.append("(&(objectClass=user)").append(utils.getMembershipSearchFilter(conf)).
filter.append("(&(objectClass=user)").append(ADUtilities.getMembershipSearchFilter(conf)).
append("(! (isDeleted=TRUE))").append(")");

return filter.toString();
Expand Down
Loading

0 comments on commit 2e6229c

Please sign in to comment.