AutoRefactored:
- work with null checked expressions first
- revert conditions
- collapse if statements
- push negations down
- invert equals()
Manually used ternary operators
| | |
| | | |
| | | if (allowsTrailingArguments) { |
| | | buffer.append(" "); |
| | | if (trailingArgsDisplayName == null) { |
| | | buffer.append(INFO_ARGPARSER_USAGE_TRAILINGARGS.get()); |
| | | } else { |
| | | if (trailingArgsDisplayName != null) { |
| | | buffer.append(trailingArgsDisplayName); |
| | | } else { |
| | | buffer.append(INFO_ARGPARSER_USAGE_TRAILINGARGS.get()); |
| | | } |
| | | } |
| | | buffer.append(EOL); |
| | |
| | | // version information. |
| | | usageOrVersionDisplayed = true; |
| | | versionPresent = true; |
| | | try { |
| | | // TODO |
| | | // DirectoryServer.printVersion(usageOutputStream); |
| | | } catch (final Exception e) { |
| | | // Ignored. |
| | | } |
| | | |
| | | return; |
| | | } else { |
| | | // There is no such argument registered. |
| | |
| | | && !shortIDMap.containsKey(OPTION_SHORT_PRODUCT_VERSION)) { |
| | | // "-V" will always be interpreted as requesting |
| | | // version information except if it's already defined |
| | | // (e.g |
| | | // in ldap tools). |
| | | // (e.g in ldap tools). |
| | | usageOrVersionDisplayed = true; |
| | | versionPresent = true; |
| | | try { |
| | | // TODO |
| | | // DirectoryServer.printVersion(usageOutputStream); |
| | | } catch (final Exception e) { |
| | | // Ignored. |
| | | } |
| | | return; |
| | | } else { |
| | | // There is no such argument registered. |
| | |
| | | String value; |
| | | if (a.needsValue()) { |
| | | LocalizableMessage pHolder = a.getValuePlaceholder(); |
| | | if (pHolder == null) { |
| | | value = " {value}"; |
| | | } else { |
| | | if (pHolder != null) { |
| | | value = " " + pHolder; |
| | | } else { |
| | | value = " {value}"; |
| | | } |
| | | } else { |
| | | value = ""; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks that the java version. |
| | | * Checks the java version. |
| | | * |
| | | * @throws ClientException |
| | | * If the java version we are running on is not compatible. |
| | | */ |
| | | public static void checkJavaVersion() throws ClientException { |
| | | final String version = System.getProperty("java.specification.version"); |
| | | if (!(Float.valueOf(version) >= 1.6)) { |
| | | if (Float.valueOf(version) < 1.6) { |
| | | final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; |
| | | throw new ClientException(ReturnCode.JAVA_VERSION_INCOMPATIBLE, ERR_INCOMPATIBLE_JAVA_VERSION.get("1.6", |
| | | version, javaBin), null); |
| | |
| | | } |
| | | |
| | | // Make sure the reference managed object is enabled. |
| | | if (needsEnabling) { |
| | | if (!targetIsEnabledCondition.evaluate(context, ref)) { |
| | | if (needsEnabling |
| | | && !targetIsEnabledCondition.evaluate(context, ref)) { |
| | | LocalizableMessage msg = ERR_CLIENT_REFINT_TARGET_DISABLED.get(ufn, name, getName()); |
| | | unacceptableReasons.add(msg); |
| | | isAcceptable = false; |
| | | } |
| | | } |
| | | } |
| | | return isAcceptable; |
| | | } |
| | | |
| | |
| | | // constraint violation. |
| | | boolean isAcceptable = true; |
| | | for (ManagedObject<?> mo : findReferences(context, getManagedObjectDefinition(), path.getName())) { |
| | | String name = mo.getManagedObjectPath().getName(); |
| | | if (name == null) { |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_CANNOT_DELETE_WITHOUT_NAME.get(getName(), mo.getManagedObjectDefinition() |
| | | .getUserFriendlyName(), getManagedObjectDefinition().getUserFriendlyName()); |
| | | final LocalizableMessage uName1 = mo.getManagedObjectDefinition().getUserFriendlyName(); |
| | | final LocalizableMessage uName2 = getManagedObjectDefinition().getUserFriendlyName(); |
| | | final String moName = mo.getManagedObjectPath().getName(); |
| | | |
| | | final LocalizableMessage msg = moName != null |
| | | ? ERR_CLIENT_REFINT_CANNOT_DELETE_WITH_NAME.get(getName(), uName1, moName, uName2) |
| | | : ERR_CLIENT_REFINT_CANNOT_DELETE_WITHOUT_NAME.get(getName(), uName1, uName2); |
| | | unacceptableReasons.add(msg); |
| | | } else { |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_CANNOT_DELETE_WITH_NAME.get(getName(), mo.getManagedObjectDefinition() |
| | | .getUserFriendlyName(), name, getManagedObjectDefinition().getUserFriendlyName()); |
| | | unacceptableReasons.add(msg); |
| | | } |
| | | isAcceptable = false; |
| | | } |
| | | return isAcceptable; |
| | |
| | | for (ManagedObject<?> mo : findReferences(context, getManagedObjectDefinition(), managedObject |
| | | .getManagedObjectPath().getName())) { |
| | | if (targetNeedsEnablingCondition.evaluate(context, mo)) { |
| | | String name = mo.getManagedObjectPath().getName(); |
| | | if (name == null) { |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_CANNOT_DISABLE_WITHOUT_NAME.get(managedObject |
| | | .getManagedObjectDefinition().getUserFriendlyName(), getName(), mo |
| | | .getManagedObjectDefinition().getUserFriendlyName()); |
| | | final LocalizableMessage uName1 = managedObject.getManagedObjectDefinition().getUserFriendlyName(); |
| | | final LocalizableMessage uName2 = mo.getManagedObjectDefinition().getUserFriendlyName(); |
| | | final String moName = mo.getManagedObjectPath().getName(); |
| | | |
| | | final LocalizableMessage msg = moName != null |
| | | ? ERR_CLIENT_REFINT_CANNOT_DISABLE_WITH_NAME.get(uName1, getName(), uName2, moName) |
| | | : ERR_CLIENT_REFINT_CANNOT_DISABLE_WITHOUT_NAME.get(uName1, getName(), uName2); |
| | | unacceptableReasons.add(msg); |
| | | } else { |
| | | LocalizableMessage msg = |
| | | ERR_CLIENT_REFINT_CANNOT_DISABLE_WITH_NAME.get( |
| | | managedObject.getManagedObjectDefinition().getUserFriendlyName(), getName(), |
| | | mo.getManagedObjectDefinition().getUserFriendlyName(), name); |
| | | unacceptableReasons.add(msg); |
| | | } |
| | | isAcceptable = false; |
| | | } |
| | | } |
| | |
| | | * representation. |
| | | */ |
| | | public void setBaseDN(String baseDN) { |
| | | if (baseDN == null) { |
| | | setBaseDN((DN) null); |
| | | } else { |
| | | // TODO: is it correct to replace server DN.decode by SDK |
| | | // valueOf ? |
| | | setBaseDN(DN.valueOf(baseDN)); |
| | | } |
| | | setBaseDN(baseDN != null ? DN.valueOf(baseDN) : null); |
| | | } |
| | | |
| | | /** |
| | |
| | | public final void setBaseUnit(DurationUnit unit) { |
| | | Reject.ifNull(unit); |
| | | |
| | | // Make sure that the base unit is not bigger than the maximum |
| | | // unit. |
| | | if (maximumUnit != null) { |
| | | if (unit.getDuration() > maximumUnit.getDuration()) { |
| | | // Make sure that the base unit is not bigger than the maximum unit. |
| | | if (maximumUnit != null && unit.getDuration() > maximumUnit.getDuration()) { |
| | | throw new IllegalArgumentException("Base unit greater than maximum unit"); |
| | | } |
| | | } |
| | | |
| | | this.baseUnit = unit; |
| | | } |
| | |
| | | * base unit. |
| | | */ |
| | | public final void setMaximumUnit(String unit) { |
| | | if (unit == null) { |
| | | setMaximumUnit((DurationUnit) null); |
| | | } else { |
| | | setMaximumUnit(DurationUnit.getUnit(unit)); |
| | | } |
| | | setMaximumUnit(unit != null ? DurationUnit.getUnit(unit) : null); |
| | | } |
| | | |
| | | /** |
| | |
| | | * unit. |
| | | */ |
| | | public final void setMaximumUnit(DurationUnit unit) { |
| | | if (unit != null) { |
| | | // Make sure that the maximum unit is not smaller than the |
| | | // base unit. |
| | | if (unit.getDuration() < baseUnit.getDuration()) { |
| | | // Make sure that the maximum unit is not smaller than the base unit. |
| | | if (unit != null && unit.getDuration() < baseUnit.getDuration()) { |
| | | throw new IllegalArgumentException("Maximum unit smaller than base unit"); |
| | | } |
| | | } |
| | | |
| | | this.maximumUnit = unit; |
| | | } |
| | |
| | | * limit is greater than the upper limit. |
| | | */ |
| | | public final void setUpperLimit(String upperLimit) { |
| | | if (upperLimit == null) { |
| | | setUpperLimit((Long) null); |
| | | } else { |
| | | setUpperLimit(DurationUnit.parseValue(upperLimit, baseUnit)); |
| | | } |
| | | setUpperLimit(upperLimit != null ? DurationUnit.parseValue(upperLimit, baseUnit) : null); |
| | | } |
| | | |
| | | /** |
| | |
| | | public String encodeValue(Long value) { |
| | | Reject.ifNull(value); |
| | | |
| | | // Make sure that we correctly encode negative values as |
| | | // "unlimited". |
| | | if (allowUnlimited) { |
| | | if (value < 0) { |
| | | // Make sure that we correctly encode negative values as "unlimited". |
| | | if (allowUnlimited && value < 0) { |
| | | return UNLIMITED; |
| | | } |
| | | } |
| | | |
| | | // Encode the size value using the base unit. |
| | | StringBuilder builder = new StringBuilder(); |
| | |
| | | Reject.ifNull(value); |
| | | |
| | | // First check for the special "unlimited" value when necessary. |
| | | if (allowUnlimited) { |
| | | if (value.trim().equalsIgnoreCase(UNLIMITED)) { |
| | | if (allowUnlimited && UNLIMITED.equalsIgnoreCase(value.trim())) { |
| | | return -1L; |
| | | } |
| | | } |
| | | |
| | | // Parse the string representation. |
| | | long ms; |
| | |
| | | Long i = (long) baseUnit.fromMilliSeconds(ms); |
| | | try { |
| | | validateValue(i); |
| | | return i; |
| | | } catch (PropertyException e) { |
| | | throw PropertyException.illegalPropertyValueException(this, value); |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | */ |
| | | public enum DurationUnit { |
| | | |
| | | /** |
| | | * A day unit. |
| | | */ |
| | | DAYS((long) 24 * 60 * 60 * 1000, "d", "days"), |
| | | /** A day unit. */ |
| | | DAYS(24 * 60 * 60 * 1000, "d", "days"), |
| | | |
| | | /** |
| | | * An hour unit. |
| | | */ |
| | | HOURS((long) 60 * 60 * 1000, "h", "hours"), |
| | | /** An hour unit. */ |
| | | HOURS(60 * 60 * 1000, "h", "hours"), |
| | | |
| | | /** |
| | | * A millisecond unit. |
| | | */ |
| | | /** A millisecond unit. */ |
| | | MILLI_SECONDS(1L, "ms", "milliseconds"), |
| | | |
| | | /** |
| | | * A minute unit. |
| | | */ |
| | | MINUTES((long) 60 * 1000, "m", "minutes"), |
| | | /** A minute unit. */ |
| | | MINUTES(60 * 1000, "m", "minutes"), |
| | | |
| | | /** |
| | | * A second unit. |
| | | */ |
| | | /** A second unit. */ |
| | | SECONDS(1000L, "s", "seconds"), |
| | | |
| | | /** |
| | | * A week unit. |
| | | */ |
| | | WEEKS((long) 7 * 24 * 60 * 60 * 1000, "w", "weeks"); |
| | | /** A week unit. */ |
| | | WEEKS(7 * 24 * 60 * 60 * 1000, "w", "weeks"); |
| | | |
| | | /** A lookup table for resolving a unit from its name. */ |
| | | private static final Map<String, DurationUnit> NAME_TO_UNIT; |
| | |
| | | Reject.ifNull(value); |
| | | |
| | | // Make sure that we correctly encode negative values as "unlimited". |
| | | if (allowUnlimited) { |
| | | if (value < 0) { |
| | | if (allowUnlimited && value < 0) { |
| | | return UNLIMITED; |
| | | } |
| | | } |
| | | |
| | | return value.toString(); |
| | | } |
| | |
| | | public Integer decodeValue(String value) { |
| | | Reject.ifNull(value); |
| | | |
| | | if (allowUnlimited) { |
| | | if (value.trim().equalsIgnoreCase(UNLIMITED)) { |
| | | if (allowUnlimited && UNLIMITED.equalsIgnoreCase(value.trim())) { |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | Integer i; |
| | | try { |
| | |
| | | ResourceBundle resource = getResourceBundle(d, locale); |
| | | |
| | | // TODO: use message framework directly |
| | | if (args == null) { |
| | | return LocalizableMessage.raw(resource.getString(key)); |
| | | } else { |
| | | if (args != null) { |
| | | return LocalizableMessage.raw(resource.getString(key), (Object[]) args); |
| | | } |
| | | return LocalizableMessage.raw(resource.getString(key)); |
| | | } |
| | | |
| | | /** |
| | |
| | | lastElement.getManagedObjectDefinition()); |
| | | } |
| | | |
| | | // Decode an element. |
| | | // @Checkstyle:ignore |
| | | private static <C extends ConfigurationClient, S extends Configuration> Element<? extends C, ? extends S> createElement( |
| | | RelationDefinition<C, S> r, String path, String element, String type, String name) { |
| | | /** Decode an element. */ |
| | | private static <C extends ConfigurationClient, S extends Configuration> Element<? extends C, ? extends S> |
| | | createElement(RelationDefinition<C, S> r, String path, String element, String type, String name) { |
| | | // First determine the managed object definition. |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d = null; |
| | | |
| | |
| | | return true; |
| | | } else if (o instanceof PropertyDefinition) { |
| | | PropertyDefinition<?> other = (PropertyDefinition<?>) o; |
| | | if (propertyName.equals(other.propertyName)) { |
| | | if (theClass.equals(other.theClass)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | return propertyName.equals(other.propertyName) |
| | | && theClass.equals(other.theClass); |
| | | } else { |
| | | return false; |
| | | } |
| | |
| | | Reject.ifNull(value); |
| | | |
| | | // Make sure that we correctly encode negative values as "unlimited". |
| | | if (allowUnlimited) { |
| | | if (value < 0) { |
| | | if (allowUnlimited && value < 0) { |
| | | return UNLIMITED; |
| | | } |
| | | } |
| | | |
| | | // Encode the size value using the best-fit unit. |
| | | StringBuilder builder = new StringBuilder(); |
| | |
| | | Reject.ifNull(value); |
| | | |
| | | // First check for the special "unlimited" value when necessary. |
| | | if (allowUnlimited) { |
| | | if (value.trim().equalsIgnoreCase(UNLIMITED)) { |
| | | if (allowUnlimited && UNLIMITED.equalsIgnoreCase(value.trim())) { |
| | | return -1L; |
| | | } |
| | | } |
| | | |
| | | // Decode the value. |
| | | Long i; |
| | |
| | | */ |
| | | public enum SizeUnit { |
| | | |
| | | /** |
| | | * A byte unit. |
| | | */ |
| | | /** A byte unit. */ |
| | | BYTES(1L, "b", "bytes"), |
| | | |
| | | /** |
| | | * A gibi-byte unit. |
| | | */ |
| | | GIBI_BYTES((long) 1024 * 1024 * 1024, "gib", "gibibytes"), |
| | | /** A gibi-byte unit. */ |
| | | GIBI_BYTES(1024 * 1024 * 1024, "gib", "gibibytes"), |
| | | |
| | | /** |
| | | * A giga-byte unit. |
| | | */ |
| | | GIGA_BYTES((long) 1000 * 1000 * 1000, "gb", "gigabytes"), |
| | | /** A giga-byte unit. */ |
| | | GIGA_BYTES(1000 * 1000 * 1000, "gb", "gigabytes"), |
| | | |
| | | /** |
| | | * A kibi-byte unit. |
| | | */ |
| | | /** A kibi-byte unit. */ |
| | | KIBI_BYTES(1024L, "kib", "kibibytes"), |
| | | |
| | | /** |
| | | * A kilo-byte unit. |
| | | */ |
| | | /** A kilo-byte unit. */ |
| | | KILO_BYTES(1000L, "kb", "kilobytes"), |
| | | |
| | | /** |
| | | * A mebi-byte unit. |
| | | */ |
| | | MEBI_BYTES((long) 1024 * 1024, "mib", "mebibytes"), |
| | | /** A mebi-byte unit. */ |
| | | MEBI_BYTES(1024 * 1024, "mib", "mebibytes"), |
| | | |
| | | /** |
| | | * A mega-byte unit. |
| | | */ |
| | | MEGA_BYTES((long) 1000 * 1000, "mb", "megabytes"), |
| | | /** A mega-byte unit. */ |
| | | MEGA_BYTES(1000 * 1000, "mb", "megabytes"), |
| | | |
| | | /** |
| | | * A tebi-byte unit. |
| | | */ |
| | | TEBI_BYTES((long) 1024 * 1024 * 1024 * 1024, "tib", "tebibytes"), |
| | | /** A tebi-byte unit. */ |
| | | TEBI_BYTES(1024L * 1024 * 1024 * 1024, "tib", "tebibytes"), |
| | | |
| | | /** |
| | | * A tera-byte unit. |
| | | */ |
| | | TERA_BYTES((long) 1000 * 1000 * 1000 * 1000, "tb", "terabytes"); |
| | | /** A tera-byte unit. */ |
| | | TERA_BYTES(1000L * 1000 * 1000 * 1000, "tb", "terabytes"); |
| | | |
| | | /** A lookup table for resolving a unit from its name. */ |
| | | private static final Map<String, SizeUnit> NAME_TO_UNIT; |
| | |
| | | |
| | | newProperties.addProperty(propertyDef, defaultValues, activeValues); |
| | | |
| | | if (activeValues.isEmpty() && defaultValues.isEmpty() && propertyDef.hasOption(PropertyOption.MANDATORY)) { |
| | | // The active values maybe empty because of a previous |
| | | // exception. |
| | | if (exception == null) { |
| | | if (activeValues.isEmpty() |
| | | && defaultValues.isEmpty() |
| | | && propertyDef.hasOption(PropertyOption.MANDATORY) |
| | | && exception == null) { |
| | | // The active values maybe empty because of a previous exception. |
| | | exception = PropertyException.propertyIsMandatoryException(propertyDef); |
| | | } |
| | | } |
| | | |
| | | if (exception != null) { |
| | | throw exception; |
| | | } |
| | | } |
| | | |
| | | // Determine the type of managed object associated with the named |
| | | // entry. |
| | | // @Checkstyle:off |
| | | /** Determine the type of managed object associated with the named entry. */ |
| | | private <C extends ConfigurationClient, S extends Configuration> ManagedObjectDefinition<? extends C, ? extends S> |
| | | getEntryDefinition(AbstractManagedObjectDefinition<C, S> d, DN dn) throws LdapException, |
| | | DefinitionDecodingException { |
| | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public final <P> void setPropertyValue(PropertyDefinition<P> pd, P value) { |
| | | if (value == null) { |
| | | setPropertyValues(pd, Collections.<P> emptySet()); |
| | | } else { |
| | | if (value != null) { |
| | | setPropertyValues(pd, Collections.singleton(value)); |
| | | } else { |
| | | setPropertyValues(pd, Collections.<P> emptySet()); |
| | | } |
| | | } |
| | | |
| | |
| | | throw PropertyException.propertyIsSingleValuedException(d); |
| | | } |
| | | |
| | | if (values.isEmpty() && d.hasOption(PropertyOption.MANDATORY)) { |
| | | // But only if there are no default values. |
| | | if (property.getDefaultValues().isEmpty()) { |
| | | if (values.isEmpty() && d.hasOption(PropertyOption.MANDATORY) && property.getDefaultValues().isEmpty()) { |
| | | throw PropertyException.propertyIsMandatoryException(d); |
| | | } |
| | | } |
| | | |
| | | // Validate each value. |
| | | for (T e : values) { |
| | |
| | | @SuppressWarnings("unchecked") |
| | | public <T> Collection<T> getPropertyValues(PropertyDefinition<T> d) { |
| | | Collection<T> values = (Collection<T>) properties.get(d); |
| | | if (values == null) { |
| | | return Collections.emptySet(); |
| | | } |
| | | if (values != null) { |
| | | return values; |
| | | } |
| | | return Collections.emptySet(); |
| | | } |
| | | |
| | | /** Add a single property value. */ |
| | | @SuppressWarnings("unchecked") |
| | |
| | | builder.setPrompt(INFO_EDITOR_PROMPT_MODIFY_MENU.get(d.getName())); |
| | | |
| | | // First option is for leaving the property unchanged or |
| | | // applying changes, but only if the state of the property is |
| | | // valid. |
| | | if (!(d.hasOption(PropertyOption.MANDATORY) && currentValues.isEmpty())) { |
| | | // applying changes, but only if the state of the property is valid. |
| | | if (!d.hasOption(PropertyOption.MANDATORY) || !currentValues.isEmpty()) { |
| | | MenuResult<Boolean> result; |
| | | if (!oldValues.equals(currentValues)) { |
| | | result = MenuResult.success(true); |
| | |
| | | // properties should apply here. |
| | | DefaultBehaviorQuery<T> query = DefaultBehaviorQuery.query(pd); |
| | | LocalizableMessage aliasDescription = query.getAliasDescription(); |
| | | if (aliasDescription == null) { |
| | | app.println(INFO_EDITOR_HEADING_READ_ONLY_ALIAS_UNDEFINED.get(pd.getName())); |
| | | } else { |
| | | if (aliasDescription != null) { |
| | | app.println(INFO_EDITOR_HEADING_READ_ONLY_ALIAS.get(pd.getName(), aliasDescription)); |
| | | } else { |
| | | app.println(INFO_EDITOR_HEADING_READ_ONLY_ALIAS_UNDEFINED.get(pd.getName())); |
| | | } |
| | | break; |
| | | case 1: |
| | |
| | | pvalues.add(value); |
| | | } |
| | | |
| | | if (pvalues.isEmpty() && propertyDef.hasOption(PropertyOption.MANDATORY)) { |
| | | // The values maybe empty because of a previous exception. |
| | | if (exception == null) { |
| | | if (pvalues.isEmpty() && propertyDef.hasOption(PropertyOption.MANDATORY) && exception == null) { |
| | | exception = PropertyException.propertyIsMandatoryException(propertyDef); |
| | | } |
| | | } |
| | | |
| | | if (exception != null) { |
| | | throw exception; |
| | | } else { |
| | | return pvalues; |
| | | } |
| | | return pvalues; |
| | | } |
| | | |
| | | /** Gets the attribute values associated with a property from a ConfigEntry. */ |
| | |
| | | Method getPropertyDefMethod = getPropertyDefinitionMethod(definitionClass, invokedMethodName); |
| | | Class<?> propertyReturnType = getPropertyReturnType(getPropertyDefMethod); |
| | | Object defaultValue = getDefaultValue(definition, getPropertyDefMethod, propertyReturnType); |
| | | if (defaultValue == null) { |
| | | return answerFromDefaultMockitoBehavior(invocation); |
| | | } |
| | | if (defaultValue != null) { |
| | | return defaultValue; |
| | | } |
| | | return answerFromDefaultMockitoBehavior(invocation); |
| | | } catch (Exception e) { |
| | | return answerFromDefaultMockitoBehavior(invocation); |
| | | } |
| | |
| | | LDAPProfile.Wrapper profile = new LDAPProfile.Wrapper() { |
| | | @Override |
| | | public String getRelationRDNSequence(RelationDefinition<?, ?> r) { |
| | | if (r.getName().equals(DUMMY_TEST_RELATION)) { |
| | | if (DUMMY_TEST_RELATION.equals(r.getName())) { |
| | | return "cn=dummy configuration,cn=config"; |
| | | } else { |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | }; |
| | |
| | | public static <P extends Provider> P getProvider(final Class<P> providerClass, final String requestedProvider, |
| | | final ClassLoader classLoader) { |
| | | ServiceLoader<P> loader = null; |
| | | if (classLoader == null) { |
| | | loader = ServiceLoader.load(providerClass); |
| | | } else { |
| | | if (classLoader != null) { |
| | | loader = ServiceLoader.load(providerClass, classLoader); |
| | | } else { |
| | | loader = ServiceLoader.load(providerClass); |
| | | } |
| | | StringBuilder providersFound = new StringBuilder(); |
| | | for (P provider : loader) { |
| | |
| | | continue; |
| | | } |
| | | |
| | | if (objectClass.getObjectClassType() == ObjectClassType.STRUCTURAL) { |
| | | if (structuralObjectClass == null |
| | | || objectClass.isDescendantOf(structuralObjectClass)) { |
| | | if (objectClass.getObjectClassType() == ObjectClassType.STRUCTURAL |
| | | && (structuralObjectClass == null || objectClass.isDescendantOf(structuralObjectClass))) { |
| | | structuralObjectClass = objectClass; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return structuralObjectClass; |
| | | } |
| | |
| | | */ |
| | | public static Filter present(final String attributeDescription) { |
| | | Reject.ifNull(attributeDescription); |
| | | if (toLowerCase(attributeDescription).equals("objectclass")) { |
| | | if ("objectclass".equals(toLowerCase(attributeDescription))) { |
| | | return OBJECT_CLASS_PRESENT; |
| | | } |
| | | return new Filter(new PresentImpl(attributeDescription)); |
| | |
| | | final String qop = (String) saslClient.getNegotiatedProperty(Sasl.QOP); |
| | | if (qop.equalsIgnoreCase("auth-int") || qop.equalsIgnoreCase("auth-conf")) { |
| | | return this; |
| | | } else { |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | void handle(final RealmCallback callback) throws UnsupportedCallbackException { |
| | | if (realm == null) { |
| | | callback.setText(callback.getDefaultText()); |
| | | } else { |
| | | callback.setText(realm); |
| | | } |
| | | callback.setText(realm != null ? realm : callback.getDefaultText()); |
| | | } |
| | | |
| | | } |
| | |
| | | @Override |
| | | public ConnectionSecurityLayer getConnectionSecurityLayer() { |
| | | final String qop = (String) saslClient.getNegotiatedProperty(Sasl.QOP); |
| | | if (qop.equalsIgnoreCase("auth-int") || qop.equalsIgnoreCase("auth-conf")) { |
| | | if ("auth-int".equalsIgnoreCase(qop) || "auth-conf".equalsIgnoreCase(qop)) { |
| | | return this; |
| | | } else { |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | if (bindClient == null) { |
| | | return new BindClientImpl(this).setNextAuthenticationValue(authenticationValue); |
| | | } else { |
| | | if (bindClient != null) { |
| | | return bindClient; |
| | | } |
| | | return new BindClientImpl(this).setNextAuthenticationValue(authenticationValue); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public final S setDiagnosticMessage(final String message) { |
| | | if (message == null) { |
| | | this.diagnosticMessage = ""; |
| | | } else { |
| | | this.diagnosticMessage = message; |
| | | } |
| | | |
| | | this.diagnosticMessage = message != null ? message : ""; |
| | | return getThis(); |
| | | } |
| | | |
| | | @Override |
| | | public final S setMatchedDN(final String dn) { |
| | | if (dn == null) { |
| | | this.matchedDN = ""; |
| | | } else { |
| | | this.matchedDN = dn; |
| | | } |
| | | |
| | | this.matchedDN = dn != null ? dn : ""; |
| | | return getThis(); |
| | | } |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | if (superiorType.isCollective() != isCollective()) { |
| | | if (!isCollective()) { |
| | | LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_ATTRTYPE_NONCOLLECTIVE_FROM_COLLECTIVE.get( |
| | | if (superiorType.isCollective() != isCollective() && !isCollective()) { |
| | | LocalizableMessage message = WARN_ATTR_SYNTAX_ATTRTYPE_NONCOLLECTIVE_FROM_COLLECTIVE.get( |
| | | getNameOrOID(), superiorType.getNameOrOID()); |
| | | failValidation(invalidSchemaElements, warnings, message); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (syntaxOID != null) { |
| | | if (!schema.hasSyntax(syntaxOID)) { |
| | |
| | | final int endPos = valueLength - 2; |
| | | for (int i = sharpPos + 2; i < endPos; i++) { |
| | | final char c = valueString.charAt(i); |
| | | if (!(c == '0' || c == '1')) { |
| | | if (c != '0' && c != '1') { |
| | | invalidReason.append(ERR_ATTR_SYNTAX_NAMEANDUID_ILLEGAL_BINARY_DIGIT.get( |
| | | valueString, String.valueOf(c), i)); |
| | | return false; |
| | |
| | | // or spaces. |
| | | for (int i = 0; i < length; i++) { |
| | | final char c = valueString.charAt(i); |
| | | if (!(isDigit(c) || c == ' ')) { |
| | | if (!isDigit(c) && c != ' ') { |
| | | invalidReason.append(WARN_ATTR_SYNTAX_NUMERIC_STRING_ILLEGAL_CHAR.get(valueString, |
| | | String.valueOf(c), i)); |
| | | return false; |
| | |
| | | if (!isAllowed) { |
| | | if (errorMessages != null) { |
| | | final LocalizableMessage message; |
| | | if (ditContentRule == null) { |
| | | message = ERR_ENTRY_SCHEMA_OC_DISALLOWED_ATTRIBUTES.get( |
| | | entry.getName(), t.getNameOrOID()); |
| | | } else { |
| | | if (ditContentRule != null) { |
| | | message = ERR_ENTRY_SCHEMA_DCR_DISALLOWED_ATTRIBUTES.get( |
| | | entry.getName(), t.getNameOrOID(), ditContentRule.getNameOrOID()); |
| | | } else { |
| | | message = ERR_ENTRY_SCHEMA_OC_DISALLOWED_ATTRIBUTES.get( |
| | | entry.getName(), t.getNameOrOID()); |
| | | } |
| | | errorMessages.add(message); |
| | | } |
| | |
| | | // the synchronizer. |
| | | if (!isDone()) { |
| | | updateTimestamp(); |
| | | if (searchResultHandler != null) { |
| | | if (!searchResultHandler.handleEntry(entry)) { |
| | | if (searchResultHandler != null && !searchResultHandler.handleEntry(entry)) { |
| | | searchResultHandler = null; |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | |
| | | // the synchronizer. |
| | | if (!isDone()) { |
| | | updateTimestamp(); |
| | | if (searchResultHandler != null) { |
| | | if (!searchResultHandler.handleReference(reference)) { |
| | | if (searchResultHandler != null && !searchResultHandler.handleReference(reference)) { |
| | | searchResultHandler = null; |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | Result newErrorResult(final ResultCode resultCode, final String diagnosticMessage, |
| | | final Throwable cause) { |
| | | return Responses.newResult(resultCode).setDiagnosticMessage(diagnosticMessage).setCause( |
| | | cause); |
| | | return Responses.newResult(resultCode).setDiagnosticMessage(diagnosticMessage).setCause(cause); |
| | | } |
| | | |
| | | @Override |
| | |
| | | final String[] arguments = args.toArray(new String[args.size()]); |
| | | |
| | | final AttributeValueTag tag = new AttributeValueTag(); |
| | | if (branch == null) { |
| | | tag.initializeForTemplate(schema, this, template, arguments, lineNumber, warnings); |
| | | } else { |
| | | if (branch != null) { |
| | | tag.initializeForBranch(schema, this, branch, arguments, lineNumber, warnings); |
| | | } else { |
| | | tag.initializeForTemplate(schema, this, template, arguments, lineNumber, warnings); |
| | | } |
| | | return tag; |
| | | } |
| | |
| | | break; |
| | | |
| | | case NUMERIC: |
| | | long randomValue = ((random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % valueRange) + minValue; |
| | | if (decimalFormat == null) { |
| | | templateValue.append(randomValue); |
| | | } else { |
| | | long randomValue = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % valueRange + minValue; |
| | | if (decimalFormat != null) { |
| | | templateValue.append(decimalFormat.format(randomValue)); |
| | | } else { |
| | | templateValue.append(randomValue); |
| | | } |
| | | break; |
| | | |
| | |
| | | @Override |
| | | TagResult generateValue(TemplateEntry templateEntry, TemplateValue templateValue) { |
| | | DN dn = templateEntry.getDN(); |
| | | if (dn == null || dn.isRootDN()) { |
| | | return TagResult.SUCCESS; |
| | | } else { |
| | | if (dn != null && !dn.isRootDN()) { |
| | | templateValue.append(dn.rdn()); |
| | | return TagResult.SUCCESS; |
| | | } |
| | | return TagResult.SUCCESS; |
| | | } |
| | | } |
| | | |
| | |
| | | public void testOperatingSystems(String value) throws Exception { |
| | | String orig = System.getProperty("os.name"); |
| | | try { |
| | | if (value == null) { |
| | | System.clearProperty("os.name"); |
| | | } else { |
| | | if (value != null) { |
| | | System.setProperty("os.name", value); |
| | | } else { |
| | | System.clearProperty("os.name"); |
| | | } |
| | | run(); |
| | | } finally { |
| | |
| | | @Test(dataProvider = "dataForToLowerCase") |
| | | public void testToLowerCaseString(final String s, final String expected) { |
| | | final String actual = toLowerCase(s); |
| | | if (expected == null) { |
| | | Assert.assertSame(actual, s); |
| | | } else { |
| | | if (expected != null) { |
| | | Assert.assertEquals(actual, expected); |
| | | } else { |
| | | Assert.assertSame(actual, s); |
| | | } |
| | | } |
| | | |
| | |
| | | public void testToLowerCaseStringBuilder(final String s, final String expected) { |
| | | final StringBuilder builder = new StringBuilder(); |
| | | final String actual = toLowerCase(s, builder).toString(); |
| | | if (expected == null) { |
| | | Assert.assertEquals(actual, s); |
| | | } else { |
| | | if (expected != null) { |
| | | Assert.assertEquals(actual, expected); |
| | | } else { |
| | | Assert.assertEquals(actual, s); |
| | | } |
| | | } |
| | | |
| | |
| | | @Test(dataProvider = "createModifiableInstance") |
| | | public void testAuthType(final BindRequest request) throws Exception { |
| | | final byte b = request.getAuthenticationType(); |
| | | if (!(b == LDAP.TYPE_AUTHENTICATION_SASL || b == LDAP.TYPE_AUTHENTICATION_SIMPLE)) { |
| | | throw new Exception("Invalid bind type"); |
| | | } |
| | | assertThat(b).isIn(LDAP.TYPE_AUTHENTICATION_SASL, LDAP.TYPE_AUTHENTICATION_SIMPLE); |
| | | } |
| | | |
| | | @Test(dataProvider = "createModifiableInstance") |
| | |
| | | final PasswordExpiredResponseControl control = |
| | | result.getControl(PasswordExpiredResponseControl.DECODER, |
| | | new DecodeOptions()); |
| | | if (!(control == null) && control.hasValue()) { |
| | | if (control != null && control.hasValue()) { |
| | | System.out.println("Password expired for " + dn); |
| | | } |
| | | } catch (final DecodeException de) { |
| | |
| | | final PasswordExpiringResponseControl control = |
| | | result.getControl(PasswordExpiringResponseControl.DECODER, |
| | | new DecodeOptions()); |
| | | if (!(control == null) && control.hasValue()) { |
| | | if (control != null && control.hasValue()) { |
| | | System.out.println("Password for " + dn + " expires in " |
| | | + control.getSecondsUntilExpiration() + " seconds."); |
| | | } |
| | |
| | | final PasswordPolicyResponseControl control = |
| | | result.getControl(PasswordPolicyResponseControl.DECODER, |
| | | new DecodeOptions()); |
| | | if (!(control == null) && !(control.getWarningType() == null)) { |
| | | if (control != null && control.getWarningType() != null) { |
| | | System.out.println("Password policy warning " |
| | | + control.getWarningType() + ", value " |
| | | + control.getWarningValue() + " for " + dn); |
| | |
| | | final PasswordPolicyResponseControl control = |
| | | result.getControl(PasswordPolicyResponseControl.DECODER, |
| | | new DecodeOptions()); |
| | | if (!(control == null)) { |
| | | if (control != null) { |
| | | System.out.println("Password policy error " |
| | | + control.getErrorType() + " for " + dn); |
| | | } |
| | |
| | | port = Integer.parseInt(args[1]); |
| | | infoType = args[2]; |
| | | final String infoTypeLc = infoType.toLowerCase(); |
| | | if (!("all".equals(infoTypeLc) |
| | | || "controls".equals(infoTypeLc) |
| | | || "extops".equals(infoTypeLc))) { |
| | | if (!"all".equals(infoTypeLc) |
| | | && !"controls".equals(infoTypeLc) |
| | | && !"extops".equals(infoTypeLc)) { |
| | | giveUp(); |
| | | } |
| | | } |
| | |
| | | Requests.newCompareRequest(groupDN, "member", memberDN); |
| | | CompareResult result = connection.compare(request); |
| | | |
| | | if (modType == ModificationType.ADD) { |
| | | if (result.getResultCode() == ResultCode.COMPARE_FALSE) { |
| | | if (modType == ModificationType.ADD |
| | | && result.getResultCode() == ResultCode.COMPARE_FALSE) { |
| | | System.out.println("Member does not yet belong to group." |
| | | + " Adding it..."); |
| | | final ModifyRequest addMember = |
| | |
| | | .addModification(modType, "member", memberDN); |
| | | connection.modify(addMember); |
| | | } |
| | | } |
| | | |
| | | if (modType == ModificationType.DELETE) { |
| | | if (result.getResultCode() == ResultCode.COMPARE_TRUE) { |
| | | if (modType == ModificationType.DELETE |
| | | && result.getResultCode() == ResultCode.COMPARE_TRUE) { |
| | | System.out.println("Member belongs to group." |
| | | + " Removing it..."); |
| | | final ModifyRequest delMember = |
| | |
| | | .addModification(modType, "member", memberDN); |
| | | connection.modify(delMember); |
| | | } |
| | | } |
| | | // --- JCite without permissive --- |
| | | |
| | | } |
| | | |
| | | String op = (modType == ModificationType.ADD) ? "added to" : "deleted from"; |
| | |
| | | */ |
| | | private static ModificationType getModificationType(String operation) { |
| | | final boolean isAdd = "add".equalsIgnoreCase(operation); |
| | | if (!(isAdd || "del".equalsIgnoreCase(operation))) { |
| | | if (!isAdd && !"del".equalsIgnoreCase(operation)) { |
| | | printUsage(); |
| | | } |
| | | return isAdd ? ModificationType.ADD : ModificationType.DELETE; |
| | |
| | | String formattedString; |
| | | int colonPos; |
| | | ModifyRequest mr; |
| | | if (data == null) { |
| | | mr = Requests.newModifyRequest(baseDN); |
| | | } else { |
| | | if (data != null) { |
| | | mr = Requests.newModifyRequest(String.format(baseDN, data)); |
| | | } else { |
| | | mr = Requests.newModifyRequest(baseDN); |
| | | } |
| | | for (final String modString : modStrings) { |
| | | if (data == null) { |
| | | formattedString = modString; |
| | | } else { |
| | | if (data != null) { |
| | | formattedString = String.format(modString, data); |
| | | } else { |
| | | formattedString = modString; |
| | | } |
| | | colonPos = formattedString.indexOf(':'); |
| | | if (colonPos > 0) { |
| | |
| | | synchronized (cachedReads) { |
| | | cachedReads.put(request.getName(), pendingCachedRead); |
| | | } |
| | | final LdapPromise<Result> promise = (LdapPromise<Result>) connection |
| | | final LdapPromise<Result> promise = connection |
| | | .searchAsync(withControls(request), intermediateResponseHandler, pendingCachedRead) |
| | | .onSuccess(pendingCachedRead).onFailure(pendingCachedRead); |
| | | pendingCachedRead.setPromise(promise); |
| | |
| | | * @return The password linked to this root user DN. |
| | | */ |
| | | public String getPassword() { |
| | | if (password == null) { |
| | | return null; |
| | | } |
| | | if (password != null) { |
| | | return String.valueOf(password); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * Sets the user root's password. |