OPENDJ-1308 Migrate schema support
Used ConditionResult.valueOf() to simplify client code and make it more readable.
| | |
| | | */ |
| | | package org.opends.guitools.controlpanel.util; |
| | | |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | |
| | | import java.io.File; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.api.ConfigHandler; |
| | | import org.opends.server.config.ConfigEntry; |
| | |
| | | import org.opends.server.types.BackupConfig; |
| | | import org.opends.server.types.BackupDirectory; |
| | | import org.opends.server.types.CanceledOperationException; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryEnvironmentConfig; |
| | | import org.opends.server.types.DirectoryException; |
| | |
| | | import org.opends.server.util.LDIFReader; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | |
| | | /** |
| | | * A class used to read the configuration from a file. This config file |
| | | * handler does not allow to modify the configuration, only to read it. |
| | |
| | | public ConditionResult hasSubordinates(DN entryDN) throws DirectoryException |
| | | { |
| | | ConfigEntry baseEntry = configEntries.get(entryDN); |
| | | if(baseEntry == null) |
| | | if (baseEntry != null) |
| | | { |
| | | return ConditionResult.valueOf(baseEntry.hasChildren()); |
| | | } |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else if(baseEntry.hasChildren()) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | |
| | | */ |
| | | package org.opends.server.api; |
| | | |
| | | |
| | | |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | |
| | | /** |
| | | * This class defines the set of methods and structures that must be |
| | |
| | | public ConditionResult valuesMatch(ByteSequence attributeValue, |
| | | ByteSequence assertionValue) |
| | | { |
| | | if (approximatelyMatch(attributeValue, assertionValue)) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf( |
| | | approximatelyMatch(attributeValue, assertionValue)); |
| | | } |
| | | } |
| | | |
| | |
| | | public ConditionResult valuesMatch(ByteSequence attributeValue, |
| | | ByteSequence assertionValue) |
| | | { |
| | | if (areEqual(attributeValue, assertionValue)) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(areEqual(attributeValue, assertionValue)); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else if(ret == 0) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | return ConditionResult.valueOf(ret != 0); |
| | | } |
| | | |
| | | |
| | |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.util.Reject; |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.admin.std.server.MemoryBackendCfg; |
| | | import org.opends.server.api.Backend; |
| | |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.core.ModifyDNOperation; |
| | | import org.opends.server.core.SearchOperation; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.BackupConfig; |
| | | import org.opends.server.types.BackupDirectory; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.DN; |
| | |
| | | import org.opends.server.util.LDIFException; |
| | | import org.opends.server.util.LDIFReader; |
| | | import org.opends.server.util.LDIFWriter; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | import static org.opends.messages.BackendMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else if(ret == 0) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | return ConditionResult.valueOf(ret != 0); |
| | | } |
| | | |
| | | /** |
| | |
| | | throws DirectoryException |
| | | { |
| | | final NavigableMap<DN, MonitorProvider<?>> dit = getDIT(); |
| | | if (!dit.containsKey(entryDN)) |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else |
| | | if (dit.containsKey(entryDN)) |
| | | { |
| | | final DN nextDN = dit.higherKey(entryDN); |
| | | if (nextDN == null || !nextDN.isDescendantOf(entryDN)) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | return ConditionResult.valueOf( |
| | | nextDN != null && nextDN.isDescendantOf(entryDN)); |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | } |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else if(ret == 0) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | return ConditionResult.valueOf(ret != 0); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else if(ret == 0) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | return ConditionResult.valueOf(ret != 0); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | EntryIDSet entryIDList = |
| | | new EntryIDSet(key.getData(), data.getData()); |
| | | |
| | | if (!entryIDList.isDefined()) |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else if (entryIDList.contains(entryID)) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(entryIDList.contains(entryID)); |
| | | } |
| | | else |
| | | { |
| | |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else if(ret == 0) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | return ConditionResult.valueOf(ret != 0); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public boolean isPasswordExpired() |
| | | { |
| | | if ((isPasswordExpired == null) || |
| | | (isPasswordExpired == ConditionResult.UNDEFINED)) |
| | | { |
| | | getPasswordExpirationTime(); |
| | | } |
| | | |
| | | refreshIfUndefined(isPasswordExpired); |
| | | return isPasswordExpired == ConditionResult.TRUE; |
| | | } |
| | | |
| | | |
| | | private void refreshIfUndefined(ConditionResult cond) |
| | | { |
| | | if (cond == null || cond == ConditionResult.UNDEFINED) |
| | | { |
| | | getPasswordExpirationTime(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether the user's last password change was within the minimum |
| | |
| | | */ |
| | | public boolean mayUseGraceLogin() |
| | | { |
| | | if ((mayUseGraceLogin == null) || |
| | | (mayUseGraceLogin == ConditionResult.UNDEFINED)) |
| | | { |
| | | getPasswordExpirationTime(); |
| | | } |
| | | |
| | | refreshIfUndefined(mayUseGraceLogin); |
| | | return mayUseGraceLogin == ConditionResult.TRUE; |
| | | } |
| | | |
| | |
| | | */ |
| | | public boolean shouldWarn() |
| | | { |
| | | if ((shouldWarn == null) || (shouldWarn == ConditionResult.UNDEFINED)) |
| | | { |
| | | getPasswordExpirationTime(); |
| | | } |
| | | |
| | | refreshIfUndefined(shouldWarn); |
| | | return shouldWarn == ConditionResult.TRUE; |
| | | } |
| | | |
| | |
| | | */ |
| | | public boolean isFirstWarning() |
| | | { |
| | | if ((isFirstWarning == null) || |
| | | (isFirstWarning == ConditionResult.UNDEFINED)) |
| | | { |
| | | getPasswordExpirationTime(); |
| | | } |
| | | |
| | | refreshIfUndefined(isFirstWarning); |
| | | return isFirstWarning == ConditionResult.TRUE; |
| | | } |
| | | |
| | |
| | | throws DirectoryException |
| | | { |
| | | ConfigEntry baseEntry = configEntries.get(entryDN); |
| | | if(baseEntry == null) |
| | | if (baseEntry != null) |
| | | { |
| | | return ConditionResult.valueOf(baseEntry.hasChildren()); |
| | | } |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | else if(baseEntry.hasChildren()) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | return ConditionResult.FALSE; |
| | | } |
| | | |
| | | |
| | | // We support the scheme, so make the determination. |
| | | if (storageScheme.authPasswordMatches(assertionValue, |
| | | return ConditionResult.valueOf( |
| | | storageScheme.authPasswordMatches(assertionValue, |
| | | authPWComponents[1].toString(), |
| | | authPWComponents[2].toString())) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | authPWComponents[2].toString())); |
| | | } |
| | | |
| | | |
| | |
| | | public ConditionResult valuesMatch(ByteSequence attributeValue, |
| | | ByteSequence assertionValue) |
| | | { |
| | | if (assertionValue.equals(attributeValue)) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(assertionValue.equals(attributeValue)); |
| | | } |
| | | |
| | | |
| | |
| | | ByteSequence assertionValue) |
| | | { |
| | | int ret = attributeValue.compareTo(assertionValue); |
| | | |
| | | if (ret < 0) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(ret < 0); |
| | | } |
| | | |
| | | |
| | |
| | | ByteSequence assertionValue) |
| | | { |
| | | int ret = attributeValue.compareTo(assertionValue); |
| | | |
| | | if (ret <= 0) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(ret <= 0); |
| | | } |
| | | |
| | | |
| | |
| | | ByteSequence assertionValue) |
| | | { |
| | | int ret = attributeValue.compareTo(assertionValue); |
| | | |
| | | if (ret > 0) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(ret > 0); |
| | | } |
| | | |
| | | |
| | |
| | | ByteSequence assertionValue) |
| | | { |
| | | int ret = attributeValue.compareTo(assertionValue); |
| | | |
| | | if (ret >= 0) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(ret >= 0); |
| | | } |
| | | |
| | | |
| | |
| | | ByteSequence assertionValue) |
| | | { |
| | | int ret = compareValues(attributeValue, assertionValue); |
| | | |
| | | if (ret > 0) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(ret > 0); |
| | | } |
| | | |
| | | |
| | |
| | | ByteSequence assertionValue) |
| | | { |
| | | int ret = compareValues(attributeValue, assertionValue); |
| | | |
| | | if (ret < 0) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(ret < 0); |
| | | } |
| | | |
| | | |
| | |
| | | int assertMonth = bb.getInt(16); |
| | | int assertYear = bb.getInt(20); |
| | | |
| | | if(assertSecond != -1 && assertSecond !=second) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | |
| | | if(assertMinute !=-1 && assertMinute !=minute) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | |
| | | if(assertHour !=-1 && assertHour !=hour) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | |
| | | if ((assertSecond != -1 && assertSecond != second) |
| | | || (assertMinute != -1 && assertMinute != minute) |
| | | || (assertHour != -1 && assertHour != hour) |
| | | //All the non-zero values should match. |
| | | if(assertDate !=0 && assertDate != date) |
| | | || (assertDate != 0 && assertDate != date) |
| | | || (assertMonth != -1 && assertMonth != month) |
| | | || (assertYear != 0 && assertYear != year)) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | |
| | | if(assertMonth !=-1 && assertMonth != month) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | |
| | | if(assertYear !=0 && assertYear != year) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | |
| | | return ConditionResult.TRUE; |
| | | } |
| | | |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.opends.server.api.EqualityMatchingRule; |
| | | import org.opends.server.api.PasswordStorageScheme; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.opends.server.types.DirectoryException; |
| | | |
| | | import static org.opends.server.schema.SchemaConstants.*; |
| | |
| | | return ConditionResult.FALSE; |
| | | } |
| | | |
| | | |
| | | // We support the scheme, so make the determination. |
| | | if (storageScheme.passwordMatches(assertionValue, |
| | | ByteString.valueOf(userPWComponents[1]))) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return ConditionResult.valueOf(storageScheme.passwordMatches( |
| | | assertionValue, ByteString.valueOf(userPWComponents[1]))); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | // See if the entry has an attribute with the requested type. |
| | | // If so, then it's a match. If not, then it's not a match. |
| | | if (entry.hasAttribute(attributeType, attributeOptions)) |
| | | { |
| | | ConditionResult result = ConditionResult.valueOf( |
| | | entry.hasAttribute(attributeType, attributeOptions)); |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace( |
| | | "Returning TRUE for presence component %s in " + |
| | | "filter %s for entry %s", |
| | | this, completeFilter, entry.getName()); |
| | | "Returning %s for presence component %s in filter %s for entry %s", |
| | | result, this, completeFilter, entry.getName()); |
| | | } |
| | | return ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace( |
| | | "Returning FALSE for presence component %s in " + |
| | | "filter %s for entry %s", |
| | | this, completeFilter, entry.getName()); |
| | | } |
| | | return ConditionResult.FALSE; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | |
| | | package org.opends.server.schema; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.opends.server.api.EqualityMatchingRule; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.AcceptRejectWarn; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | |
| | | |
| | | ConditionResult liveResult = |
| | | rule.valuesMatch(normalizedValue1, normalizedValue2); |
| | | if (result == true) |
| | | assertEquals(ConditionResult.TRUE, liveResult); |
| | | else |
| | | assertEquals(ConditionResult.FALSE, liveResult); |
| | | |
| | | assertEquals(liveResult, ConditionResult.valueOf(result)); |
| | | } |
| | | |
| | | } |
| | |
| | | MatchingRule partialTimeRule = DirectoryServer.getMatchingRule( |
| | | EXT_PARTIAL_DATE_TIME_NAME.toLowerCase()); |
| | | ByteString str = partialTimeRule.normalizeAssertionValue(ByteString.valueOf(assertionValue)); |
| | | assertTrue(partialTimeRule.valuesMatch(ByteString.valueOf(attributeValue), str) == |
| | | ConditionResult.TRUE); |
| | | assertEquals(partialTimeRule.valuesMatch(ByteString.valueOf(attributeValue), str), ConditionResult.TRUE); |
| | | } |
| | | |
| | | |