Skip to content

Commit

Permalink
Added Support for Self-Service Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
tanya732 committed Dec 20, 2024
1 parent 920affc commit bd020b0
Show file tree
Hide file tree
Showing 14 changed files with 799 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/auth0/client/mgmt/ManagementAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,14 @@ public PromptsEntity prompts() {
return new PromptsEntity(client, baseUrl, tokenProvider);
}

/**
* Getter for the SelfServiceProfiles Entity
* @return the SelfServiceProfiles Entity
*/
public SelfServiceProfilesEntity selfServiceProfiles() {
return new SelfServiceProfilesEntity(client, baseUrl, tokenProvider);
}

/**
* Builder for {@link ManagementAPI} API client instances.
*/
Expand Down
132 changes: 132 additions & 0 deletions src/main/java/com/auth0/client/mgmt/SelfServiceProfilesEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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.net.BaseRequest;
import com.auth0.net.Request;
import com.auth0.net.VoidRequest;
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 scope read:self_service_profiles 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 scope create:self_service_profiles 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 scope read:self_service_profiles 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 scope delete:self_service_profiles 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 scope update:self_service_profiles 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;
}
}
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;
}
}
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 src/main/java/com/auth0/json/mgmt/selfserviceprofiles/Color.java
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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;

import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class SelfServiceProfile {
@JsonProperty("name")
private String name;
@JsonProperty("description")
private String description;
@JsonProperty("user_attributes")
private List<UserAttribute> userAttributes;
@JsonProperty("branding")
private Branding branding;
@JsonProperty("allowed_strategies")
private List<String> allowedStrategies;

/**
* Getter for the name of the self-service profile.
* @return the name of the self-service profile.
*/
public String getName() {
return name;
}

/**
* Setter for the name of the self-service profile.
* @param name the name of the self-service profile to set.
*/
public void setName(String name) {
this.name = name;
}

/**
* Getter for the description of the self-service profile.
* @return the description of the self-service profile.
*/
public String getDescription() {
return description;
}

/**
* Setter for the description of the self-service profile.
* @param description the description of the self-service profile to set.
*/
public void setDescription(String description) {
this.description = description;
}

/**
* Getter for the user attributes of the self-service profile.
* @return the user attributes of the self-service profile.
*/
public List<UserAttribute> getUserAttributes() {
return userAttributes;
}

/**
* Setter for the user attributes of the self-service profile.
* @param userAttributes the user attributes of the self-service profile to set.
*/
public void setUserAttributes(List<UserAttribute> userAttributes) {
this.userAttributes = userAttributes;
}

/**
* Getter for the branding of the self-service profile.
* @return the branding of the self-service profile.
*/
public Branding getBranding() {
return branding;
}

/**
* Setter for the branding of the self-service profile.
* @param branding the branding of the self-service profile to set.
*/
public void setBranding(Branding branding) {
this.branding = branding;
}

/**
* Getter for the allowed strategies of the self-service profile.
* @return the allowed strategies of the self-service profile.
*/
public List<String> getAllowedStrategies() {
return allowedStrategies;
}

/**
* Setter for the allowed strategies of the self-service profile.
* @param allowedStrategies the allowed strategies of the self-service profile to set.
*/
public void setAllowedStrategies(List<String> allowedStrategies) {
this.allowedStrategies = allowedStrategies;
}
}
Loading

0 comments on commit bd020b0

Please sign in to comment.