com.identityx.clientSDK.piiSupport.FidoRequestUtil Maven / Gradle / Ivy
package com.identityx.clientSDK.piiSupport;
import java.io.StringWriter;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter;
import com.identityx.clientSDK.piiSupport.transactionContentProviders.ITransactionContentProvider;
public class FidoRequestUtil {
/*
* Parses the fidoAuthenticationRequest string and provides the required content
*/
public String replaceTransactionContent(String fidoAuthRequestJson, ITransactionContentProvider[] transactionContentProviders) {
StringWriter mjson = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(mjson);
Gson gson = new Gson();
Object data = gson.fromJson(fidoAuthRequestJson, Object.class);
JsonArray jsonArray = (JsonArray) gson.toJsonTree(data);
for (JsonElement ielement : jsonArray) {
JsonObject iobject = ielement.getAsJsonObject();
JsonElement transactionElement = iobject.get("transaction");
JsonArray iarray = transactionElement.getAsJsonArray();
for (JsonElement jelement : iarray) {
JsonObject transObj = jelement.getAsJsonObject();
JsonElement contentTypeElem = transObj.get("contentType");
for (ITransactionContentProvider transactionContentProvider : transactionContentProviders) {
if (transactionContentProvider.isContentTypeSupported(contentTypeElem.getAsString())) {
JsonElement tcDisplayElem = transObj.get("tcDisplayPNGCharacteristics");
if (tcDisplayElem != null) {
JsonObject dcObj = tcDisplayElem.getAsJsonObject();
DisplayPNGCharacteristics display = gson.fromJson(dcObj, DisplayPNGCharacteristics.class);
String base64Image = transactionContentProvider.getContent(display);
transObj.addProperty("content", base64Image);
}
else {
transObj.addProperty("content", transactionContentProvider.getContent());
}
}
}
}
}
gson.toJson(jsonArray, jsonWriter);
return mjson.toString();
}
/*
* Replaces the username in the fidoRegistrationRequest
*/
public String replaceUsername(String fidoRegRequestJson, String newUsername) {
StringWriter mjson = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(mjson);
Gson gson = new Gson();
Object data = gson.fromJson(fidoRegRequestJson, Object.class);
JsonArray jsonArray = (JsonArray) gson.toJsonTree(data);
for (JsonElement ielement : jsonArray) {
JsonObject iobject = ielement.getAsJsonObject();
iobject.addProperty("username", newUsername);
}
gson.toJson(jsonArray, jsonWriter);
return mjson.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy