Skip to content

Commit f73de92

Browse files
committed
Added rotate key endpoint for connections
1 parent 908229f commit f73de92

File tree

9 files changed

+367
-39
lines changed

9 files changed

+367
-39
lines changed

src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.auth0.client.mgmt.filter.EnabledClientsFilter;
55
import com.auth0.json.mgmt.connections.*;
66
import com.auth0.net.BaseRequest;
7+
import com.auth0.net.EmptyBodyRequest;
78
import com.auth0.net.Request;
89
import com.auth0.net.VoidRequest;
910
import com.auth0.net.client.Auth0HttpClient;
@@ -425,9 +426,12 @@ public Request<Void> updateEnabledClients(String connectionId, List<EnabledClien
425426
}
426427

427428
/**
428-
*
429+
* Get the Connection Keys.
430+
* A token with scope read:connections_keys is needed.
431+
* @param connectionId the connection id.
432+
* @return a Request to execute.
429433
*/
430-
public Request<ConnectionKeys> getKeys(String connectionId) {
434+
public Request<List<ConnectionKeys>> getKeys(String connectionId) {
431435
Asserts.assertNotNull(connectionId, "connection id");
432436

433437
String url = baseUrl
@@ -437,8 +441,26 @@ public Request<ConnectionKeys> getKeys(String connectionId) {
437441
.addPathSegment("keys")
438442
.build()
439443
.toString();
440-
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<ConnectionKeys>() {
444+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<List<ConnectionKeys>>() {
441445
});
442446
}
443447

448+
/** * Rotate the Connection Keys.
449+
* A token with scope create:connections_keys and update:connections_keys is needed.
450+
* @param connectionId the connection id.
451+
* @return a Request to execute.
452+
*/
453+
public Request<RotateKey> rotateKey(String connectionId) {
454+
Asserts.assertNotNull(connectionId, "connection id");
455+
456+
String url = baseUrl
457+
.newBuilder()
458+
.addPathSegments("api/v2/connections")
459+
.addPathSegment(connectionId)
460+
.addPathSegments("keys/rotate")
461+
.build()
462+
.toString();
463+
464+
return new EmptyBodyRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference<RotateKey>() {});
465+
}
444466
}

src/main/java/com/auth0/json/mgmt/connections/ConnectionKeys.java

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package com.auth0.json.mgmt.connections;
22

3-
import com.fasterxml.jackson.annotation.JsonFormat;
43
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
54
import com.fasterxml.jackson.annotation.JsonInclude;
65
import com.fasterxml.jackson.annotation.JsonProperty;
76

8-
import java.util.Date;
9-
107
@JsonIgnoreProperties(ignoreUnknown = true)
118
@JsonInclude(JsonInclude.Include.NON_NULL)
129
public class ConnectionKeys {
@@ -37,97 +34,184 @@ public class ConnectionKeys {
3734
@JsonProperty("current")
3835
private Boolean current;
3936

40-
@JsonFormat(shape = JsonFormat.Shape.STRING)
4137
@JsonProperty("current_since")
42-
private Date currentSince;
38+
private String currentSince;
4339

4440
@JsonProperty("next")
4541
private Boolean next;
4642

43+
/**
44+
* Getter for the Key ID (kid).
45+
* @return the Key ID (kid).
46+
*/
4747
public String getKid() {
4848
return kid;
4949
}
5050

51+
/**
52+
* Setter for the Key ID (kid).
53+
* @param kid the Key ID (kid).
54+
*/
5155
public void setKid(String kid) {
5256
this.kid = kid;
5357
}
5458

59+
/**
60+
* Getter for the algorithm used by the key.
61+
* @return the algorithm used by the key.
62+
*/
5563
public String getAlgorithm() {
5664
return algorithm;
5765
}
5866

67+
/**
68+
* Setter for the algorithm used by the key.
69+
* @param algorithm the algorithm used by the key.
70+
*/
5971
public void setAlgorithm(String algorithm) {
6072
this.algorithm = algorithm;
6173
}
6274

75+
/**
76+
* Getter for the key use (e.g., "sig" for signature).
77+
* @return the key use.
78+
*/
6379
public String getKeyUse() {
6480
return keyUse;
6581
}
6682

83+
/**
84+
* Setter for the key use.
85+
* @param keyUse the key use (e.g., "sig" for signature).
86+
*/
6787
public void setKeyUse(String keyUse) {
6888
this.keyUse = keyUse;
6989
}
7090

91+
/**
92+
* Getter for the subject distinguished name (DN).
93+
* @return the subject DN.
94+
*/
7195
public String getSubjectDn() {
7296
return subjectDn;
7397
}
7498

99+
/**
100+
* Setter for the subject distinguished name (DN).
101+
* @param subjectDn the subject DN.
102+
*/
75103
public void setSubjectDn(String subjectDn) {
76104
this.subjectDn = subjectDn;
77105
}
78106

107+
/**
108+
* Getter for the certificate associated with the key.
109+
* @return the certificate.
110+
*/
79111
public String getCert() {
80112
return cert;
81113
}
82114

115+
/**
116+
* Setter for the certificate associated with the key.
117+
* @param cert the certificate.
118+
*/
83119
public void setCert(String cert) {
84120
this.cert = cert;
85121
}
86122

123+
/**
124+
* Getter for the fingerprint of the key.
125+
* @return the fingerprint.
126+
*/
87127
public String getFingerprint() {
88128
return fingerprint;
89129
}
90130

131+
/**
132+
* Setter for the fingerprint of the key.
133+
* @param fingerprint the fingerprint.
134+
*/
91135
public void setFingerprint(String fingerprint) {
92136
this.fingerprint = fingerprint;
93137
}
94138

139+
/**
140+
* Getter for the thumbprint of the key.
141+
* @return the thumbprint.
142+
*/
95143
public String getThumbprint() {
96144
return thumbprint;
97145
}
98146

147+
/**
148+
* Setter for the thumbprint of the key.
149+
* @param thumbprint the thumbprint.
150+
*/
99151
public void setThumbprint(String thumbprint) {
100152
this.thumbprint = thumbprint;
101153
}
102154

155+
/**
156+
* Getter for the PKCS#8 representation of the key.
157+
* @return the PKCS#8 representation.
158+
*/
103159
public String getPkcs() {
104160
return pkcs;
105161
}
106162

163+
/**
164+
* Setter for the PKCS#8 representation of the key.
165+
* @param pkcs the PKCS#8 representation.
166+
*/
107167
public void setPkcs(String pkcs) {
108168
this.pkcs = pkcs;
109169
}
110170

171+
/**
172+
* Getter for whether the key is currently active.
173+
* @return true if the key is current, false otherwise.
174+
*/
111175
public Boolean getCurrent() {
112176
return current;
113177
}
114178

179+
/**
180+
* Setter for whether the key is currently active.
181+
* @param current true if the key is current, false otherwise.
182+
*/
115183
public void setCurrent(Boolean current) {
116184
this.current = current;
117185
}
118186

119-
public Date getCurrentSince() {
187+
/**
188+
* Getter for the timestamp when the key became current.
189+
* @return the timestamp in ISO 8601 format.
190+
*/
191+
public String getCurrentSince() {
120192
return currentSince;
121193
}
122194

123-
public void setCurrentSince(Date currentSince) {
195+
/**
196+
* Setter for the timestamp when the key became current.
197+
* @param currentSince the timestamp in ISO 8601 format.
198+
*/
199+
public void setCurrentSince(String currentSince) {
124200
this.currentSince = currentSince;
125201
}
126202

203+
/**
204+
* Getter for whether there is a next key available.
205+
* @return true if there is a next key, false otherwise.
206+
*/
127207
public Boolean getNext() {
128208
return next;
129209
}
130210

211+
/**
212+
* Setter for whether there is a next key available.
213+
* @param next true if there is a next key, false otherwise.
214+
*/
131215
public void setNext(Boolean next) {
132216
this.next = next;
133217
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.auth0.json.mgmt.connections;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
@JsonIgnoreProperties(ignoreUnknown = true)
8+
@JsonInclude(JsonInclude.Include.NON_NULL)
9+
public class RotateKey {
10+
@JsonProperty("cert")
11+
private String cert;
12+
@JsonProperty("kid")
13+
private String kid;
14+
15+
/**
16+
* Returns the certificate used for the key rotation.
17+
* @return the certificate as a String.
18+
*/
19+
public String getCert() {
20+
return cert;
21+
}
22+
23+
/**
24+
* Sets the certificate used for the key rotation.
25+
* @param cert the certificate as a String.
26+
*/
27+
public void setCert(String cert) {
28+
this.cert = cert;
29+
}
30+
31+
/**
32+
* Returns the Key ID (kid) of the key being rotated.
33+
* @return the Key ID as a String.
34+
*/
35+
public String getKid() {
36+
return kid;
37+
}
38+
39+
/**
40+
* Sets the Key ID (kid) of the key being rotated.
41+
* @param kid the Key ID as a String.
42+
*/
43+
public void setKid(String kid) {
44+
this.kid = kid;
45+
}
46+
}

src/test/java/com/auth0/client/MockServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class MockServer {
5050
public static final String MGMT_CONNECTION_SCIM_TOKENS = "src/test/resources/mgmt/connection_scim_tokens.json";
5151
public static final String MGMT_CONNECTION_SCIM_TOKEN = "src/test/resources/mgmt/connection_scim_token.json";
5252
public static final String MGMT_ENABLED_CLIENTS_FOR_CONNECTION = "src/test/resources/mgmt/enabled_clients_for_connection.json";
53+
public static final String MGMT_CONNECTION_KEY = "src/test/resources/mgmt/connection_key.json";
54+
public static final String MGMT_ROTATE_KEY = "src/test/resources/mgmt/rotate_key.json";
5355
public static final String MGMT_DEVICE_CREDENTIALS_LIST = "src/test/resources/mgmt/device_credentials_list.json";
5456
public static final String MGMT_DEVICE_CREDENTIALS = "src/test/resources/mgmt/device_credentials.json";
5557
public static final String MGMT_GRANTS_LIST = "src/test/resources/mgmt/grants_list.json";

0 commit comments

Comments
 (0)