Search in sources :

Example 36 with JSONValue

use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSON method getAvailableSASLMechanisms.

/**
 * Retrieves a list of the names of the SASL mechanisms that the user can use
 * to authenticate.
 *
 * @return  A list of the names of the SASL mechanisms that the user can use
 *          to authenticate, or an empty list if no SASL mechanisms are
 *          available to the user or if this was not included in the password
 *          policy state JSON object.
 */
@NotNull()
public List<String> getAvailableSASLMechanisms() {
    final List<String> saslMechanismNames = new ArrayList<>();
    final List<JSONValue> values = passwordPolicyStateObject.getFieldAsArray(AVAILABLE_SASL_MECHANISMS.getFieldName());
    if (values != null) {
        for (final JSONValue v : values) {
            try {
                saslMechanismNames.add(((JSONString) v).stringValue());
            } catch (final Exception e) {
                Debug.debugException(e);
            }
        }
    }
    return Collections.unmodifiableList(saslMechanismNames);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) ArrayList(java.util.ArrayList) JSONString(com.unboundid.util.json.JSONString) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Example 37 with JSONValue

use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSON method getAuthenticationFailureTimes.

/**
 * Retrieves a list of the outstanding authentication failure times for the
 * user account.
 *
 * @return  A list of the outstanding authentication failure times for the
 *          user account, or an empty list if there are no outstanding
 *          authentication failures or if this was not included in the
 *          password policy state JSON object (e.g., because account lockout
 *          is not configured in the password policy that governs the user).
 */
@NotNull()
public List<Date> getAuthenticationFailureTimes() {
    final List<Date> authFailureTimes = new ArrayList<>();
    final List<JSONValue> values = passwordPolicyStateObject.getFieldAsArray(AUTHENTICATION_FAILURE_TIMES.getFieldName());
    if (values != null) {
        for (final JSONValue v : values) {
            try {
                final String valueString = ((JSONString) v).stringValue();
                authFailureTimes.add(StaticUtils.decodeRFC3339Time(valueString));
            } catch (final Exception e) {
                Debug.debugException(e);
            }
        }
    }
    return Collections.unmodifiableList(authFailureTimes);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) ArrayList(java.util.ArrayList) JSONString(com.unboundid.util.json.JSONString) Date(java.util.Date) JSONString(com.unboundid.util.json.JSONString) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Example 38 with JSONValue

use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSON method getAccountUsabilityErrors.

/**
 * Retrieves a list of information about any error conditions that may
 * affect usability of the user's account.
 *
 * @return  A list of information about any error conditions that may affect
 *          the usability of the user's account.  The returned list may be
 *          empty if there are no account usability errors or if this was not
 *          included in the password policy state JSON object.
 */
@NotNull()
public List<PasswordPolicyStateAccountUsabilityError> getAccountUsabilityErrors() {
    final List<PasswordPolicyStateAccountUsabilityError> errors = new ArrayList<>();
    final List<JSONValue> values = passwordPolicyStateObject.getFieldAsArray(ACCOUNT_USABILITY_ERRORS.getFieldName());
    if (values != null) {
        for (final JSONValue v : values) {
            if (v instanceof JSONObject) {
                final JSONObject o = (JSONObject) v;
                final String typeName = o.getFieldAsString(USABILITY_FIELD_TYPE_NAME);
                final Integer typeID = o.getFieldAsInteger(USABILITY_FIELD_TYPE_ID);
                final String message = o.getFieldAsString(USABILITY_FIELD_MESSAGE);
                if ((typeName != null) && (typeID != null)) {
                    errors.add(new PasswordPolicyStateAccountUsabilityError(typeID, typeName, message));
                }
            }
        }
    }
    return Collections.unmodifiableList(errors);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) PasswordPolicyStateAccountUsabilityError(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError) JSONObject(com.unboundid.util.json.JSONObject) ArrayList(java.util.ArrayList) JSONString(com.unboundid.util.json.JSONString) NotNull(com.unboundid.util.NotNull)

Example 39 with JSONValue

use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSON method getAccountUsabilityNotices.

/**
 * Retrieves a list of information about any notices related to the usability
 * of the user's account.
 *
 * @return  A list of information about any notices related to the usability
 *          of the user's account.  The returned list may be empty if there
 *          are no account usability notices or if this was not included in
 *          the password policy state JSON object.
 */
@NotNull()
public List<PasswordPolicyStateAccountUsabilityNotice> getAccountUsabilityNotices() {
    final List<PasswordPolicyStateAccountUsabilityNotice> notices = new ArrayList<>();
    final List<JSONValue> values = passwordPolicyStateObject.getFieldAsArray(ACCOUNT_USABILITY_NOTICES.getFieldName());
    if (values != null) {
        for (final JSONValue v : values) {
            if (v instanceof JSONObject) {
                final JSONObject o = (JSONObject) v;
                final String typeName = o.getFieldAsString(USABILITY_FIELD_TYPE_NAME);
                final Integer typeID = o.getFieldAsInteger(USABILITY_FIELD_TYPE_ID);
                final String message = o.getFieldAsString(USABILITY_FIELD_MESSAGE);
                if ((typeName != null) && (typeID != null)) {
                    notices.add(new PasswordPolicyStateAccountUsabilityNotice(typeID, typeName, message));
                }
            }
        }
    }
    return Collections.unmodifiableList(notices);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) PasswordPolicyStateAccountUsabilityNotice(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice) JSONObject(com.unboundid.util.json.JSONObject) ArrayList(java.util.ArrayList) JSONString(com.unboundid.util.json.JSONString) NotNull(com.unboundid.util.NotNull)

Example 40 with JSONValue

use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.

the class GreaterThanJSONObjectFilter method toJSONObject.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public JSONObject toJSONObject() {
    final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(6));
    fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
    if (field.size() == 1) {
        fields.put(FIELD_FIELD_PATH, new JSONString(field.get(0)));
    } else {
        final ArrayList<JSONValue> fieldNameValues = new ArrayList<>(field.size());
        for (final String s : field) {
            fieldNameValues.add(new JSONString(s));
        }
        fields.put(FIELD_FIELD_PATH, new JSONArray(fieldNameValues));
    }
    fields.put(FIELD_VALUE, value);
    if (allowEquals) {
        fields.put(FIELD_ALLOW_EQUALS, JSONBoolean.TRUE);
    }
    if (matchAllElements) {
        fields.put(FIELD_MATCH_ALL_ELEMENTS, JSONBoolean.TRUE);
    }
    if (caseSensitive) {
        fields.put(FIELD_CASE_SENSITIVE, JSONBoolean.TRUE);
    }
    return new JSONObject(fields);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.unboundid.util.json.JSONArray) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Aggregations

JSONValue (com.unboundid.util.json.JSONValue)50 JSONString (com.unboundid.util.json.JSONString)45 JSONObject (com.unboundid.util.json.JSONObject)40 NotNull (com.unboundid.util.NotNull)33 LinkedHashMap (java.util.LinkedHashMap)31 JSONArray (com.unboundid.util.json.JSONArray)27 ArrayList (java.util.ArrayList)27 Test (org.testng.annotations.Test)9 LogException (com.unboundid.ldap.sdk.unboundidds.logs.LogException)8 JSONBoolean (com.unboundid.util.json.JSONBoolean)6 Map (java.util.Map)6 JSONNumber (com.unboundid.util.json.JSONNumber)5 File (java.io.File)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 JSONException (com.unboundid.util.json.JSONException)4 JSONField (com.unboundid.util.json.JSONField)4 Date (java.util.Date)4 List (java.util.List)4 Entry (com.unboundid.ldap.sdk.Entry)3 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)2