Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions src/main/java/com/auth0/client/mgmt/KeysEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.auth0.client.mgmt;

import com.auth0.client.mgmt.filter.EncryptionKeyFilter;
import com.auth0.json.mgmt.keys.EncryptionKey;
import com.auth0.json.mgmt.keys.EncryptionKeysPage;
import com.auth0.json.mgmt.keys.EncryptionWrappingKeyResponse;
import com.auth0.json.mgmt.keys.Key;
import com.auth0.net.EmptyBodyRequest;
import com.auth0.net.BaseRequest;
Expand All @@ -12,6 +16,7 @@
import okhttp3.HttpUrl;

import java.util.List;
import java.util.Map;

/**
* Class that provides an implementation of the Keys methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Keys
Expand Down Expand Up @@ -117,4 +122,141 @@ public Request<Void> postEncryptionRekey(){

return new EmptyBodyVoidRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Void>() {});
}

/**
* Get all encryption keys.
* A token with scope read:encryption_keys is needed
* See https://auth0.com/docs/api/management/v2#!/Keys/get-encryption-keys
* @param filter Filter to apply. Use null to get all encryption keys.
* @return a Request to execute.
*/
public Request<EncryptionKeysPage> listEncryptionKeys(EncryptionKeyFilter filter){

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/keys/encryption");

if (filter != null) {
for (Map.Entry<String, Object> e : filter.getAsMap().entrySet()) {
builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue()));
}
}

String url = builder.build().toString();
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<EncryptionKeysPage>() {
});
}

/**
* Get the encryption key with the given kid.
* A token with scope read:encryption_keys is needed
* See https://auth0.com/docs/api/management/v2#!/Keys/get-encryption-key
* @param kid Encryption key ID
* @return A Request to execute
*/
public Request<EncryptionKey> getEncryptionKey(String kid){
Asserts.assertNotNull(kid, "kid");

String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/keys/encryption")
.addPathSegment(kid)
.build()
.toString();

return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<EncryptionKey>() {
});
}

/**
* Create a new encryption key.
* A token with scope create:encryption_keys is needed
* See https://auth0.com/docs/api/management/v2#!/Keys/post-encryption
* @param type key type
* @return a Request to execute.
*/
public Request<EncryptionKey> createEncryptionKey(String type) {
Asserts.assertNotNull(type, "type");

String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/keys/encryption")
.build()
.toString();

BaseRequest<EncryptionKey> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference<EncryptionKey>() {
});

request.addParameter("type", type);
return request;
}

/**
* Import an encryption key.
* A token with scope update:encryption_keys is needed
* See https://auth0.com/docs/api/management/v2#!/Keys/post-encryption-key
* @param wrappedKey Base64 encoded ciphertext of key material wrapped by public wrapping key.
* @param kid Encryption key ID
* @return A Request to execute
*/
public Request<EncryptionKey> importEncryptionKey(String wrappedKey, String kid) {
Asserts.assertNotNull(wrappedKey, "wrappedKey");
Asserts.assertNotNull(kid, "kid");

String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/keys/encryption")
.addPathSegment(kid)
.build()
.toString();

BaseRequest<EncryptionKey> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference<EncryptionKey>() {
});

request.addParameter("wrapped_key", wrappedKey);
return request;
}

/**
* Delete the encryption key with the given kid.
* A token with scope delete:encryption_keys is needed
* See https://auth0.com/docs/api/management/v2#!/delete-encryption-key
* @param kid Encryption key ID
* @return a Request to execute.
*/
public Request<Void> deleteEncryptionKey(String kid) {
Asserts.assertNotNull(kid, "kid");

String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/keys/encryption")
.addPathSegment(kid)
.build()
.toString();

return new EmptyBodyVoidRequest<>(client, tokenProvider, url, HttpMethod.DELETE, new TypeReference<Void>() {
});
}

/**
* Create a new encryption wrapping key.
* A token with scope create:encryption_keys is needed
* See https://auth0.com/docs/api/management/v2#!/Keys/post-encryption-wrapping-key
* @param kid Encryption key ID
* @return a Request to execute.
*/
public Request<EncryptionWrappingKeyResponse> createEncryptionWrappingKey(String kid) {
Asserts.assertNotNull(kid, "kid");

String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/keys/encryption")
.addPathSegment(kid)
.addPathSegment("wrapping-key")
.build()
.toString();

return new EmptyBodyRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference<EncryptionWrappingKeyResponse>() {
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.auth0.client.mgmt.filter;

public class EncryptionKeyFilter extends BaseFilter {

/**
* Filter by page
*
* @param pageNumber the page number to retrieve.
* @param amountPerPage the amount of items per page to retrieve.
* @return this filter instance
*/
public EncryptionKeyFilter withPage(int pageNumber, int amountPerPage) {
parameters.put("page", pageNumber);
parameters.put("per_page", amountPerPage);
return this;
}

/**
* Include the query summary
*
* @param includeTotals whether to include or not the query summary.
* @return this filter instance
*/
public EncryptionKeyFilter withTotals(boolean includeTotals) {
parameters.put("include_totals", includeTotals);
return this;
}

}
136 changes: 136 additions & 0 deletions src/main/java/com/auth0/json/mgmt/keys/EncryptionKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.auth0.json.mgmt.keys;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class EncryptionKey {
@JsonProperty("kid")
private String kid;
@JsonProperty("type")
private String type;
@JsonProperty("state")
private String state;
@JsonProperty("created_at")
private String createdAt;
@JsonProperty("updated_at")
private String updatedAt;
@JsonProperty("parent_kid")
private String parentKid;
@JsonProperty("public_key")
private String publicKey;

/**
* Getter for the key id.
* @return
*/
public String getKid() {
return kid;
}

/**
* Setter for the key id.
* @param kid
*/
public void setKid(String kid) {
this.kid = kid;
}

/**
* Getter for the key type.
* @return
*/
public String getType() {
return type;
}

/**
* Setter for the key type.
* @param type
*/
public void setType(String type) {
this.type = type;
}

/**
* Getter for the key state.
* @return
*/
public String getState() {
return state;
}

/**
* Setter for the key state.
* @param state
*/
public void setState(String state) {
this.state = state;
}

/**
* Getter for the key creation date.
* @return
*/
public String getCreatedAt() {
return createdAt;
}

/**
* Setter for the key creation date.
* @param createdAt
*/
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}

/**
* Getter for the key update date.
* @return
*/
public String getUpdatedAt() {
return updatedAt;
}

/**
* Setter for the key update date.
* @param updatedAt
*/
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}

/**
* Getter for the parent key id.
* @return
*/
public String getParentKid() {
return parentKid;
}

/**
* Setter for the parent key id.
* @param parentKid
*/
public void setParentKid(String parentKid) {
this.parentKid = parentKid;
}

/**
* Getter for the public key.
* @return
*/
public String getPublicKey() {
return publicKey;
}

/**
* Setter for the public key.
* @param publicKey
*/
public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/auth0/json/mgmt/keys/EncryptionKeysPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.auth0.json.mgmt.keys;

import com.auth0.json.mgmt.Page;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.util.List;

@SuppressWarnings({"unused", "WeakerAccess"})
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonDeserialize(using = EncryptionKeysPageDeserializer.class)
public class EncryptionKeysPage extends Page<EncryptionKey> {

public EncryptionKeysPage(List<EncryptionKey> items) {
super(items);
}

public EncryptionKeysPage(Integer start, Integer length, Integer total, Integer limit, List<EncryptionKey> items) {
super(start, length, total, limit, items);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.auth0.json.mgmt.keys;

import com.auth0.json.mgmt.PageDeserializer;

import java.util.List;

public class EncryptionKeysPageDeserializer extends PageDeserializer<EncryptionKeysPage, EncryptionKey> {

protected EncryptionKeysPageDeserializer() {
super(EncryptionKey.class, "keys");
}

@Override
protected EncryptionKeysPage createPage(List<EncryptionKey> items) {
return new EncryptionKeysPage(items);
}

@Override
protected EncryptionKeysPage createPage(Integer start, Integer length, Integer total, Integer limit, List<EncryptionKey> items) {
return new EncryptionKeysPage(start, length, total, limit, items);
}

}
Loading