diff --git a/src/main/java/net/tirasa/connid/bundles/ldap/commons/LdapUtil.java b/src/main/java/net/tirasa/connid/bundles/ldap/commons/LdapUtil.java index ead6a25..1aa4ab6 100644 --- a/src/main/java/net/tirasa/connid/bundles/ldap/commons/LdapUtil.java +++ b/src/main/java/net/tirasa/connid/bundles/ldap/commons/LdapUtil.java @@ -40,7 +40,6 @@ import org.identityconnectors.framework.common.exceptions.ConnectorException; import org.identityconnectors.framework.common.objects.AttributeDelta; import org.identityconnectors.framework.common.objects.AttributeDeltaUtil; -import org.identityconnectors.framework.common.objects.ConnectorObject; import org.identityconnectors.framework.common.objects.Name; public class LdapUtil { @@ -51,8 +50,7 @@ private LdapUtil() { } /** - * Returns true if the names of the given LDAP attributes are equal. Deals - * with null values as a convenience. + * @return @code true} if the names of the given LDAP attributes are equal. Deals with null values as a convenience. */ public static boolean attrNameEquals(String name1, String name2) { if (name1 == null) { @@ -62,8 +60,7 @@ public static boolean attrNameEquals(String name1, String name2) { } /** - * Returns {@code true} if the attribute has the binary option, - * e.g., {@code userCertificate;binary}. + * @return {@code true} if the attribute has the binary option, e.g., {@code userCertificate;binary}. */ public static boolean hasBinaryOption(String ldapAttrName) { return ldapAttrName.toLowerCase(Locale.US).endsWith(LDAP_BINARY_OPTION); @@ -89,22 +86,8 @@ public static String removeBinaryOption(String ldapAttrName) { return ldapAttrName; } - public static String getStringAttrValue(ConnectorObject object, String ldapAttrName) { - org.identityconnectors.framework.common.objects.Attribute attr = object.getAttributeByName(ldapAttrName); - if (attr != null) { - try { - return (String) attr.getValue().get(0); - } catch (IndexOutOfBoundsException e) { - return null; - } catch (Exception e) { - throw new ConnectorException(e); - } - } - return null; - } - /** - * Return the value of the {@code ldapAttrName} parameter cast to a String. + * @return the value of the {@code ldapAttrName} parameter cast to a String. */ public static String getStringAttrValue(Attributes ldapAttrs, String ldapAttrName) { Attribute attr = ldapAttrs.get(ldapAttrName); @@ -119,11 +102,11 @@ public static String getStringAttrValue(Attributes ldapAttrs, String ldapAttrNam } /** - * Return the case insensitive set of values of the {@code + * @return the case insensitive set of values of the {@code * ldapAttrName} parameter cast to a String. */ public static Set getStringAttrValues(Attributes ldapAttrs, String ldapAttrName) { - Set result = new HashSet(); + Set result = new HashSet<>(); addStringAttrValues(ldapAttrs, ldapAttrName, result); return result; } @@ -145,7 +128,8 @@ public static void addStringAttrValues(Attributes ldapAttrs, String ldapAttrName /** * Escapes the given attribute value to the given {@code StringBuilder}. - * Returns {@code true} iff anything was written to the builder. + * + * @returns {@code true} iff anything was written to the builder. */ public static boolean escapeAttrValue(Object value, StringBuilder toBuilder) { if (value == null) { @@ -446,38 +430,47 @@ public ListItr(ListIterator iter) { this.iter = iter; } + @Override public void add(E o) { iter.add(o); } + @Override public boolean hasNext() { return iter.hasNext(); } + @Override public boolean hasPrevious() { return iter.hasPrevious(); } + @Override public E next() { return cast(iter.next()); } + @Override public int nextIndex() { return iter.nextIndex(); } + @Override public E previous() { return cast(iter.previous()); } + @Override public int previousIndex() { return iter.previousIndex(); } + @Override public void remove() { iter.remove(); } + @Override public void set(E o) { iter.set(o); } diff --git a/src/main/java/net/tirasa/connid/bundles/ldap/search/LdapSearch.java b/src/main/java/net/tirasa/connid/bundles/ldap/search/LdapSearch.java index 01d24d5..d7dfcb1 100644 --- a/src/main/java/net/tirasa/connid/bundles/ldap/search/LdapSearch.java +++ b/src/main/java/net/tirasa/connid/bundles/ldap/search/LdapSearch.java @@ -210,7 +210,6 @@ protected LdapInternalSearch getInternalSearch(final Set attrsToGet) { controls.setSearchScope(searchScope); String optionsFilter = LdapConstants.getSearchFilter(options); - String finalFilter = ""; boolean ignoreBuiltInFilters; if (options.getOptions().containsKey(OP_IGNORE_BUILT_IN_FILTERS)) { @@ -219,6 +218,7 @@ protected LdapInternalSearch getInternalSearch(final Set attrsToGet) { ignoreBuiltInFilters = false; } + String finalFilter; if (ignoreBuiltInFilters) { finalFilter = optionsFilter; } else { @@ -231,12 +231,10 @@ protected LdapInternalSearch getInternalSearch(final Set attrsToGet) { searchFilter = conn.getConfiguration().getAnyObjectSearchFilter(); } String nativeFilter = filter == null ? null : filter.getNativeFilter(); - + finalFilter = getSearchFilter(optionsFilter, nativeFilter, searchFilter); } - return new LdapInternalSearch(conn, - finalFilter, - dns, strategy, controls); + return new LdapInternalSearch(conn, finalFilter, dns, strategy, controls); } protected Set getLdapAttributesToGet(final Set attrsToGet) { diff --git a/src/main/java/net/tirasa/connid/bundles/ldap/search/LdapSearchStrategy.java b/src/main/java/net/tirasa/connid/bundles/ldap/search/LdapSearchStrategy.java index e0eb7d5..62570e3 100644 --- a/src/main/java/net/tirasa/connid/bundles/ldap/search/LdapSearchStrategy.java +++ b/src/main/java/net/tirasa/connid/bundles/ldap/search/LdapSearchStrategy.java @@ -1,18 +1,18 @@ -/* +/* * ==================== * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * + * * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved. - * + * * The contents of this file are subject to the terms of the Common Development * and Distribution License("CDDL") (the "License"). You may not use this file * except in compliance with the License. - * + * * You can obtain a copy of the License at * http://opensource.org/licenses/cddl1.php * See the License for the specific language governing permissions and limitations * under the License. - * + * * When distributing the Covered Code, include this CDDL Header Notice in each file * and include the License file at http://opensource.org/licenses/cddl1.php. * If applicable, add the following below this CDDL Header, with the fields diff --git a/src/main/java/net/tirasa/connid/bundles/ldap/sync/GenericChangeLogSyncStrategy.java b/src/main/java/net/tirasa/connid/bundles/ldap/sync/GenericChangeLogSyncStrategy.java index 70f2fd5..d9d659c 100644 --- a/src/main/java/net/tirasa/connid/bundles/ldap/sync/GenericChangeLogSyncStrategy.java +++ b/src/main/java/net/tirasa/connid/bundles/ldap/sync/GenericChangeLogSyncStrategy.java @@ -55,6 +55,8 @@ import org.identityconnectors.framework.common.exceptions.ConnectorException; import org.identityconnectors.framework.common.objects.Attribute; import org.identityconnectors.framework.common.objects.AttributeBuilder; +import org.identityconnectors.framework.common.objects.AttributeUtil; +import org.identityconnectors.framework.common.objects.AttributesAccessor; import org.identityconnectors.framework.common.objects.ConnectorObject; import org.identityconnectors.framework.common.objects.ConnectorObjectBuilder; import org.identityconnectors.framework.common.objects.ObjectClass; @@ -109,7 +111,7 @@ public class GenericChangeLogSyncStrategy implements LdapSyncStrategy { public GenericChangeLogSyncStrategy(LdapConnection conn) { this.conn = conn; } - + protected SyncToken getLatestSyncTokenPaged(ObjectClass oclass, OperationOptionsBuilder builder) { LOG.ok("Getting latest sync token with pages of size {0}", conn.getConfiguration().getChangeLogBlockSize()); @@ -125,6 +127,7 @@ protected SyncToken getLatestSyncTokenPaged(ObjectClass oclass, OperationOptions cookies[0] = null; SearchResultsHandler handler = new SearchResultsHandler() { + @Override public boolean handle(final ConnectorObject object) { int changeNumber = convertToInt( @@ -156,17 +159,21 @@ public void handleResult(final SearchResult result) { return new SyncToken(maxChangeNumber[0]); } - + protected SyncToken getLatestSyncTokenDefault(ObjectClass oclass, OperationOptionsBuilder builder) { final int[] maxChangeNumber = { 0 }; LOG.ok("Getting latest sync token with a regular search"); ResultsHandler handler = new ResultsHandler() { + @Override public boolean handle(final ConnectorObject object) { - int changeNumber = convertToInt((String) object.getAttributeByName(getChangeNumberAttribute()).getValue().get(0), -1); - if (changeNumber > maxChangeNumber[0]) { - maxChangeNumber[0] = changeNumber; + Attribute changeNumberAttr = object.getAttributeByName(getChangeNumberAttribute()); + if (changeNumberAttr != null) { + int changeNumber = convertToInt(AttributeUtil.getStringValue(changeNumberAttr), -1); + if (changeNumber > maxChangeNumber[0]) { + maxChangeNumber[0] = changeNumber; + } } return true; @@ -179,7 +186,7 @@ public boolean handle(final ConnectorObject object) { handler, builder.build(), conn.getConfiguration().getChangeLogContext()); - + search.execute(); return new SyncToken(maxChangeNumber[0]); @@ -196,15 +203,15 @@ public SyncToken getLatestSyncToken(ObjectClass oclass) { builder.setOption(LdapSearch.OP_IGNORE_BUILT_IN_FILTERS, true); builder.setOption(LdapConstants.SEARCH_FILTER_NAME, "(objectClass=changelogEntry)"); - Class searchStrategyClass = LdapSearchStrategy.getSearchStrategy(conn, builder.build()); + Class searchStrategyClass = + LdapSearchStrategy.getSearchStrategy(conn, builder.build()); switch (searchStrategyClass.getSimpleName()) { case "PagedSearchStrategy": if (conn.getConfiguration().getChangeLogPagingSupport()) { return getLatestSyncTokenPaged(oclass, builder); - } - else { - return getLatestSyncTokenDefault(oclass, builder); + } else { + return getLatestSyncTokenDefault(oclass, builder); } default: return getLatestSyncTokenDefault(oclass, builder); @@ -217,6 +224,7 @@ public void sync( final SyncResultsHandler handler, final OperationOptions options, final ObjectClass oclass) { + final String changeNumberAttr = getChangeNumberAttribute(); OperationOptionsBuilder builder = new OperationOptionsBuilder(); @@ -237,15 +245,18 @@ public void sync( final boolean[] results = new boolean[1]; ResultsHandler resultsHandler = new ResultsHandler() { + @Override public boolean handle(final ConnectorObject object) { results[0] = true; - - int changeNumber = convertToInt((String) object.getAttributeByName(changeNumberAttr).getValue().get(0), - -1); - if (changeNumber > currentChangeNumber[0]) { - currentChangeNumber[0] = changeNumber; + Attribute changeNumberAttr = object.getAttributeByName(getChangeNumberAttribute()); + int changeNumber = -1; + if (changeNumberAttr != null) { + changeNumber = convertToInt(AttributeUtil.getStringValue(changeNumberAttr), -1); + if (changeNumber > currentChangeNumber[0]) { + currentChangeNumber[0] = changeNumber; + } } SyncDelta delta; @@ -265,12 +276,14 @@ public boolean handle(final ConnectorObject object) { do { results[0] = false; - builder.setOption(LdapConstants.SEARCH_FILTER_NAME, getChangeLogSearchFilter(changeNumberAttr, currentChangeNumber[0])); + builder.setOption( + LdapConstants.SEARCH_FILTER_NAME, + getChangeLogSearchFilter(changeNumberAttr, currentChangeNumber[0])); - LdapSearch search = new LdapSearch(conn, - oclass, - null, - resultsHandler, + LdapSearch search = new LdapSearch(conn, + oclass, + null, + resultsHandler, builder.build(), conn.getConfiguration().getChangeLogContext()); @@ -293,8 +306,9 @@ private SyncDelta createSyncDelta( LOG.ok("Attempting to create sync delta for log entry {0}", changeNumber); - final String targetDN = LdapUtil.getStringAttrValue(inputObject, "targetDN"); + final AttributesAccessor inputAttrs = new AttributesAccessor(inputObject.getAttributes()); + final String targetDN = inputAttrs.findString("targetDN"); if (targetDN == null) { LOG.error("Skipping log entry because it does not have a targetDN attribute"); return null; @@ -308,7 +322,7 @@ private SyncDelta createSyncDelta( return null; } - final String changeType = LdapUtil.getStringAttrValue(inputObject, "changeType"); + final String changeType = inputAttrs.findString("changeType"); SyncDeltaType deltaType = getSyncDeltaType(changeType); @@ -341,19 +355,17 @@ private SyncDelta createSyncDelta( return syncDeltaBuilder.build(); } - final String changes = LdapUtil.getStringAttrValue(inputObject, "changes"); + final String changes = inputAttrs.findString("changes"); final Map> attrChanges = getAttributeChanges(changeType, changes); if (filterOutByModifiersNames(attrChanges)) { - LOG.ok("Skipping entry because modifiersName is in the list of " - + "modifiersName's to filter out"); + LOG.ok("Skipping entry because modifiersName is in the list of modifiersName's to filter out"); return null; } if (filterOutByAttributes(attrChanges)) { - LOG.ok("Skipping entry because no changed attributes in the list " - + "of attributes to synchronize"); + LOG.ok("Skipping entry because no changed attributes in the list of attributes to synchronize"); return null; } @@ -362,15 +374,13 @@ private SyncDelta createSyncDelta( String newTargetDN = targetDN; if ("modrdn".equalsIgnoreCase(changeType)) { - final String newRdn = LdapUtil.getStringAttrValue(inputObject, "newRdn"); - + final String newRdn = inputAttrs.findString("newRdn"); if (StringUtil.isBlank(newRdn)) { LOG.error("Skipping log entry because it does not have a newRdn attribute"); return null; } - final String newSuperior = LdapUtil.getStringAttrValue(inputObject, "newSuperior"); - + final String newSuperior = inputAttrs.findString("newSuperior"); newTargetDN = getNewTargetDN(targetName, newSuperior, newRdn); } @@ -526,8 +536,7 @@ private boolean filterOutByAttributes( return !containsAny(filter, changedAttrs); } - private boolean filterOutByObjectClasses( - final List objectClasses) { + private boolean filterOutByObjectClasses(final List objectClasses) { Set filter = getObjectClassesToSynchronize(); if (filter.isEmpty()) { LOG.ok("Filtering by object class disabled"); @@ -537,22 +546,15 @@ private boolean filterOutByObjectClasses( } private SyncDeltaType getSyncDeltaType(final String changeType) { - if ("delete".equalsIgnoreCase(changeType)) { - return SyncDeltaType.DELETE; - } - return SyncDeltaType.CREATE_OR_UPDATE; + return "delete".equalsIgnoreCase(changeType) ? SyncDeltaType.DELETE : SyncDeltaType.CREATE_OR_UPDATE; } - private String getModifiedEntrySearchFilter(ObjectClass oclass) { - if (oclass.equals(ObjectClass.ACCOUNT)) { - return conn.getConfiguration().getAccountSynchronizationFilter(); - } - return null; + private String getModifiedEntrySearchFilter(final ObjectClass oclass) { + return oclass.equals(ObjectClass.ACCOUNT) ? conn.getConfiguration().getAccountSynchronizationFilter() : null; } private int getStartChangeNumber(final SyncToken lastToken) { - return lastToken != null ? (Integer) lastToken. - getValue() + 1 : 0; + return lastToken != null ? (Integer) lastToken.getValue() + 1 : 0; } private Map> getAttributeChanges(final String changeType, final String ldif) { @@ -633,8 +635,7 @@ private Object decodeAttributeValue(final NameValue nameValue) { } } - private String getChangeLogSearchFilter( - final String changeNumberAttr, final int startChangeNumber) { + private String getChangeLogSearchFilter(final String changeNumberAttr, final int startChangeNumber) { int blockSize = conn.getConfiguration().getChangeLogBlockSize(); boolean filterWithOrInsteadOfAnd = conn.getConfiguration(). isFilterWithOrInsteadOfAnd(); @@ -731,8 +732,7 @@ private PasswordDecryptor getPasswordDecryptor() { return passwordDecryptor; } - private boolean containsAny( - final Set haystack, final Collection needles) { + private boolean containsAny(final Set haystack, final Collection needles) { for (String needle : needles) { if (haystack.contains(needle)) { return true; @@ -751,7 +751,7 @@ private Uid createUid(final String uidAttr, final String targetDN) throws Invali return matchingRnd == null ? null : new Uid(matchingRnd.getValue().toString()); } - public static int convertToInt(String number, final int def) { + private static int convertToInt(String number, final int def) { int result = def; if (number != null && number.length() > 0) { int decimal = number.indexOf('.'); diff --git a/src/main/java/net/tirasa/connid/bundles/ldap/sync/sunds/SunDSChangeLogSyncStrategy.java b/src/main/java/net/tirasa/connid/bundles/ldap/sync/sunds/SunDSChangeLogSyncStrategy.java index 718ae42..847e3e6 100644 --- a/src/main/java/net/tirasa/connid/bundles/ldap/sync/sunds/SunDSChangeLogSyncStrategy.java +++ b/src/main/java/net/tirasa/connid/bundles/ldap/sync/sunds/SunDSChangeLogSyncStrategy.java @@ -23,15 +23,6 @@ */ package net.tirasa.connid.bundles.ldap.sync.sunds; -import static org.identityconnectors.common.CollectionUtil.isEmpty; -import static org.identityconnectors.common.CollectionUtil.newCaseInsensitiveMap; -import static org.identityconnectors.common.CollectionUtil.newCaseInsensitiveSet; -import static org.identityconnectors.common.StringUtil.isBlank; -import static net.tirasa.connid.bundles.ldap.commons.LdapUtil.getStringAttrValue; -import static net.tirasa.connid.bundles.ldap.commons.LdapUtil.isUnderContexts; -import static net.tirasa.connid.bundles.ldap.commons.LdapUtil.nullAsEmpty; -import static net.tirasa.connid.bundles.ldap.commons.LdapUtil.quietCreateLdapName; - import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; @@ -60,7 +51,6 @@ import net.tirasa.connid.bundles.ldap.search.LdapSearch; import net.tirasa.connid.bundles.ldap.search.LdapSearches; import net.tirasa.connid.bundles.ldap.sync.LdapSyncStrategy; - import org.identityconnectors.common.CollectionUtil; import org.identityconnectors.common.StringUtil; import org.identityconnectors.common.logging.Log; @@ -68,6 +58,8 @@ import org.identityconnectors.framework.common.exceptions.ConnectorException; import org.identityconnectors.framework.common.objects.Attribute; import org.identityconnectors.framework.common.objects.AttributeBuilder; +import org.identityconnectors.framework.common.objects.AttributeUtil; +import org.identityconnectors.framework.common.objects.AttributesAccessor; import org.identityconnectors.framework.common.objects.ConnectorObject; import org.identityconnectors.framework.common.objects.ConnectorObjectBuilder; import org.identityconnectors.framework.common.objects.ObjectClass; @@ -109,12 +101,12 @@ public class SunDSChangeLogSyncStrategy implements LdapSyncStrategy { private PasswordDecryptor passwordDecryptor; static { - LDIF_MODIFY_OPS = newCaseInsensitiveSet(); + LDIF_MODIFY_OPS = CollectionUtil.newCaseInsensitiveSet(); LDIF_MODIFY_OPS.add("add"); LDIF_MODIFY_OPS.add("delete"); LDIF_MODIFY_OPS.add("replace"); - LDAP_DN_ATTRIBUTES = newCaseInsensitiveSet(); + LDAP_DN_ATTRIBUTES = CollectionUtil.newCaseInsensitiveSet(); LDAP_DN_ATTRIBUTES.add("uid"); LDAP_DN_ATTRIBUTES.add("cn"); } @@ -134,6 +126,7 @@ public void sync( final SyncResultsHandler handler, final OperationOptions options, final ObjectClass oclass) { + final String changeNumberAttr = getChangeNumberAttribute(); OperationOptionsBuilder builder = new OperationOptionsBuilder(); @@ -155,15 +148,18 @@ public void sync( final boolean[] results = new boolean[1]; ResultsHandler resultsHandler = new ResultsHandler() { + @Override public boolean handle(final ConnectorObject object) { results[0] = true; - - int changeNumber = convertToInt((String) object.getAttributeByName(changeNumberAttr).getValue().get(0), - -1); - if (changeNumber > currentChangeNumber[0]) { - currentChangeNumber[0] = changeNumber; + Attribute changeNumberAttr = object.getAttributeByName(getChangeNumberAttribute()); + int changeNumber = -1; + if (changeNumberAttr != null) { + changeNumber = convertToInt(AttributeUtil.getStringValue(changeNumberAttr), -1); + if (changeNumber > currentChangeNumber[0]) { + currentChangeNumber[0] = changeNumber; + } } SyncDelta delta; @@ -183,11 +179,13 @@ public boolean handle(final ConnectorObject object) { do { results[0] = false; - builder.setOption(LdapConstants.SEARCH_FILTER_NAME, getChangeLogSearchFilter(changeNumberAttr, currentChangeNumber[0])); - LdapSearch search = new LdapSearch(conn, - oclass, - null, - resultsHandler, + builder.setOption( + LdapConstants.SEARCH_FILTER_NAME, + getChangeLogSearchFilter(changeNumberAttr, currentChangeNumber[0])); + LdapSearch search = new LdapSearch(conn, + oclass, + null, + resultsHandler, builder.build(), conn.getConfiguration().getChangeLogContext()); @@ -206,12 +204,13 @@ private SyncDelta createSyncDelta( final ConnectorObject inputObject, final int changeNumber, final String[] attrsToGetOption, - ObjectClass oclass) throws InvalidNameException { + final ObjectClass oclass) throws InvalidNameException { LOG.ok("Attempting to create sync delta for log entry {0}", changeNumber); - final String targetDN = LdapUtil.getStringAttrValue(inputObject, "targetDN"); + final AttributesAccessor inputAttrs = new AttributesAccessor(inputObject.getAttributes()); + final String targetDN = inputAttrs.findString("targetDN"); if (targetDN == null) { LOG.error("Skipping log entry because it does not have a targetDN attribute"); return null; @@ -225,7 +224,7 @@ private SyncDelta createSyncDelta( return null; } - final String changeType = LdapUtil.getStringAttrValue(inputObject, "changeType"); + final String changeType = inputAttrs.findString("changeType"); SyncDeltaType deltaType = getSyncDeltaType(changeType); @@ -234,8 +233,7 @@ private SyncDelta createSyncDelta( syncDeltaBuilder.setDeltaType(deltaType); if (deltaType.equals(SyncDeltaType.DELETE)) { - LOG.ok("Creating sync delta for deleted entry {0}", - LdapUtil.getStringAttrValue(inputObject, "targetEntryUUID")); + LOG.ok("Creating sync delta for deleted entry {0}", inputAttrs.findString("targetEntryUUID")); String uidAttr = conn.getSchema().getLdapUidAttribute(oclass); @@ -243,7 +241,7 @@ private SyncDelta createSyncDelta( if (LDAP_DN_ATTRIBUTES.contains(uidAttr)) { deletedUid = createUid(uidAttr, targetDN); } else if ("entryUUID".equalsIgnoreCase(uidAttr)) { - deletedUid = new Uid(LdapUtil.getStringAttrValue(inputObject, "targetEntryUUID")); + deletedUid = new Uid(inputAttrs.findString("targetEntryUUID")); } else { // ever fallback to dn without throwing any exception more reliable deletedUid = new Uid(targetDN); @@ -261,7 +259,7 @@ private SyncDelta createSyncDelta( return syncDeltaBuilder.build(); } - final String changes = LdapUtil.getStringAttrValue(inputObject, "changes"); + final String changes = inputAttrs.findString("changes"); final Map> attrChanges = getAttributeChanges(changeType, changes); @@ -282,15 +280,13 @@ private SyncDelta createSyncDelta( String newTargetDN = targetDN; if ("modrdn".equalsIgnoreCase(changeType)) { - final String newRdn = LdapUtil.getStringAttrValue(inputObject, "newRdn"); - + final String newRdn = inputAttrs.findString("newRdn"); if (StringUtil.isBlank(newRdn)) { LOG.error("Skipping log entry because it does not have a newRdn attribute"); return null; } - final String newSuperior = LdapUtil.getStringAttrValue(inputObject, "newSuperior"); - + final String newSuperior = inputAttrs.findString("newSuperior"); newTargetDN = getNewTargetDN(targetName, newSuperior, newRdn); } @@ -326,8 +322,7 @@ private SyncDelta createSyncDelta( CollectionUtil.nullAsEmpty(oclassAttr.getValue()), String.class); if (filterOutByObjectClasses(objectClasses)) { - LOG.ok("Skipping entry because no object class in the list of " - + "object classes to synchronize"); + LOG.ok("Skipping entry because no object class in the list of object classes to synchronize"); return null; } @@ -400,7 +395,7 @@ private String getNewTargetDN( newTargetName.remove(targetName.size() - 1); } } else { - newTargetName = quietCreateLdapName(newSuperior); + newTargetName = LdapUtil.quietCreateLdapName(newSuperior); } newTargetName.add(newRdn); return newTargetName.toString(); @@ -410,34 +405,29 @@ private String getNewTargetDN( } private boolean filterOutByBaseContexts(final LdapName targetName) { - List baseContexts = conn.getConfiguration(). - getBaseContextsToSynchronizeAsLdapNames(); + List baseContexts = conn.getConfiguration().getBaseContextsToSynchronizeAsLdapNames(); if (baseContexts.isEmpty()) { baseContexts = conn.getConfiguration().getBaseContextsAsLdapNames(); } - return !isUnderContexts(targetName, baseContexts); + return !LdapUtil.isUnderContexts(targetName, baseContexts); } - private boolean filterOutByModifiersNames( - final Map> changes) { - Set filter = conn.getConfiguration(). - getModifiersNamesToFilterOutAsLdapNames(); + private boolean filterOutByModifiersNames(final Map> changes) { + Set filter = conn.getConfiguration().getModifiersNamesToFilterOutAsLdapNames(); if (filter.isEmpty()) { LOG.ok("Filtering by modifiersName disabled"); return false; } List modifiersNameValues = changes.get("modifiersName"); - if (isEmpty(modifiersNameValues)) { + if (CollectionUtil.isEmpty(modifiersNameValues)) { LOG.ok("Not filtering by modifiersName because not set for this entry"); return false; } - LdapName modifiersName = quietCreateLdapName(modifiersNameValues.get(0). - toString()); + LdapName modifiersName = LdapUtil.quietCreateLdapName(modifiersNameValues.get(0).toString()); return filter.contains(modifiersName); } - private boolean filterOutByAttributes( - final Map> attrChanges) { + private boolean filterOutByAttributes(final Map> attrChanges) { Set filter = getAttributesToSynchronize(); if (filter.isEmpty()) { LOG.ok("Filtering by attributes disabled"); @@ -447,8 +437,7 @@ private boolean filterOutByAttributes( return !containsAny(filter, changedAttrs); } - private boolean filterOutByObjectClasses( - final List objectClasses) { + private boolean filterOutByObjectClasses(final List objectClasses) { Set filter = getObjectClassesToSynchronize(); if (filter.isEmpty()) { LOG.ok("Filtering by object class disabled"); @@ -472,17 +461,15 @@ private String getModifiedEntrySearchFilter(ObjectClass oclass) { } private int getStartChangeNumber(final SyncToken lastToken) { - Integer lastTokenValue = lastToken != null ? (Integer) lastToken. - getValue() : null; + Integer lastTokenValue = lastToken != null ? (Integer) lastToken.getValue() : null; if (lastTokenValue == null) { return getChangeLogAttributes().getFirstChangeNumber(); } return lastTokenValue + 1; // Since the token value is the last value. } - private Map> getAttributeChanges( - final String changeType, final String ldif) { - final Map> result = newCaseInsensitiveMap(); + private Map> getAttributeChanges(final String changeType, final String ldif) { + final Map> result = CollectionUtil.newCaseInsensitiveMap(); if ("modify".equalsIgnoreCase(changeType)) { LdifParser parser = new LdifParser(ldif); @@ -559,8 +546,7 @@ private Object decodeAttributeValue(final NameValue nameValue) { } } - private String getChangeLogSearchFilter( - final String changeNumberAttr, final int startChangeNumber) { + private String getChangeLogSearchFilter(final String changeNumberAttr, final int startChangeNumber) { int blockSize = conn.getConfiguration().getChangeLogBlockSize(); boolean filterWithOrInsteadOfAnd = conn.getConfiguration(). isFilterWithOrInsteadOfAnd(); @@ -620,21 +606,21 @@ ChangeLogAttributes getChangeLogAttributes() { try { Attributes attrs = conn.getInitialContext().getAttributes("", new String[] { "changeLog", "firstChangeNumber", "lastChangeNumber" }); - String changeLog = getStringAttrValue(attrs, "changeLog"); - String firstChangeNumber = getStringAttrValue(attrs, "firstChangeNumber"); - String lastChangeNumber = getStringAttrValue(attrs, "lastChangeNumber"); + String changeLog = LdapUtil.getStringAttrValue(attrs, "changeLog"); + String firstChangeNumber = LdapUtil.getStringAttrValue(attrs, "firstChangeNumber"); + String lastChangeNumber = LdapUtil.getStringAttrValue(attrs, "lastChangeNumber"); if (changeLog == null || firstChangeNumber == null | lastChangeNumber == null) { - String error = "Unable to locate the replication change log.\n" + throw new ConnectorException("Unable to locate the replication change log.\n" + "From the admin console please verify that the " + "change log is enabled under Configuration: " + "Replication: Supplier Settings and that the Retro " + "Change Log Plugin is enabled under Configuration: " - + "Plug-ins: Retro Change Log Plugin"; - throw new ConnectorException(error); + + "Plug-ins: Retro Change Log Plugin"); } - changeLogAttrs = new ChangeLogAttributes(changeLog, - convertToInt(firstChangeNumber, 0), convertToInt( - lastChangeNumber, 0)); + changeLogAttrs = new ChangeLogAttributes( + changeLog, + convertToInt(firstChangeNumber, 0), + convertToInt(lastChangeNumber, 0)); } catch (NamingException e) { throw new ConnectorException(e); } @@ -644,7 +630,7 @@ ChangeLogAttributes getChangeLogAttributes() { private String getChangeNumberAttribute() { String result = conn.getConfiguration().getChangeNumberAttribute(); - if (isBlank(result)) { + if (StringUtil.isBlank(result)) { result = "changeNumber"; } return result; @@ -652,9 +638,8 @@ private String getChangeNumberAttribute() { private Set getAttributesToSynchronize() { if (attrsToSync == null) { - Set result = newCaseInsensitiveSet(); - result.addAll(Arrays.asList(nullAsEmpty(conn.getConfiguration(). - getAttributesToSynchronize()))); + Set result = CollectionUtil.newCaseInsensitiveSet(); + result.addAll(Arrays.asList(LdapUtil.nullAsEmpty(conn.getConfiguration().getAttributesToSynchronize()))); if (conn.getConfiguration().isSynchronizePasswords()) { result.add(conn.getConfiguration(). getPasswordAttributeToSynchronize()); @@ -666,9 +651,8 @@ private Set getAttributesToSynchronize() { private Set getObjectClassesToSynchronize() { if (oclassesToSync == null) { - Set result = newCaseInsensitiveSet(); - result.addAll(Arrays.asList(nullAsEmpty(conn.getConfiguration(). - getObjectClassesToSynchronize()))); + Set result = CollectionUtil.newCaseInsensitiveSet(); + result.addAll(Arrays.asList(LdapUtil.nullAsEmpty(conn.getConfiguration().getObjectClassesToSynchronize()))); oclassesToSync = result; } return oclassesToSync; @@ -686,8 +670,7 @@ private PasswordDecryptor getPasswordDecryptor() { return passwordDecryptor; } - private boolean containsAny( - final Set haystack, final Collection needles) { + private boolean containsAny(final Set haystack, final Collection needles) { for (String needle : needles) { if (haystack.contains(needle)) { return true; diff --git a/src/test/java/net/tirasa/connid/bundles/ldap/BlindTrustProvider.java b/src/test/java/net/tirasa/connid/bundles/ldap/BlindTrustProvider.java index fb3a34d..cfa65fc 100644 --- a/src/test/java/net/tirasa/connid/bundles/ldap/BlindTrustProvider.java +++ b/src/test/java/net/tirasa/connid/bundles/ldap/BlindTrustProvider.java @@ -1,18 +1,18 @@ -/* +/* * ==================== * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * + * * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved. - * + * * The contents of this file are subject to the terms of the Common Development * and Distribution License("CDDL") (the "License"). You may not use this file * except in compliance with the License. - * + * * You can obtain a copy of the License at * http://opensource.org/licenses/cddl1.php * See the License for the specific language governing permissions and limitations * under the License. - * + * * When distributing the Covered Code, include this CDDL Header Notice in each file * and include the License file at http://opensource.org/licenses/cddl1.php. * If applicable, add the following below this CDDL Header, with the fields @@ -30,7 +30,6 @@ import java.security.Security; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; - import javax.net.ssl.ManagerFactoryParameters; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactorySpi; @@ -58,6 +57,7 @@ public static final void register() { } } + @SuppressWarnings("deprecation") public BlindTrustProvider() { super(ID, 1.0, ID); put("TrustManagerFactory." + ALGORITHM, BlindTrustManagerFactory.class.getName());