null-preserving static parsers instead of constructors
parent
9244d6413c
commit
0d25d4cb17
|
@ -8,6 +8,7 @@ import javax.persistence.Embeddable;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.nimbusds.jose.JWEAlgorithm;
|
import com.nimbusds.jose.JWEAlgorithm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,8 +31,14 @@ public class JWEAlgorithmEntity {
|
||||||
this.algorithm = algorithm;
|
this.algorithm = algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JWEAlgorithmEntity(String algorithmName) {
|
public static JWEAlgorithmEntity getForAlgorithmName (String algorithmName) {
|
||||||
setAlgorithmName(algorithmName);
|
JWEAlgorithmEntity ent = new JWEAlgorithmEntity();
|
||||||
|
ent.setAlgorithmName(algorithmName);
|
||||||
|
if (ent.getAlgorithm() == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +60,7 @@ public class JWEAlgorithmEntity {
|
||||||
* @param algorithmName
|
* @param algorithmName
|
||||||
*/
|
*/
|
||||||
public void setAlgorithmName(String algorithmName) {
|
public void setAlgorithmName(String algorithmName) {
|
||||||
if (algorithmName != null) {
|
if (!Strings.isNullOrEmpty(algorithmName)) {
|
||||||
algorithm = JWEAlgorithm.parse(algorithmName);
|
algorithm = JWEAlgorithm.parse(algorithmName);
|
||||||
} else {
|
} else {
|
||||||
algorithm = null;
|
algorithm = null;
|
||||||
|
|
|
@ -7,6 +7,7 @@ import javax.persistence.Basic;
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.nimbusds.jose.EncryptionMethod;
|
import com.nimbusds.jose.EncryptionMethod;
|
||||||
import com.nimbusds.jose.JWEAlgorithm;
|
import com.nimbusds.jose.JWEAlgorithm;
|
||||||
|
|
||||||
|
@ -27,8 +28,14 @@ public class JWEEncryptionMethodEntity {
|
||||||
this.algorithm = algorithm;
|
this.algorithm = algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JWEEncryptionMethodEntity(String algorithmName) {
|
public static JWEEncryptionMethodEntity getForAlgorithmName (String algorithmName) {
|
||||||
setAlgorithmName(algorithmName);
|
JWEEncryptionMethodEntity ent = new JWEEncryptionMethodEntity();
|
||||||
|
ent.setAlgorithmName(algorithmName);
|
||||||
|
if (ent.getAlgorithm() == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,11 +53,11 @@ public class JWEEncryptionMethodEntity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the name of this algorithm.
|
* Set the name of this algorithm.
|
||||||
* Calls JWEAlgorithm.parse()
|
* Calls EncryptionMethod.parse()
|
||||||
* @param algorithmName
|
* @param algorithmName
|
||||||
*/
|
*/
|
||||||
public void setAlgorithmName(String algorithmName) {
|
public void setAlgorithmName(String algorithmName) {
|
||||||
if (algorithmName != null) {
|
if (!Strings.isNullOrEmpty(algorithmName)) {
|
||||||
algorithm = EncryptionMethod.parse(algorithmName);
|
algorithm = EncryptionMethod.parse(algorithmName);
|
||||||
} else {
|
} else {
|
||||||
algorithm = null;
|
algorithm = null;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.nimbusds.jose.JWSAlgorithm;
|
import com.nimbusds.jose.JWSAlgorithm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,8 +32,14 @@ public class JWSAlgorithmEntity {
|
||||||
this.algorithm = algorithm;
|
this.algorithm = algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JWSAlgorithmEntity(String algorithmName) {
|
public static JWSAlgorithmEntity getForAlgorithmName (String algorithmName) {
|
||||||
setAlgorithmName(algorithmName);
|
JWSAlgorithmEntity ent = new JWSAlgorithmEntity();
|
||||||
|
ent.setAlgorithmName(algorithmName);
|
||||||
|
if (ent.getAlgorithm() == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +61,7 @@ public class JWSAlgorithmEntity {
|
||||||
* @param algorithmName
|
* @param algorithmName
|
||||||
*/
|
*/
|
||||||
public void setAlgorithmName(String algorithmName) {
|
public void setAlgorithmName(String algorithmName) {
|
||||||
if (algorithmName != null) {
|
if (!Strings.isNullOrEmpty(algorithmName)) {
|
||||||
algorithm = JWSAlgorithm.parse(algorithmName);
|
algorithm = JWSAlgorithm.parse(algorithmName);
|
||||||
} else {
|
} else {
|
||||||
algorithm = null;
|
algorithm = null;
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class ClientAPI {
|
||||||
@Override
|
@Override
|
||||||
public JWSAlgorithmEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public JWSAlgorithmEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
if (json.isJsonPrimitive()) {
|
if (json.isJsonPrimitive()) {
|
||||||
return new JWSAlgorithmEntity(json.getAsString());
|
return JWSAlgorithmEntity.getForAlgorithmName(json.getAsString());
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class ClientAPI {
|
||||||
@Override
|
@Override
|
||||||
public JWEAlgorithmEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public JWEAlgorithmEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
if (json.isJsonPrimitive()) {
|
if (json.isJsonPrimitive()) {
|
||||||
return new JWEAlgorithmEntity(json.getAsString());
|
return JWEAlgorithmEntity.getForAlgorithmName(json.getAsString());
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public class ClientAPI {
|
||||||
@Override
|
@Override
|
||||||
public JWEEncryptionMethodEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public JWEEncryptionMethodEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
if (json.isJsonPrimitive()) {
|
if (json.isJsonPrimitive()) {
|
||||||
return new JWEEncryptionMethodEntity(json.getAsString());
|
return JWEEncryptionMethodEntity.getForAlgorithmName(json.getAsString());
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ public class ClientDynamicRegistrationEndpoint {
|
||||||
private JWSAlgorithmEntity getAsJwsAlgorithm(JsonObject o, String member) {
|
private JWSAlgorithmEntity getAsJwsAlgorithm(JsonObject o, String member) {
|
||||||
String s = getAsString(o, member);
|
String s = getAsString(o, member);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
return new JWSAlgorithmEntity(s);
|
return JWSAlgorithmEntity.getForAlgorithmName(s);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ public class ClientDynamicRegistrationEndpoint {
|
||||||
private JWEAlgorithmEntity getAsJweAlgorithm(JsonObject o, String member) {
|
private JWEAlgorithmEntity getAsJweAlgorithm(JsonObject o, String member) {
|
||||||
String s = getAsString(o, member);
|
String s = getAsString(o, member);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
return new JWEAlgorithmEntity(s);
|
return JWEAlgorithmEntity.getForAlgorithmName(s);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ public class ClientDynamicRegistrationEndpoint {
|
||||||
private JWEEncryptionMethodEntity getAsJweEncryptionMethod(JsonObject o, String member) {
|
private JWEEncryptionMethodEntity getAsJweEncryptionMethod(JsonObject o, String member) {
|
||||||
String s = getAsString(o, member);
|
String s = getAsString(o, member);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
return new JWEEncryptionMethodEntity(s);
|
return JWEEncryptionMethodEntity.getForAlgorithmName(s);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue