This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As part of the upgrade, jackson has upgraded to 2.8 They over-eagerly prevent our polymorphism (FasterXML/jackson-databind#1358) so we have to use custom deserialisers for the interfaces Solo: @hugh-emerson
- Loading branch information
Hugh Emerson
committed
Sep 26, 2017
1 parent
6791713
commit cf8d90f
Showing
12 changed files
with
71 additions
and
22 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...ain/java/uk/gov/ida/common/shared/configuration/DeserializablePublicKeyConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...gov/ida/common/shared/configuration/DeserializablePublicKeyConfigurationDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package uk.gov.ida.common.shared.configuration; | ||
|
||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
|
||
public class DeserializablePublicKeyConfigurationDeserializer extends JsonDeserializer<DeserializablePublicKeyConfiguration> { | ||
@Override | ||
public DeserializablePublicKeyConfiguration deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
// Setting the Codec explicitly is needed when this executes with the YAMLParser | ||
// for example, when our Dropwizard apps start. The codec doesn't need to be set | ||
// when the JsonParser implementation is used. | ||
p.setCodec(new ObjectMapper()); | ||
JsonNode node = p.getCodec().readTree(p); | ||
|
||
JsonNode certFileNode = node.get("certFile"); | ||
if(certFileNode != null) { | ||
return p.getCodec().treeToValue(node, PublicKeyFileConfiguration.class); | ||
} | ||
return p.getCodec().treeToValue(node, EncodedCertificateConfiguration.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...y-utils/src/main/java/uk/gov/ida/common/shared/configuration/PrivateKeyConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package uk.gov.ida.common.shared.configuration; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import io.dropwizard.jackson.Discoverable; | ||
import java.security.PrivateKey; | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") | ||
@JsonDeserialize(using=PrivateKeyConfigurationDeserializer.class) | ||
public interface PrivateKeyConfiguration extends Discoverable { | ||
PrivateKey getPrivateKey(); | ||
} |
26 changes: 26 additions & 0 deletions
26
...main/java/uk/gov/ida/common/shared/configuration/PrivateKeyConfigurationDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package uk.gov.ida.common.shared.configuration; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
|
||
public class PrivateKeyConfigurationDeserializer extends JsonDeserializer<PrivateKeyConfiguration> { | ||
@Override | ||
public PrivateKeyConfiguration deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
// Setting the Codec explicitly is needed when this executes with the YAMLParser | ||
// for example, when our Dropwizard apps start. The codec doesn't need to be set | ||
// when the JsonParser implementation is used. | ||
p.setCodec(new ObjectMapper()); | ||
JsonNode node = p.getCodec().readTree(p); | ||
|
||
JsonNode certFileNode = node.get("keyFile"); | ||
if(certFileNode != null) { | ||
return p.getCodec().treeToValue(node, PrivateKeyFileConfiguration.class); | ||
} | ||
return p.getCodec().treeToValue(node, EncodedPrivateKeyConfiguration.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
...tils/src/main/java/uk/gov/ida/common/shared/configuration/PublicKeyFileConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters