made binary encode/decode null safe

pull/695/head
Justin Richer 2014-10-06 23:25:48 -04:00
parent a8377513a6
commit 1fbdd240f1
3 changed files with 44 additions and 28 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();