-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Support for Self-Service-Profile (#683)
- Loading branch information
Showing
23 changed files
with
1,523 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 239 additions & 0 deletions
239
src/main/java/com/auth0/client/mgmt/SelfServiceProfilesEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
package com.auth0.client.mgmt; | ||
|
||
import com.auth0.client.mgmt.filter.PageBasedPaginationFilter; | ||
import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfile; | ||
import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponse; | ||
import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponsePage; | ||
import com.auth0.json.mgmt.selfserviceprofiles.SsoAccessTicketResponse; | ||
import com.auth0.net.*; | ||
import com.auth0.net.client.Auth0HttpClient; | ||
import com.auth0.net.client.HttpMethod; | ||
import com.auth0.utils.Asserts; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import okhttp3.HttpUrl; | ||
|
||
import java.util.Map; | ||
|
||
public class SelfServiceProfilesEntity extends BaseManagementEntity { | ||
|
||
private final static String ORGS_PATH = "api/v2/self-service-profiles"; | ||
|
||
SelfServiceProfilesEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { | ||
super(client, baseUrl, tokenProvider); | ||
} | ||
|
||
/** | ||
* Request the list of self-service profiles. | ||
* A token with {@code read:self_service_profiles} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles</a> | ||
* @param pageFilter the pagination filter to apply. Can be null to use the default values. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<SelfServiceProfileResponsePage> get(PageBasedPaginationFilter pageFilter) { | ||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH); | ||
|
||
if (pageFilter != null) { | ||
for (Map.Entry<String, Object> e : pageFilter.getAsMap().entrySet()) { | ||
builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); | ||
} | ||
} | ||
|
||
String url = builder.build().toString(); | ||
return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<SelfServiceProfileResponsePage>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Create a new self-service profile. | ||
* A token with {@code create:self_service_profiles} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-self-service-profiles">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-self-service-profiles</a> | ||
* @param selfServiceProfile the self-service profile to create. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<SelfServiceProfileResponse> create(SelfServiceProfile selfServiceProfile) { | ||
Asserts.assertNotNull(selfServiceProfile, "self service profile"); | ||
Asserts.assertNotNull(selfServiceProfile.getName(), "name"); | ||
|
||
String url = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.build() | ||
.toString(); | ||
|
||
BaseRequest<SelfServiceProfileResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<SelfServiceProfileResponse>() { | ||
}); | ||
request.setBody(selfServiceProfile); | ||
return request; | ||
} | ||
|
||
/** | ||
* Request the self-service profile with the given ID. | ||
* A token with {@code read:self_service_profiles} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profiles-by-id</a> | ||
* @param id the self-service profile ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<SelfServiceProfileResponse> getById(String id) { | ||
Asserts.assertNotNull(id, "id"); | ||
|
||
String url = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(id) | ||
.build() | ||
.toString(); | ||
|
||
return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<SelfServiceProfileResponse>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the self-service profile with the given ID. | ||
* A token with {@code delete:self_service_profiles} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/delete-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/delete-self-service-profiles-by-id</a> | ||
* @param id the self-service profile ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Void> delete(String id) { | ||
Asserts.assertNotNull(id, "id"); | ||
|
||
String url = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(id) | ||
.build() | ||
.toString(); | ||
|
||
return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE); | ||
} | ||
|
||
/** | ||
* Update the self-service profile with the given ID. | ||
* A token with {@code update:self_service_profiles} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/patch-self-service-profiles-by-id">https://auth0.com/docs/api/management/v2#!/self-service-profiles/patch-self-service-profiles-by-id</a> | ||
* @param selfServiceProfile the self-service profile to update. | ||
* @param id the self-service profile ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<SelfServiceProfileResponse> update(SelfServiceProfile selfServiceProfile, String id) { | ||
Asserts.assertNotNull(selfServiceProfile, "self service profile"); | ||
Asserts.assertNotNull(id, "id"); | ||
|
||
String url = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(id) | ||
.build() | ||
.toString(); | ||
|
||
BaseRequest<SelfServiceProfileResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<SelfServiceProfileResponse>() { | ||
}); | ||
request.setBody(selfServiceProfile); | ||
return request; | ||
} | ||
|
||
/** | ||
* Get the custom text for specific self-service profile and language. | ||
* A token with {@code read:self_service_profile_custom_texts} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profile-custom-text">https://auth0.com/docs/api/management/v2#!/self-service-profiles/get-self-service-profile-custom-text</a> | ||
* @param id the self-service profile ID. | ||
* @param language the language. | ||
* @param page the page. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Object> getCustomText(String id, String language, String page) { | ||
Asserts.assertNotNull(id, "id"); | ||
Asserts.assertNotNull(language, "language"); | ||
Asserts.assertNotNull(page, "page"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(id) | ||
.addPathSegment("custom-text") | ||
.addPathSegment(language) | ||
.addPathSegment(page); | ||
|
||
String url = builder.build().toString(); | ||
|
||
return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Set the custom text for specific self-service profile and language. | ||
* A token with {@code update:self_service_profile_custom_texts} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/put-self-service-profile-custom-text">https://auth0.com/docs/api/management/v2#!/self-service-profiles/put-self-service-profile-custom-text</a> | ||
* @param id the self-service profile ID. | ||
* @param language the language. | ||
* @param page the page. | ||
* @param customText the custom text. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Object> setCustomText(String id, String language, String page, Object customText) { | ||
Asserts.assertNotNull(id, "id"); | ||
Asserts.assertNotNull(language, "language"); | ||
Asserts.assertNotNull(page, "page"); | ||
Asserts.assertNotNull(customText, "custom text"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(id) | ||
.addPathSegment("custom-text") | ||
.addPathSegment(language) | ||
.addPathSegment(page); | ||
|
||
String url = builder.build().toString(); | ||
|
||
BaseRequest<Object> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Object>() { | ||
}); | ||
request.setBody(customText); | ||
return request; | ||
} | ||
|
||
/** | ||
* Create a new SSO access ticket. | ||
* A token with {@code create:sso_access_tickets} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-sso-ticket">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-sso-ticket</a> | ||
* @param id the self-service profile ID. | ||
* @param payload the payload. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<SsoAccessTicketResponse> createSsoAccessTicket(String id, Object payload) { | ||
Asserts.assertNotNull(id, "id"); | ||
Asserts.assertNotNull(payload, "payload"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(id) | ||
.addPathSegment("sso-ticket"); | ||
|
||
String url = builder.build().toString(); | ||
|
||
BaseRequest<SsoAccessTicketResponse> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<SsoAccessTicketResponse>() { | ||
}); | ||
request.setBody(payload); | ||
return request; | ||
} | ||
|
||
/** | ||
* Revoke an SSO ticket. | ||
* A token with {@code delete:sso_access_tickets} scope is needed | ||
* @see <a href="https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-revoke">https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-revoke</a> | ||
* @param id the self-service profile ID. | ||
* @param ticketId the ticket ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Void> revokeSsoTicket(String id, String ticketId) { | ||
Asserts.assertNotNull(id, "id"); | ||
Asserts.assertNotNull(ticketId, "ticket id"); | ||
|
||
HttpUrl.Builder builder = baseUrl.newBuilder() | ||
.addPathSegments(ORGS_PATH) | ||
.addPathSegment(id) | ||
.addPathSegment("sso-ticket") | ||
.addPathSegment(ticketId) | ||
.addPathSegment("revoke"); | ||
|
||
String url = builder.build().toString(); | ||
|
||
return new EmptyBodyVoidRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<Void>() { | ||
}); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/auth0/client/mgmt/filter/PageBasedPaginationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.auth0.client.mgmt.filter; | ||
|
||
/** | ||
* Class that represents a filter to be used when requesting a list of items with pagination. | ||
*/ | ||
public class PageBasedPaginationFilter 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 PageBasedPaginationFilter 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 PageBasedPaginationFilter withTotals(boolean includeTotals) { | ||
parameters.put("include_totals", includeTotals); | ||
return this; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/auth0/json/mgmt/selfserviceprofiles/Branding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.auth0.json.mgmt.selfserviceprofiles; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Branding { | ||
@JsonProperty("logo_url") | ||
private String logoUrl; | ||
@JsonProperty("colors") | ||
private Color colors; | ||
|
||
/** | ||
* Getter for the logo URL. | ||
* @return the logo URL. | ||
*/ | ||
public String getLogoUrl() { | ||
return logoUrl; | ||
} | ||
|
||
/** | ||
* Setter for the logo URL. | ||
* @param logoUrl the logo URL to set. | ||
*/ | ||
public void setLogoUrl(String logoUrl) { | ||
this.logoUrl = logoUrl; | ||
} | ||
|
||
/** | ||
* Getter for the colors. | ||
* @return the colors. | ||
*/ | ||
public Color getColors() { | ||
return colors; | ||
} | ||
|
||
/** | ||
* Setter for the colors. | ||
* @param colors the colors to set. | ||
*/ | ||
public void setColors(Color colors) { | ||
this.colors = colors; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/auth0/json/mgmt/selfserviceprofiles/Color.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.auth0.json.mgmt.selfserviceprofiles; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Color { | ||
@JsonProperty("primary") | ||
private String primary; | ||
|
||
/** | ||
* Creates a new instance of the Color class. | ||
*/ | ||
public Color() {} | ||
|
||
/** | ||
* Creates a new instance of the Color class. | ||
* @param primary the primary color. | ||
*/ | ||
@JsonCreator | ||
public Color(@JsonProperty("primary") String primary) { | ||
this.primary = primary; | ||
} | ||
|
||
/** | ||
* Getter for the primary color. | ||
* @return the primary color. | ||
*/ | ||
public String getPrimary() { | ||
return primary; | ||
} | ||
|
||
/** | ||
* Setter for the primary color. | ||
* @param primary the primary color to set. | ||
*/ | ||
public void setPrimary(String primary) { | ||
this.primary = primary; | ||
} | ||
} |
Oops, something went wrong.