made binary encode/decode null safe
parent
a8377513a6
commit
1fbdd240f1
|
@ -328,8 +328,12 @@ public class MITREidDataService_1_0 extends MITREidDataService_1_X {
|
|||
if (subName.equals("clientAuthorization")) {
|
||||
clientAuthorization = readAuthorizationRequest(reader);
|
||||
} else if (subName.equals("userAuthentication")) {
|
||||
if (reader.peek() == JsonToken.NULL) {
|
||||
reader.skipValue();
|
||||
} else {
|
||||
String authString = reader.nextString();
|
||||
userAuthentication = base64UrlDecodeObject(authString, Authentication.class);
|
||||
}
|
||||
} else {
|
||||
logger.debug("Found unexpected entry");
|
||||
reader.skipValue();
|
||||
|
|
|
@ -667,8 +667,12 @@ public class MITREidDataService_1_1 extends MITREidDataService_1_X {
|
|||
if (subName.equals("clientAuthorization")) {
|
||||
clientAuthorization = readAuthorizationRequest(reader);
|
||||
} else if (subName.equals("userAuthentication")) {
|
||||
if (reader.peek() == JsonToken.NULL) {
|
||||
reader.skipValue();
|
||||
} else {
|
||||
String authString = reader.nextString();
|
||||
userAuthentication = base64UrlDecodeObject(authString, Authentication.class);
|
||||
}
|
||||
} else {
|
||||
logger.debug("Found unexpected entry");
|
||||
reader.skipValue();
|
||||
|
|
|
@ -71,6 +71,9 @@ public abstract class MITREidDataService_1_X implements MITREidDataService {
|
|||
}
|
||||
|
||||
protected static <T> T base64UrlDecodeObject(String encoded, Class<T> type) {
|
||||
if (encoded == null) {
|
||||
return null;
|
||||
} else {
|
||||
T deserialized = null;
|
||||
try {
|
||||
byte[] decoded = BaseEncoding.base64Url().decode(encoded);
|
||||
|
@ -84,8 +87,12 @@ public abstract class MITREidDataService_1_X implements MITREidDataService {
|
|||
}
|
||||
return deserialized;
|
||||
}
|
||||
}
|
||||
|
||||
protected static String base64UrlEncodeObject(Serializable obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
} else {
|
||||
String encoded = null;
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
@ -99,6 +106,7 @@ public abstract class MITREidDataService_1_X implements MITREidDataService {
|
|||
}
|
||||
return encoded;
|
||||
}
|
||||
}
|
||||
protected static Set readSet(JsonReader reader) throws IOException {
|
||||
Set arraySet = null;
|
||||
reader.beginArray();
|
||||
|
|
Loading…
Reference in New Issue