Add typingDNA connector to PreferenceRetrievalClient
@@ -63,6 +63,8 @@ public class PreferenceRetrievalClient {
private static final String MULTI_ATTRIBUTE_LOGIN_HANDLER = "multiattribute.login.handler";
private static final String PROPERTY_NAME = "name";
private static final String PROPERTY_VALUE = "value";
+ private static final String TYPING_DNA_CONNECTOR = "typingdna-config";
+ private static final String TYPING_DNA_PROPERTY = "adaptive_authentication.tdna.enable";
/**
* Check self registration is enabled or not.
@@ -139,6 +141,18 @@ public class PreferenceRetrievalClient {
return checkPreference(tenant, MULTI_ATTRIBUTE_LOGIN_HANDLER, MULTI_ATTRIBUTE_LOGIN_PROPERTY);
}
+ /**
+ * Check typingDNA authentication is enabled or not.
+ *
+ * @param tenant Tenant domain name.
+ * @return returns true if typingDNA enabled.
+ * @throws PreferenceRetrievalClientException PreferenceRetrievalClientException.
+ */
+ public boolean checkTypingDNA(String tenant) throws PreferenceRetrievalClientException {
+
+ return checkPreference(tenant, TYPING_DNA_CONNECTOR, TYPING_DNA_PROPERTY, false);
+ }
+
/**
* Check for preference in the given tenant.
*
@@ -151,6 +165,22 @@ public class PreferenceRetrievalClient {
public boolean checkPreference(String tenant, String connectorName, String propertyName)
throws PreferenceRetrievalClientException {
+ return checkPreference(tenant, connectorName, propertyName, true);
+ }
+
+ /**
+ * Check for preference in the given tenant.
+ *
+ * @param tenant Tenant domain name.
+ * @param connectorName Name of the connector.
+ * @param propertyName Property name to check.
+ * @param defaultValue Default value to be returned if there is any error.
+ * @return returns true if the property is enabled.
+ * @throws PreferenceRetrievalClientException PreferenceRetrievalClientException.
+ */
+ public boolean checkPreference(String tenant, String connectorName, String propertyName, boolean defaultValue)
+ throws PreferenceRetrievalClientException {
+
try (CloseableHttpClient httpclient = HttpClientBuilder.create().useSystemProperties().build()) {
JSONArray main = new JSONArray();
JSONObject preference = new JSONObject();
@@ -171,15 +201,16 @@ public class PreferenceRetrievalClient {
new JSONTokener(new InputStreamReader(response.getEntity().getContent())));
JSONObject connector = (JSONObject) jsonResponse.get(0);
JSONArray responseProperties = connector.getJSONArray(PROPERTIES);
- for (int itemIndex = 0, totalObject = responseProperties.length(); itemIndex < totalObject; itemIndex++) {
+ for (int itemIndex = 0, totalObject = responseProperties.length();
+ itemIndex < totalObject; itemIndex++) {
JSONObject config = responseProperties.getJSONObject(itemIndex);
- if (StringUtils.equalsIgnoreCase(responseProperties.getJSONObject(itemIndex).getString(PROPERTY_NAME),
- propertyName)) {
+ if (StringUtils.equalsIgnoreCase(
+ responseProperties.getJSONObject(itemIndex).getString(PROPERTY_NAME), propertyName)) {
return Boolean.valueOf(config.getString(PROPERTY_VALUE));
}
}
}
- return true;
+ return defaultValue;
} finally {
post.releaseConnection();
}
