Skip to content

Commit

Permalink
added cyok implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tanya732 committed Oct 9, 2024
1 parent f6df9ce commit 043c1be
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/com/auth0/client/mgmt/KeysEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.auth0.json.mgmt.keys.Key;
import com.auth0.net.EmptyBodyRequest;
import com.auth0.net.BaseRequest;
import com.auth0.net.EmptyBodyVoidRequest;
import com.auth0.net.Request;
import com.auth0.net.client.Auth0HttpClient;
import com.auth0.net.client.HttpMethod;
Expand Down Expand Up @@ -100,4 +101,20 @@ public Request<Key> revoke(String kid) {
return new EmptyBodyRequest<>(this.client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Key>() {
});
}

/**
* Perform rekeying operation on the key hierarchy.
* A token with scope create:encryption_keys and update:encryption_keys is needed
* See https://auth0.com/docs/api/management/v2#!/Keys/post-encryption-rekey
* @return a Request to execute.
*/
public Request<Void> rekey(){
String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/keys/encryption/rekey")
.build()
.toString();

return new EmptyBodyVoidRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Void>() {});
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/auth0/net/EmptyBodyVoidRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.auth0.net;

import com.auth0.client.mgmt.TokenProvider;
import com.auth0.exception.Auth0Exception;
import com.auth0.net.client.Auth0HttpClient;
import com.auth0.net.client.Auth0HttpResponse;
import com.auth0.net.client.HttpMethod;
import com.auth0.net.client.HttpRequestBody;
import com.fasterxml.jackson.core.type.TypeReference;

/**
* Request class that does not accept parameters to be sent as part of its body and request doesn't return any value on its success.
* The content type of this request is "application/json".
*
* @param <T> The type expected to be received as part of the response.
* @see BaseRequest
*/
public class EmptyBodyVoidRequest<T> extends BaseRequest<T> {
public EmptyBodyVoidRequest(Auth0HttpClient client, TokenProvider tokenProvider, String url, HttpMethod method, TypeReference<T> tType) {
super(client, tokenProvider, url, method, tType);
}

@Override
@SuppressWarnings("deprecation")
protected HttpRequestBody createRequestBody() {
return HttpRequestBody.create("application/json", new byte[0]);
}

@Override
public EmptyBodyVoidRequest<T> addParameter(String name, Object value) {
//do nothing
return this;
}
@Override
protected T parseResponseBody(Auth0HttpResponse response) throws Auth0Exception {
if (!response.isSuccessful()) {
throw super.createResponseException(response);
}
return null;
}

}
14 changes: 14 additions & 0 deletions src/test/java/com/auth0/client/mgmt/KeysEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,18 @@ public void shouldRevokeKey() throws Exception {

assertThat(response, is(notNullValue()));
}

@Test
public void shouldRekey() throws Exception {
Request<Void> request = api.keys().rekey();
assertThat(request, is(notNullValue()));

server.emptyResponse(204);
request.execute().getBody();
RecordedRequest recordedRequest = server.takeRequest();

assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/api/v2/keys/encryption/rekey"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
}
}

0 comments on commit 043c1be

Please sign in to comment.