Skip to content

Commit

Permalink
Added CRUD for Resource server
Browse files Browse the repository at this point in the history
  • Loading branch information
mfarsikov committed Nov 27, 2017
1 parent 61ad709 commit 801209c
Show file tree
Hide file tree
Showing 7 changed files with 536 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/auth0/client/mgmt/ManagementAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,8 @@ public TenantsEntity tenants() {
public TicketsEntity tickets() {
return new TicketsEntity(client, baseUrl, apiToken);
}

public ResourceServerEntity resourceServers(){
return new ResourceServerEntity(client, baseUrl, apiToken);
}
}
137 changes: 137 additions & 0 deletions src/main/java/com/auth0/client/mgmt/ResourceServerEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.auth0.client.mgmt;

import java.util.List;

import com.auth0.json.mgmt.ResourceServer;
import com.auth0.net.CustomRequest;
import com.auth0.net.Request;
import com.auth0.net.VoidRequest;
import com.auth0.utils.Asserts;
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;

public class ResourceServerEntity {
private OkHttpClient client;
private HttpUrl baseUrl;
private String apiToken;

ResourceServerEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
this.client = client;
this.baseUrl = baseUrl;
this.apiToken = apiToken;
}

/**
* Creates request to fetch all resource servers.
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers>API documentation</a>
*
* @return request to execute
*/
public Request<List<ResourceServer>> list() {

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers");

String url = builder.build().toString();
CustomRequest<List<ResourceServer>> request = new CustomRequest<>(client, url, "GET",
new TypeReference<List<ResourceServer>>() {
});
request.addHeader("Authorization", "Bearer " + apiToken);
return request;
}

/**
* Cretes request for fetching single resource server by it's ID.
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers_by_id>API documentation</a>
*
* @param resourceServerId {@link ResourceServer#id} field
* @return request to execute
*/
public Request<ResourceServer> get(String resourceServerId) {
Asserts.assertNotNull(resourceServerId, "Resource server ID");

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers")
.addPathSegment(resourceServerId);

String url = builder.build().toString();
CustomRequest<ResourceServer> request = new CustomRequest<>(client, url, "GET",
new TypeReference<ResourceServer>() {
});
request.addHeader("Authorization", "Bearer " + apiToken);
return request;
}

/**
* Cretes request for creation resource server
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/post_resource_servers>API documentation</a>
*
* @param resourceServer resource server body
* @return request to execute
*/
public Request<ResourceServer> create(ResourceServer resourceServer) {
Asserts.assertNotNull(resourceServer, "Resource server");

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers");

String url = builder.build().toString();
CustomRequest<ResourceServer> request = new CustomRequest<>(client, url, "POST",
new TypeReference<ResourceServer>() {
});
request.addHeader("Authorization", "Bearer " + apiToken);
request.setBody(resourceServer);
return request;
}

/**
* Creates request for delete resource server by it's ID
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/delete_resource_servers_by_id>API documentation</a>
*
* @param resourceServerId {@link ResourceServer#id} field
* @return request to execute
*/
public Request<Void> delete(String resourceServerId) {
Asserts.assertNotNull(resourceServerId, "Resource server ID");

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers")
.addPathSegment(resourceServerId);

String url = builder.build().toString();
VoidRequest request = new VoidRequest(client, url, "DELETE");
request.addHeader("Authorization", "Bearer " + apiToken);
return request;
}

/**
* Creates request for partial update of resource server. All null fields stay not changed.
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/patch_resource_servers_by_id>API documentation</a>
*
* @param resourceServerId {@link ResourceServer#id} field
* @param resourceServer {@link ResourceServer} body
* @return request to execute
*/
public Request<ResourceServer> update(String resourceServerId, ResourceServer resourceServer) {
Asserts.assertNotNull(resourceServerId, "resourceServerId");
Asserts.assertNotNull(resourceServer, "resourceServer");

HttpUrl.Builder builder = baseUrl
.newBuilder()
.addPathSegments("api/v2/resource-servers")
.addPathSegment(resourceServerId);

String url = builder.build().toString();
CustomRequest<ResourceServer> request = new CustomRequest<ResourceServer>(client, url, "PATCH",
new TypeReference<ResourceServer>() {
});
request.addHeader("Authorization", "Bearer " + apiToken);
request.setBody(resourceServer);
return request;
}
}
165 changes: 165 additions & 0 deletions src/main/java/com/auth0/json/mgmt/ResourceServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package com.auth0.json.mgmt;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
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 ResourceServer {
@JsonProperty
private String id;
@JsonProperty
private String name;
@JsonProperty("identifier")
private String identifier;
@JsonProperty("scopes")
private List<Scope> scopes;
@JsonProperty("signing_alg")
private String signingAlg;
@JsonProperty("signing_secret")
private String signingSecret;
@JsonProperty("allow_offline_access")
private Boolean allowOfflineAccess;
@JsonProperty("skip_consent_for_verifiable_first_party_clients")
private Boolean skipConsentForVerifiableFirstPartyClients;
@JsonProperty("token_lifetime")
private Integer tokenLifetime;
@JsonProperty("verificationKey")
private String verificationKey;
@JsonProperty("verificationLocation")
private String verificationLocation;
@JsonProperty("is_system")
private Boolean isSystem;

public ResourceServer(String identifier) {
this.identifier = identifier;
}

@JsonCreator
public ResourceServer(@JsonProperty("id") String id,
@JsonProperty("name") String name,
@JsonProperty("identifier") String identifier,
@JsonProperty("scopes") List<Scope> scopes,
@JsonProperty("signing_alg") String signingAlg,
@JsonProperty("signing_secret") String signingSecret,
@JsonProperty("allow_offline_access") Boolean allowOfflineAccess,
@JsonProperty("skip_consent_for_verifiable_first_party_clients")
Boolean skipConsentForVerifiableFirstPartyClients,
@JsonProperty("token_lifetime") Integer tokenLifetime,
@JsonProperty("verificationKey") String verificationKey,
@JsonProperty("verificationLocation") String verificationLocation,
@JsonProperty("is_system") Boolean isSystem) {
this.id = id;
this.name = name;
this.identifier = identifier;
this.scopes = scopes;
this.signingAlg = signingAlg;
this.signingSecret = signingSecret;
this.allowOfflineAccess = allowOfflineAccess;
this.skipConsentForVerifiableFirstPartyClients = skipConsentForVerifiableFirstPartyClients;
this.tokenLifetime = tokenLifetime;
this.verificationKey = verificationKey;
this.verificationLocation = verificationLocation;
this.isSystem = isSystem;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Boolean getIsSystem() {
return isSystem;
}

public void setIsSystem(Boolean system) {
isSystem = system;
}

public String getIdentifier() {
return identifier;
}

public void setIdentifier(String identifier) {
this.identifier = identifier;
}

public List<Scope> getScopes() {
return scopes;
}

public void setScopes(List<Scope> scopes) {
this.scopes = scopes;
}

public String getSigningAlg() {
return signingAlg;
}

public void setSigningAlg(String signingAlg) {
this.signingAlg = signingAlg;
}

public String getSigningSecret() {
return signingSecret;
}

public void setSigningSecret(String signingSecret) {
this.signingSecret = signingSecret;
}

public Boolean getAllowOfflineAccess() {
return allowOfflineAccess;
}

public void setAllowOfflineAccess(Boolean allowOfflineAccess) {
this.allowOfflineAccess = allowOfflineAccess;
}

public Boolean getSkipConsentForVerifiableFirstPartyClients() {
return skipConsentForVerifiableFirstPartyClients;
}

public void setSkipConsentForVerifiableFirstPartyClients(Boolean skipConsentForVerifiableFirstPartyClients) {
this.skipConsentForVerifiableFirstPartyClients = skipConsentForVerifiableFirstPartyClients;
}

public Integer getTokenLifetime() {
return tokenLifetime;
}

public void setTokenLifetime(Integer tokenLifetime) {
this.tokenLifetime = tokenLifetime;
}

public String getVerificationKey() {
return verificationKey;
}

public void setVerificationKey(String verificationKey) {
this.verificationKey = verificationKey;
}

public String getVerificationLocation() {
return verificationLocation;
}

public void setVerificationLocation(String verificationLocation) {
this.verificationLocation = verificationLocation;
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/auth0/json/mgmt/Scope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.auth0.json.mgmt;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class Scope {
@JsonProperty("description")
private String description;
@JsonProperty("value")
private String value;

@JsonCreator
public Scope(@JsonProperty("value") String value,
@JsonProperty("description") String description) {
this.description = description;
this.value = value;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}
Loading

0 comments on commit 801209c

Please sign in to comment.