Skip to content

Commit 424f99c

Browse files
mfarsikovlbalmaceda
authored andcommitted
Resource server (#77)
* Added CRUD for `Resource server` * Code review iteration * Serialization tests
1 parent 858f5ba commit 424f99c

11 files changed

Lines changed: 642 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,8 @@ public TenantsEntity tenants() {
213213
public TicketsEntity tickets() {
214214
return new TicketsEntity(client, baseUrl, apiToken);
215215
}
216+
217+
public ResourceServerEntity resourceServers(){
218+
return new ResourceServerEntity(client, baseUrl, apiToken);
219+
}
216220
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package com.auth0.client.mgmt;
2+
3+
import java.util.List;
4+
5+
import com.auth0.json.mgmt.ResourceServer;
6+
import com.auth0.net.CustomRequest;
7+
import com.auth0.net.Request;
8+
import com.auth0.net.VoidRequest;
9+
import com.auth0.utils.Asserts;
10+
import com.fasterxml.jackson.core.type.TypeReference;
11+
import okhttp3.HttpUrl;
12+
import okhttp3.OkHttpClient;
13+
14+
public class ResourceServerEntity {
15+
private OkHttpClient client;
16+
private HttpUrl baseUrl;
17+
private String apiToken;
18+
19+
ResourceServerEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
20+
this.client = client;
21+
this.baseUrl = baseUrl;
22+
this.apiToken = apiToken;
23+
}
24+
25+
/**
26+
* Creates request to fetch all resource servers.
27+
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers>API documentation</a>
28+
*
29+
* @return request to execute
30+
*/
31+
public Request<List<ResourceServer>> list() {
32+
33+
HttpUrl.Builder builder = baseUrl
34+
.newBuilder()
35+
.addPathSegments("api/v2/resource-servers");
36+
37+
String url = builder.build().toString();
38+
CustomRequest<List<ResourceServer>> request = new CustomRequest<>(client, url, "GET",
39+
new TypeReference<List<ResourceServer>>() {
40+
});
41+
request.addHeader("Authorization", "Bearer " + apiToken);
42+
return request;
43+
}
44+
45+
/**
46+
* Cretes request for fetching single resource server by it's ID.
47+
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers_by_id>API documentation</a>
48+
*
49+
* @param resourceServerIdOrIdentifier {@link ResourceServer#id} or {@link ResourceServer#identifier} (audience) field
50+
* @return request to execute
51+
*/
52+
public Request<ResourceServer> get(String resourceServerIdOrIdentifier) {
53+
Asserts.assertNotNull(resourceServerIdOrIdentifier, "Resource server ID");
54+
55+
HttpUrl.Builder builder = baseUrl
56+
.newBuilder()
57+
.addPathSegments("api/v2/resource-servers")
58+
.addPathSegment(resourceServerIdOrIdentifier);
59+
60+
String url = builder.build().toString();
61+
CustomRequest<ResourceServer> request = new CustomRequest<>(client, url, "GET",
62+
new TypeReference<ResourceServer>() {
63+
});
64+
request.addHeader("Authorization", "Bearer " + apiToken);
65+
return request;
66+
}
67+
68+
/**
69+
* Cretes request for creation resource server
70+
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/post_resource_servers>API documentation</a>
71+
*
72+
* @param resourceServer resource server body
73+
* @return request to execute
74+
*/
75+
public Request<ResourceServer> create(ResourceServer resourceServer) {
76+
Asserts.assertNotNull(resourceServer, "Resource server");
77+
78+
HttpUrl.Builder builder = baseUrl
79+
.newBuilder()
80+
.addPathSegments("api/v2/resource-servers");
81+
82+
String url = builder.build().toString();
83+
CustomRequest<ResourceServer> request = new CustomRequest<>(client, url, "POST",
84+
new TypeReference<ResourceServer>() {
85+
});
86+
request.addHeader("Authorization", "Bearer " + apiToken);
87+
request.setBody(resourceServer);
88+
return request;
89+
}
90+
91+
/**
92+
* Creates request for delete resource server by it's ID
93+
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/delete_resource_servers_by_id>API documentation</a>
94+
*
95+
* @param resourceServerId {@link ResourceServer#id} field
96+
* @return request to execute
97+
*/
98+
public Request<Void> delete(String resourceServerId) {
99+
Asserts.assertNotNull(resourceServerId, "Resource server ID");
100+
101+
HttpUrl.Builder builder = baseUrl
102+
.newBuilder()
103+
.addPathSegments("api/v2/resource-servers")
104+
.addPathSegment(resourceServerId);
105+
106+
String url = builder.build().toString();
107+
VoidRequest request = new VoidRequest(client, url, "DELETE");
108+
request.addHeader("Authorization", "Bearer " + apiToken);
109+
return request;
110+
}
111+
112+
/**
113+
* Creates request for partial update of resource server. All null fields stay not changed.
114+
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/patch_resource_servers_by_id>API documentation</a>
115+
*
116+
* @param resourceServerId {@link ResourceServer#id} field
117+
* @param resourceServer {@link ResourceServer} body
118+
* @return request to execute
119+
*/
120+
public Request<ResourceServer> update(String resourceServerId, ResourceServer resourceServer) {
121+
Asserts.assertNotNull(resourceServerId, "resourceServerId");
122+
Asserts.assertNotNull(resourceServer, "resourceServer");
123+
124+
HttpUrl.Builder builder = baseUrl
125+
.newBuilder()
126+
.addPathSegments("api/v2/resource-servers")
127+
.addPathSegment(resourceServerId);
128+
129+
String url = builder.build().toString();
130+
CustomRequest<ResourceServer> request = new CustomRequest<ResourceServer>(client, url, "PATCH",
131+
new TypeReference<ResourceServer>() {
132+
});
133+
request.addHeader("Authorization", "Bearer " + apiToken);
134+
request.setBody(resourceServer);
135+
return request;
136+
}
137+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package com.auth0.json.mgmt;
2+
3+
import java.util.List;
4+
5+
import com.fasterxml.jackson.annotation.JsonCreator;
6+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7+
import com.fasterxml.jackson.annotation.JsonInclude;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
@SuppressWarnings({"WeakerAccess", "unused"})
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
@JsonInclude(JsonInclude.Include.NON_NULL)
13+
public class ResourceServer {
14+
@JsonProperty("id")
15+
private String id;
16+
@JsonProperty("name")
17+
private String name;
18+
@JsonProperty("identifier")
19+
private String identifier;
20+
@JsonProperty("scopes")
21+
private List<Scope> scopes;
22+
@JsonProperty("signing_alg")
23+
private String signingAlgorithm;
24+
@JsonProperty("signing_secret")
25+
private String signingSecret;
26+
@JsonProperty("allow_offline_access")
27+
private Boolean allowOfflineAccess;
28+
@JsonProperty("skip_consent_for_verifiable_first_party_clients")
29+
private Boolean skipConsentForVerifiableFirstPartyClients;
30+
@JsonProperty("token_lifetime")
31+
private Integer tokenLifetime;
32+
@JsonProperty("token_lifetime_for_web")
33+
private Integer tokenLifetimeForWeb;
34+
@JsonProperty("verification_location")
35+
private String verificationLocation;
36+
@JsonProperty("is_system")
37+
private Boolean isSystem;
38+
39+
@JsonCreator
40+
public ResourceServer(@JsonProperty("identifier") String identifier) {
41+
this.identifier = identifier;
42+
}
43+
44+
public ResourceServer() {
45+
}
46+
47+
@JsonProperty("id")
48+
public String getId() {
49+
return id;
50+
}
51+
52+
@JsonProperty("id")
53+
public void setId(String id) {
54+
this.id = id;
55+
}
56+
57+
@JsonProperty("name")
58+
public String getName() {
59+
return name;
60+
}
61+
62+
@JsonProperty("name")
63+
public void setName(String name) {
64+
this.name = name;
65+
}
66+
67+
@JsonProperty("is_system")
68+
public Boolean isSystem() {
69+
return isSystem;
70+
}
71+
72+
@JsonProperty("identifier")
73+
public String getIdentifier() {
74+
return identifier;
75+
}
76+
77+
@JsonProperty("scopes")
78+
public List<Scope> getScopes() {
79+
return scopes;
80+
}
81+
82+
@JsonProperty("scopes")
83+
public void setScopes(List<Scope> scopes) {
84+
this.scopes = scopes;
85+
}
86+
87+
@JsonProperty("signing_alg")
88+
public String getSigningAlgorithm() {
89+
return signingAlgorithm;
90+
}
91+
92+
@JsonProperty("signing_alg")
93+
public void setSigningAlgorithm(String signingAlgorithm) {
94+
this.signingAlgorithm = signingAlgorithm;
95+
}
96+
97+
@JsonProperty("signing_secret")
98+
public String getSigningSecret() {
99+
return signingSecret;
100+
}
101+
102+
@JsonProperty("signing_secret")
103+
public void setSigningSecret(String signingSecret) {
104+
this.signingSecret = signingSecret;
105+
}
106+
107+
@JsonProperty("allow_offline_access")
108+
public Boolean getAllowOfflineAccess() {
109+
return allowOfflineAccess;
110+
}
111+
112+
@JsonProperty("allow_offline_access")
113+
public void setAllowOfflineAccess(Boolean allowOfflineAccess) {
114+
this.allowOfflineAccess = allowOfflineAccess;
115+
}
116+
117+
@JsonProperty("skip_consent_for_verifiable_first_party_clients")
118+
public Boolean getSkipConsentForVerifiableFirstPartyClients() {
119+
return skipConsentForVerifiableFirstPartyClients;
120+
}
121+
122+
@JsonProperty("skip_consent_for_verifiable_first_party_clients")
123+
public void setSkipConsentForVerifiableFirstPartyClients(Boolean skipConsentForVerifiableFirstPartyClients) {
124+
this.skipConsentForVerifiableFirstPartyClients = skipConsentForVerifiableFirstPartyClients;
125+
}
126+
127+
@JsonProperty("token_lifetime")
128+
public Integer getTokenLifetime() {
129+
return tokenLifetime;
130+
}
131+
132+
@JsonProperty("token_lifetime")
133+
public void setTokenLifetime(Integer tokenLifetime) {
134+
this.tokenLifetime = tokenLifetime;
135+
}
136+
137+
@JsonProperty("verification_location")
138+
public String getVerificationLocation() {
139+
return verificationLocation;
140+
}
141+
142+
@JsonProperty("verification_location")
143+
public void setVerificationLocation(String verificationLocation) {
144+
this.verificationLocation = verificationLocation;
145+
}
146+
147+
@JsonProperty("token_lifetime_for_web")
148+
public Integer getTokenLifetimeForWeb() {
149+
return tokenLifetimeForWeb;
150+
}
151+
152+
@JsonProperty("token_lifetime_for_web")
153+
public void setTokenLifetimeForWeb(Integer tokenLifetimeForWeb) {
154+
this.tokenLifetimeForWeb = tokenLifetimeForWeb;
155+
}
156+
157+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.auth0.json.mgmt;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
@SuppressWarnings({"WeakerAccess", "unused"})
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
@JsonInclude(JsonInclude.Include.NON_NULL)
11+
public class Scope {
12+
@JsonProperty("description")
13+
private String description;
14+
@JsonProperty("value")
15+
private String value;
16+
17+
@JsonCreator
18+
public Scope(@JsonProperty("value") String value) {
19+
this.value = value;
20+
}
21+
22+
@JsonProperty("description")
23+
public String getDescription() {
24+
return description;
25+
}
26+
27+
@JsonProperty("description")
28+
public void setDescription(String description) {
29+
this.description = description;
30+
}
31+
32+
@JsonProperty("value")
33+
public String getValue() {
34+
return value;
35+
}
36+
37+
@JsonProperty("value")
38+
public void setValue(String value) {
39+
this.value = value;
40+
}
41+
}

0 commit comments

Comments
 (0)