Skip to content

Commit 7ed2b13

Browse files
committed
Added support for Tenant ACL
1 parent 0be0144 commit 7ed2b13

File tree

16 files changed

+1008
-0
lines changed

16 files changed

+1008
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,14 @@ public SelfServiceProfilesEntity selfServiceProfiles() {
396396
return new SelfServiceProfilesEntity(client, baseUrl, tokenProvider);
397397
}
398398

399+
/**
400+
* Getter for the Network Acls Entity
401+
* @return the Network Acls Entity
402+
*/
403+
public NetworkAclsEntity networkAcls() {
404+
return new NetworkAclsEntity(client, baseUrl, tokenProvider);
405+
}
406+
399407
/**
400408
* Builder for {@link ManagementAPI} API client instances.
401409
*/
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package com.auth0.client.mgmt;
2+
3+
import com.auth0.client.mgmt.filter.NetworkAclsFilter;
4+
import com.auth0.json.mgmt.networkacls.NetworkAcls;
5+
import com.auth0.json.mgmt.networkacls.NetworkAclsPage;
6+
import com.auth0.net.BaseRequest;
7+
import com.auth0.net.Request;
8+
import com.auth0.net.VoidRequest;
9+
import com.auth0.net.client.Auth0HttpClient;
10+
import com.auth0.net.client.HttpMethod;
11+
import com.auth0.utils.Asserts;
12+
import com.fasterxml.jackson.core.type.TypeReference;
13+
import okhttp3.HttpUrl;
14+
15+
import java.util.Map;
16+
17+
public class NetworkAclsEntity extends BaseManagementEntity {
18+
19+
private final static String ORGS_PATH = "api/v2/network-acls";
20+
21+
NetworkAclsEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) {
22+
super(client, baseUrl, tokenProvider);
23+
}
24+
25+
/**
26+
* Lists all Network ACLs for the Auth0 tenant.
27+
* This method allows you to filter the results using the provided {@link NetworkAclsFilter}.
28+
* A token with scope read:network_acls is needed.
29+
*
30+
* @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/get-network-acls">https://auth0.com/docs/api/management/v2#!/network-acls/get-network-acls</a>
31+
* @param filter the filter to apply to the request, can be null.
32+
* @return a Request that can be executed to retrieve a page of Network ACLs.
33+
*/
34+
public Request<NetworkAclsPage> list(NetworkAclsFilter filter) {
35+
HttpUrl.Builder builder = baseUrl.newBuilder()
36+
.addPathSegments(ORGS_PATH);
37+
38+
if (filter != null) {
39+
for (Map.Entry<String, Object> e : filter.getAsMap().entrySet()) {
40+
builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue()));
41+
}
42+
}
43+
44+
String url = builder.build().toString();
45+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<NetworkAclsPage>(){
46+
});
47+
}
48+
49+
/**
50+
* Creates a new Network ACL for the Auth0 tenant.
51+
* A token with scope create:network_acls is needed.
52+
*
53+
* @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/post-network-acls">https://auth0.com/docs/api/management/v2#!/network-acls/post-network-acls</a>
54+
* @param networkAcls the Network ACL to create.
55+
* @return a Request that can be executed to create the Network ACL.
56+
*/
57+
public Request<NetworkAcls> create(NetworkAcls networkAcls) {
58+
Asserts.assertNotNull(networkAcls, "network acls");
59+
String url = baseUrl.newBuilder()
60+
.addPathSegments(ORGS_PATH)
61+
.build().toString();
62+
BaseRequest<NetworkAcls> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference<NetworkAcls>(){});
63+
request.setBody(networkAcls);
64+
return request;
65+
}
66+
67+
/**
68+
* Get a Network ACL by its ID.
69+
* A token with scope read:network_acls is needed.
70+
*
71+
* @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/get-network-acls-by-id">https://auth0.com/docs/api/management/v2#!/network-acls/get-network-acls-by-id</a>
72+
* @param id the ID of the Network ACL to delete.
73+
* @return a Request that can be executed to delete the Network ACL.
74+
*/
75+
public Request<NetworkAcls> get(String id) {
76+
Asserts.assertNotNull(id, "id");
77+
78+
String url = baseUrl.newBuilder()
79+
.addPathSegments(ORGS_PATH)
80+
.addPathSegment(id)
81+
.build().toString();
82+
83+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<NetworkAcls>(){});
84+
}
85+
86+
/**
87+
* Deletes a Network ACL by its ID.
88+
* A token with scope delete:network_acls is needed.
89+
*
90+
* @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/delete-network-acls-by-id">https://auth0.com/docs/api/management/v2#!/network-acls/delete-network-acls-by-id</a>
91+
* @param id the ID of the Network ACL to delete.
92+
* @return a Request that can be executed to delete the Network ACL.
93+
*/
94+
public Request<Void> delete(String id) {
95+
Asserts.assertNotNull(id, "id");
96+
97+
String url = baseUrl.newBuilder()
98+
.addPathSegments(ORGS_PATH)
99+
.addPathSegment(id)
100+
.build().toString();
101+
102+
return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE);
103+
}
104+
105+
/**
106+
* Updates a Network ACL by its ID.
107+
* A token with scope update:network_acls is needed.
108+
*
109+
* @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/put-network-acls-by-id">https://auth0.com/docs/api/management/v2#!/network-acls/put-network-acls-by-id</a>
110+
* @param id the ID of the Network ACL to update.
111+
* @param networkAcls the Network ACL to update.
112+
* @return a Request that can be executed to update the Network ACL.
113+
*/
114+
public Request<NetworkAcls> update(String id, NetworkAcls networkAcls) {
115+
Asserts.assertNotNull(id, "id");
116+
Asserts.assertNotNull(networkAcls, "network acls");
117+
118+
String url = baseUrl.newBuilder()
119+
.addPathSegments(ORGS_PATH)
120+
.addPathSegment(id)
121+
.build().toString();
122+
123+
BaseRequest<NetworkAcls> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PUT, new TypeReference<NetworkAcls>() {
124+
});
125+
request.setBody(networkAcls);
126+
return request;
127+
}
128+
129+
/**
130+
* Partially updates a Network ACL by its ID.
131+
* A token with scope update:network_acls is needed.
132+
*
133+
* @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/patch-network-acls-by-id">https://auth0.com/docs/api/management/v2#!/network-acls/patch-network-acls-by-id</a>
134+
* @param id the ID of the Network ACL to update.
135+
* @param networkAcls the Network ACL to update.
136+
* @return a Request that can be executed to partially update the Network ACL.
137+
*/
138+
Request<NetworkAcls> patch(String id, NetworkAcls networkAcls) {
139+
Asserts.assertNotNull(id, "id");
140+
141+
String url = baseUrl.newBuilder()
142+
.addPathSegments(ORGS_PATH)
143+
.addPathSegment(id)
144+
.build().toString();
145+
146+
BaseRequest<NetworkAcls> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<NetworkAcls>() {
147+
});
148+
request.setBody(networkAcls);
149+
return request;
150+
}
151+
152+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.auth0.client.mgmt.filter;
2+
3+
public class NetworkAclsFilter extends BaseFilter {
4+
5+
/**
6+
* Filter by page
7+
*
8+
* @param pageNumber the page number to retrieve.
9+
* @param amountPerPage the amount of items per page to retrieve.
10+
* @return this filter instance
11+
*/
12+
public NetworkAclsFilter withPage(int pageNumber, int amountPerPage) {
13+
parameters.put("page", pageNumber);
14+
parameters.put("per_page", amountPerPage);
15+
return this;
16+
}
17+
18+
/**
19+
* Include the query summary
20+
*
21+
* @param includeTotals whether to include or not the query summary.
22+
* @return this filter instance
23+
*/
24+
public NetworkAclsFilter withTotals(boolean includeTotals) {
25+
parameters.put("include_totals", includeTotals);
26+
return this;
27+
}
28+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.auth0.json.mgmt.networkacls;
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 Action {
10+
@JsonProperty("block")
11+
private boolean block;
12+
@JsonProperty("allow")
13+
private boolean allow;
14+
@JsonProperty("log")
15+
private boolean log;
16+
@JsonProperty("redirect")
17+
private boolean redirect;
18+
@JsonProperty("redirect_uri")
19+
private String redrectUri;
20+
21+
/**
22+
* Getter for the block action.
23+
* @return true if the action is to block.
24+
*/
25+
@JsonProperty("block")
26+
public boolean isBlock() {
27+
return block;
28+
}
29+
30+
/**
31+
* Setter for the block action.
32+
* @param block true to set the action as block, false otherwise.
33+
*/
34+
@JsonProperty("block")
35+
public void setBlock(boolean block) {
36+
this.block = block;
37+
}
38+
39+
/**
40+
* Getter for the allow action.
41+
* @return true if the action is to allow.
42+
*/
43+
@JsonProperty("allow")
44+
public boolean isAllow() {
45+
return allow;
46+
}
47+
48+
/**
49+
* Setter for the allow action.
50+
* @param allow true to set the action as allow, false otherwise.
51+
*/
52+
@JsonProperty("allow")
53+
public void setAllow(boolean allow) {
54+
this.allow = allow;
55+
}
56+
57+
/**
58+
* Getter for the log action.
59+
* @return true if the action is to log.
60+
*/
61+
@JsonProperty("log")
62+
public boolean isLog() {
63+
return log;
64+
}
65+
66+
/**
67+
* Setter for the log action.
68+
* @param log true to set the action as log, false otherwise.
69+
*/
70+
@JsonProperty("log")
71+
public void setLog(boolean log) {
72+
this.log = log;
73+
}
74+
75+
/**
76+
* Getter for the redirect action.
77+
* @return true if the action is to redirect.
78+
*/
79+
@JsonProperty("redirect")
80+
public boolean isRedirect() {
81+
return redirect;
82+
}
83+
84+
/**
85+
* Setter for the redirect action.
86+
* @param redirect true to set the action as redirect, false otherwise.
87+
*/
88+
@JsonProperty("redirect")
89+
public void setRedirect(boolean redirect) {
90+
this.redirect = redirect;
91+
}
92+
93+
/**
94+
* Getter for the redirect URI.
95+
* @return the redirect URI if set, null otherwise.
96+
*/
97+
public String getRedrectUri() {
98+
return redrectUri;
99+
}
100+
101+
/**
102+
* Setter for the redirect URI.
103+
* @param redrectUri the URI to set for redirection.
104+
*/
105+
public void setRedrectUri(String redrectUri) {
106+
this.redrectUri = redrectUri;
107+
}
108+
}

0 commit comments

Comments
 (0)