33import io .github .jopenlibs .vault .api .Logical ;
44import io .github .jopenlibs .vault .api .pki .Credential ;
55import io .github .jopenlibs .vault .api .pki .RoleOptions ;
6+ import io .github .jopenlibs .vault .json .JsonObject ;
7+ import io .github .jopenlibs .vault .json .JsonValue ;
68import io .github .jopenlibs .vault .rest .RestResponse ;
79import java .util .ArrayList ;
810import java .util .List ;
911import java .util .Map ;
1012import java .util .StringTokenizer ;
13+ import java .util .stream .Collectors ;
1114
1215/**
1316 * This class is a container for the information returned by Vault in PKI backend API operations
@@ -25,7 +28,7 @@ public class PkiResponse extends LogicalResponse {
2528 public PkiResponse (final RestResponse restResponse , final int retries ) {
2629 super (restResponse , retries , Logical .logicalOperations .authentication );
2730 roleOptions = buildRoleOptionsFromData (this .getData ());
28- credential = buildCredentialFromData (this .getData ());
31+ credential = buildCredentialFromData (this .getData (), this . getDataObject () );
2932 }
3033
3134 public RoleOptions getRoleOptions () {
@@ -104,14 +107,21 @@ private RoleOptions buildRoleOptionsFromData(final Map<String, String> data) {
104107 *
105108 * @param data The <code>"data"</code> object from a Vault JSON response, converted into Java
106109 * key-value pairs.
110+ * @param dataObject The <code>"data"</code> object from a Vault JSON response.
107111 * @return A container for credential data
108112 */
109- private Credential buildCredentialFromData (final Map <String , String > data ) {
113+ private Credential buildCredentialFromData (final Map <String , String > data , final JsonObject dataObject ) {
110114 if (data == null ) {
111115 return null ;
112116 }
113117 final String certificate = data .get ("certificate" );
114118 final String issuingCa = data .get ("issuing_ca" );
119+ final JsonValue caChainJsonValue = dataObject != null ? dataObject .get ("ca_chain" ) : null ;
120+ final List <String > caChain = caChainJsonValue != null
121+ ? caChainJsonValue .asArray ().values ().stream ()
122+ .map (JsonValue ::asString )
123+ .collect (Collectors .toList ())
124+ : null ;
115125 final String privateKey = data .get ("private_key" );
116126 final String privateKeyType = data .get ("private_key_type" );
117127 final String serialNumber = data .get ("serial_number" );
@@ -123,6 +133,7 @@ private Credential buildCredentialFromData(final Map<String, String> data) {
123133 return new Credential ()
124134 .certificate (certificate )
125135 .issuingCa (issuingCa )
136+ .caChain (caChain )
126137 .privateKey (privateKey )
127138 .privateKeyType (privateKeyType )
128139 .serialNumber (serialNumber );
0 commit comments