From d2c9b2f85e3a5acaf351080ddd4ea39d02fe8707 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Wed, 24 Sep 2025 14:22:36 +0530 Subject: [PATCH 1/6] Feat: Add Support for Self-Service-Provisioning --- .../com/auth0/client/mgmt/ManagementAPI.java | 8 + .../mgmt/UserAttributeProfilesEntity.java | 156 +++++++++ .../filter/UserAttributeProfilesFilter.java | 17 + .../ProvisioningConfig.java | 53 +++ .../SelfServiceProfile.java | 18 ++ .../SsoAccessTicketRequest.java | 18 ++ .../ListUserAttributeProfile.java | 32 ++ .../ListUserAttributeProfileTemplate.java | 32 ++ .../userAttributeProfiles/OidcMapping.java | 34 ++ .../StrategyOverridesUserAttributes.java | 73 +++++ .../StrategyOverridesUserId.java | 72 +++++ .../UserAttributeProfile.java | 84 +++++ .../UserAttributeProfileTemplate.java | 42 +++ .../UserAttributeProfileTemplateResponse.java | 71 ++++ .../userAttributeProfiles/UserAttributes.java | 174 ++++++++++ .../mgmt/userAttributeProfiles/UserId.java | 93 ++++++ .../java/com/auth0/client/MockServer.java | 23 +- .../mgmt/UserAttributeProfilesEntityTest.java | 302 ++++++++++++++++++ ...rAttributeProfileTemplateResponseTest.java | 223 +++++++++++++ .../ListUserAttributeProfileTest.java | 197 ++++++++++++ ...rAttributeProfileTemplateResponseTest.java | 139 ++++++++ .../UserAttributeProfileTest.java | 127 ++++++++ .../mgmt/user_attribute_profile.json | 30 ++ .../mgmt/user_attribute_profile_template.json | 33 ++ ...user_attribute_profile_templates_list.json | 39 +++ .../mgmt/user_attribute_profiles_list.json | 93 ++++++ 26 files changed, 2174 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java create mode 100644 src/main/java/com/auth0/client/mgmt/filter/UserAttributeProfilesFilter.java create mode 100644 src/main/java/com/auth0/json/mgmt/selfserviceprofiles/ProvisioningConfig.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/OidcMapping.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/StrategyOverridesUserAttributes.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/StrategyOverridesUserId.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfile.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributes.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserId.java create mode 100644 src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateResponseTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponseTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java create mode 100644 src/test/resources/mgmt/user_attribute_profile.json create mode 100644 src/test/resources/mgmt/user_attribute_profile_template.json create mode 100644 src/test/resources/mgmt/user_attribute_profile_templates_list.json create mode 100644 src/test/resources/mgmt/user_attribute_profiles_list.json diff --git a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java index d2ad4355a..5105aee65 100644 --- a/src/main/java/com/auth0/client/mgmt/ManagementAPI.java +++ b/src/main/java/com/auth0/client/mgmt/ManagementAPI.java @@ -415,6 +415,14 @@ public NetworkAclsEntity networkAcls() { return new NetworkAclsEntity(client, baseUrl, tokenProvider); } + /** + * Getter for the User Attribute Profiles Entity + * @return the User Attribute Profiles Entity + */ + public UserAttributeProfilesEntity userAttributeProfiles() { + return new UserAttributeProfilesEntity(client, baseUrl, tokenProvider); + } + /** * Builder for {@link ManagementAPI} API client instances. */ diff --git a/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java new file mode 100644 index 000000000..0b42bbbf3 --- /dev/null +++ b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java @@ -0,0 +1,156 @@ +package com.auth0.client.mgmt; + +import com.auth0.client.mgmt.filter.UserAttributeProfilesFilter; +import com.auth0.json.mgmt.userAttributeProfiles.*; +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; + +public class UserAttributeProfilesEntity extends BaseManagementEntity { + + private final static String ORGS_PATH = "api/v2/user-attribute-profiles"; + + UserAttributeProfilesEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { + super(client, baseUrl, tokenProvider); + } + + /** + * Get a user attribute profile by its ID. A token with {@code read:user_attribute_profiles} scope is required. + * @param id the ID of the user attribute profile to retrieve. + * @return a Request to execute. + */ + public Request get(String id) { + Asserts.assertNotNull(id, "id"); + + String url = baseUrl.newBuilder() + .addPathSegments(ORGS_PATH) + .addPathSegment(id) + .build().toString(); + + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * Get all user attribute profiles. A token with {@code read:user_attribute_profiles} scope is required. + * + * @param filter an optional pagination filter + * @return a Request to execute + * + */ + public Request getAll(UserAttributeProfilesFilter filter) { + HttpUrl.Builder builder = baseUrl.newBuilder() + .addPathSegments(ORGS_PATH); + + applyFilter(filter, builder); + + String url = builder.build().toString(); + + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + private void applyFilter(UserAttributeProfilesFilter filter, HttpUrl.Builder builder) { + if (filter != null) { + filter.getAsMap().forEach((k, v) -> builder.addQueryParameter(k, String.valueOf(v))); + } + } + + + /** + * Update a user attribute profile. A token with {@code update:user_attribute_profiles} scope is required. + * + * @param userAttributeProfile the user attribute profile to update. + * @return a Request to execute. + */ + public Request update(String id, UserAttributeProfile userAttributeProfile) { + Asserts.assertNotNull(id, "id"); + Asserts.assertNotNull(userAttributeProfile, "userAttributeProfile"); + + String url = baseUrl.newBuilder() + .addPathSegments(ORGS_PATH) + .addPathSegment(id) + .build().toString(); + + BaseRequest request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PATCH, new TypeReference() { + }); + + request.setBody(userAttributeProfile); + return request; + } + + /** + * Create a new user attribute profile. A token with {@code create:user_attribute_profiles} scope is required. + * @param userAttributeProfile the user attribute profile to create. + * @return a Request to execute. + */ + public Request create(UserAttributeProfile userAttributeProfile) { + Asserts.assertNotNull(userAttributeProfile.getName(), "name"); + Asserts.assertNotNull(userAttributeProfile.getUserAttributes(), "userAttributes"); + + String url = baseUrl.newBuilder() + .addPathSegments(ORGS_PATH) + .build().toString(); + + BaseRequest request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference() { + }); + + request.setBody(userAttributeProfile); + return request; + } + + /** + * Delete a user attribute profile by its ID. A token with {@code delete:user_attribute_profiles} scope is required. + * @param id the ID of the user attribute profile to delete. + * @return a Request to execute. + */ + public Request delete(String id) { + Asserts.assertNotNull(id, "id"); + + HttpUrl.Builder builder = baseUrl + .newBuilder() + .addPathSegments(ORGS_PATH) + .addPathSegment(id); + + String url = builder.build().toString(); + return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); + } + + /** + * Get a user attribute profile template by its ID. A token with {@code read:user_attribute_profiles} scope is required. + * @param id the ID of the user attribute profile template to retrieve. + * @return a Request to execute. + */ + public Request getTemplate(String id) { + Asserts.assertNotNull(id, "id"); + + String url = baseUrl.newBuilder() + .addPathSegments(ORGS_PATH) + .addPathSegment("templates") + .addPathSegment(id) + .build().toString(); + + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * Get all user attribute profile templates. A token with {@code read:user_attribute_profiles} scope is required. + * + * @return a Request to execute + */ + public Request getAllTemplates() { + String url = baseUrl.newBuilder() + .addPathSegments(ORGS_PATH) + .addPathSegment("templates") + .build().toString(); + + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } +} diff --git a/src/main/java/com/auth0/client/mgmt/filter/UserAttributeProfilesFilter.java b/src/main/java/com/auth0/client/mgmt/filter/UserAttributeProfilesFilter.java new file mode 100644 index 000000000..5822105d1 --- /dev/null +++ b/src/main/java/com/auth0/client/mgmt/filter/UserAttributeProfilesFilter.java @@ -0,0 +1,17 @@ +package com.auth0.client.mgmt.filter; + +public class UserAttributeProfilesFilter extends BaseFilter { + + /** + * Filter by checkpoint pagination support + * + * @param from the starting index identifier + * @param take the number of items to retrieve + * @return this filter instance + */ + public UserAttributeProfilesFilter withCheckpointPagination(String from, int take) { + parameters.put("from", from); + parameters.put("take", take); + return this; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/ProvisioningConfig.java b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/ProvisioningConfig.java new file mode 100644 index 000000000..c267e7ec4 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/ProvisioningConfig.java @@ -0,0 +1,53 @@ +package com.auth0.json.mgmt.selfserviceprofiles; + +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 ProvisioningConfig { + @JsonProperty("scopes") + private List scopes; + @JsonProperty("token_lifetime") + private int tokenLifetime; + + + /** + * Getter for the scopes. + * @return the scopes. + */ + @JsonProperty("scopes") + public List getScopes() { + return scopes; + } + + /** + * Setter for the scopes. + * @param scopes the scopes to set. + */ + @JsonProperty("scopes") + public void setScopes(List scopes) { + this.scopes = scopes; + } + + /** + * Getter for the token lifetime. + * @return the token lifetime. + */ + @JsonProperty("token_lifetime") + public int getTokenLifetime() { + return tokenLifetime; + } + + /** + * Setter for the token lifetime. + * @param tokenLifetime the token lifetime to set. + */ + @JsonProperty("token_lifetime") + public void setTokenLifetime(int tokenLifetime) { + this.tokenLifetime = tokenLifetime; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SelfServiceProfile.java b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SelfServiceProfile.java index 1a81aa81a..534f0e074 100644 --- a/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SelfServiceProfile.java +++ b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SelfServiceProfile.java @@ -20,6 +20,8 @@ public class SelfServiceProfile { private Branding branding; @JsonProperty("allowed_strategies") private List allowedStrategies; + @JsonProperty("user_attribute_profile_id") + private String userAttributeProfileId; /** * Getter for the name of the self-service profile. @@ -100,4 +102,20 @@ public List getAllowedStrategies() { public void setAllowedStrategies(List allowedStrategies) { this.allowedStrategies = allowedStrategies; } + + /** + * Getter for user attribute profile ID. + * @return the user attribute profile ID. + */ + public String getUserAttributeProfileId() { + return userAttributeProfileId; + } + + /** + * Setter for user attribute profile ID. + * @param userAttributeProfileId the user attribute profile ID to set. + */ + public void setUserAttributeProfileId(String userAttributeProfileId) { + this.userAttributeProfileId = userAttributeProfileId; + } } diff --git a/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequest.java b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequest.java index d521bec42..7b9436664 100644 --- a/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequest.java +++ b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequest.java @@ -22,6 +22,8 @@ public class SsoAccessTicketRequest { private int ttlSec; @JsonProperty("domain_aliases_config") private DomainAliasesConfig domainAliasesConfig; + @JsonProperty("provisioning_config") + private ProvisioningConfig provisioningConfig; /** * Creates a new instance. @@ -118,4 +120,20 @@ public DomainAliasesConfig getDomainAliasesConfig() { public void setDomainAliasesConfig(DomainAliasesConfig domainAliasesConfig) { this.domainAliasesConfig = domainAliasesConfig; } + + /** + * Getter for the provisioning configuration. + * @return the provisioning configuration. + */ + public ProvisioningConfig getProvisioningConfig() { + return provisioningConfig; + } + + /** + * Setter for the provisioning configuration. + * @param provisioningConfig the provisioning configuration to set. + */ + public void setProvisioningConfig(ProvisioningConfig provisioningConfig) { + this.provisioningConfig = provisioningConfig; + } } diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java new file mode 100644 index 000000000..282e08cd9 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java @@ -0,0 +1,32 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ListUserAttributeProfile { + @JsonProperty("user_attribute_profiles") + private List userAttributeProfiles; + + /** + * Gets the user attribute profiles. + * @return the user attribute profiles + */ + @JsonProperty("user_attribute_profiles") + public List getUserAttributeProfiles() { + return userAttributeProfiles; + } + + /** + * Sets the user attribute profiles. + * @param userAttributeProfiles the user attribute profiles + */ + @JsonProperty("user_attribute_profiles") + public void setUserAttributeProfiles(List userAttributeProfiles) { + this.userAttributeProfiles = userAttributeProfiles; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java new file mode 100644 index 000000000..c3515a65a --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java @@ -0,0 +1,32 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ListUserAttributeProfileTemplate { + @JsonProperty("user_attribute_profile_templates") + private List userAttributeProfileTemplateResponses; + + /** + * Gets the user attribute profile templates + * @return the user attribute profile templates + */ + @JsonProperty("user_attribute_profile_templates") + public List getUserAttributeProfileTemplates() { + return userAttributeProfileTemplateResponses; + } + + /** + * Sets the user attribute profile templates + * @param userAttributeProfileTemplateResponses the user attribute profile templates + */ + @JsonProperty("user_attribute_profile_templates") + public void setUserAttributeProfileTemplates(List userAttributeProfileTemplateResponses) { + this.userAttributeProfileTemplateResponses = userAttributeProfileTemplateResponses; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/OidcMapping.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/OidcMapping.java new file mode 100644 index 000000000..363d53d24 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/OidcMapping.java @@ -0,0 +1,34 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +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 OidcMapping { + @JsonProperty("mapping") + private String mapping; + @JsonProperty("display_name") + private String displayName; + + @JsonProperty("mapping") + public String getMapping() { + return mapping; + } + + @JsonProperty("mapping") + public void setMapping(String mapping) { + this.mapping = mapping; + } + + @JsonProperty("display_name") + public String getDisplayName() { + return displayName; + } + + @JsonProperty("display_name") + public void setDisplayName(String displayName) { + this.displayName = displayName; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/StrategyOverridesUserAttributes.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/StrategyOverridesUserAttributes.java new file mode 100644 index 000000000..221cf0288 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/StrategyOverridesUserAttributes.java @@ -0,0 +1,73 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class StrategyOverridesUserAttributes { + + @JsonProperty("oidc_mapping") + private OidcMapping oidcMapping; + @JsonProperty("saml_mapping") + private List samlMapping; + @JsonProperty("scim_mapping") + private String scimMapping; + + /** + * OIDC mapping. + * @return the OIDC mapping + */ + @JsonProperty("oidc_mapping") + public OidcMapping getOidcMapping() { + return oidcMapping; + } + + /** + * Sets the OIDC mapping. + * @param oidcMapping the OIDC mapping + */ + @JsonProperty("oidc_mapping") + public void setOidcMapping(OidcMapping oidcMapping) { + this.oidcMapping = oidcMapping; + } + + /** + * SAML mapping. + * @return the SAML mapping + */ + @JsonProperty("saml_mapping") + public List getSamlMapping() { + return samlMapping; + } + + /** + * Sets the SAML mapping. + * @param samlMapping the SAML mapping + */ + @JsonProperty("saml_mapping") + public void setSamlMapping(List samlMapping) { + this.samlMapping = samlMapping; + } + + /** + * SCIM mapping. + * @return the SCIM mapping + */ + @JsonProperty("scim_mapping") + public String getScimMapping() { + return scimMapping; + } + + /** + * Sets the SCIM mapping. + * @param scimMapping the SCIM mapping + */ + @JsonProperty("scim_mapping") + public void setScimMapping(String scimMapping) { + this.scimMapping = scimMapping; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/StrategyOverridesUserId.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/StrategyOverridesUserId.java new file mode 100644 index 000000000..9e2543cd5 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/StrategyOverridesUserId.java @@ -0,0 +1,72 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class StrategyOverridesUserId { + @JsonProperty("oidc_mapping") + private String oidcMapping; + @JsonProperty("saml_mapping") + private List samlMapping; + @JsonProperty("scim_mapping") + private String scimMapping; + + /** + * OIDC mapping. + * @return the OIDC mapping + */ + @JsonProperty("oidc_mapping") + public String getOidcMapping() { + return oidcMapping; + } + + /** + * Sets the OIDC mapping. + * @param oidcMapping the OIDC mapping + */ + @JsonProperty("oidc_mapping") + public void setOidcMapping(String oidcMapping) { + this.oidcMapping = oidcMapping; + } + + /** + * SAML mapping. + * @return the SAML mapping + */ + @JsonProperty("saml_mapping") + public List getSamlMapping() { + return samlMapping; + } + + /** + * Sets the SAML mapping. + * @param samlMapping the SAML mapping + */ + @JsonProperty("saml_mapping") + public void setSamlMapping(List samlMapping) { + this.samlMapping = samlMapping; + } + + /** + * SCIM mapping. + * @return the SCIM mapping + */ + @JsonProperty("scim_mapping") + public String getScimMapping() { + return scimMapping; + } + + /** + * Sets the SCIM mapping. + * @param scimMapping the SCIM mapping + */ + @JsonProperty("scim_mapping") + public void setScimMapping(String scimMapping) { + this.scimMapping = scimMapping; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfile.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfile.java new file mode 100644 index 000000000..f0e9d5587 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfile.java @@ -0,0 +1,84 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Map; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserAttributeProfile { + + @JsonProperty("id") + private String id; + @JsonProperty("name") + private String name; + @JsonProperty("user_id") + private UserId userId; + @JsonProperty("user_attributes") + private Map userAttributes; + + /** + * Gets the user attribute profile ID. + * @return the user attribute profile ID + */ + @JsonProperty("id") + public String getId() { + return id; + } + + /** + * Sets the user attribute profile ID. + * @return the user attribute profile ID + */ + @JsonProperty("name") + public String getName() { + return name; + } + + /** + * Sets the user attribute profile name. + * @param name the user attribute profile name + */ + @JsonProperty("name") + public void setName(String name) { + this.name = name; + } + + /** + * Gets the user ID configuration. + * @return the user ID configuration + */ + @JsonProperty("user_id") + public UserId getUserId() { + return userId; + } + + /** + * Sets the user ID configuration. + * @param userId the user ID configuration + */ + @JsonProperty("user_id") + public void setUserId(UserId userId) { + this.userId = userId; + } + + /** + * Gets the user attributes configuration. + * @return the user attributes configuration + */ + @JsonProperty("user_attributes") + public Map getUserAttributes() { + return userAttributes; + } + + /** + * Sets the user attributes configuration. + * @param userAttributes the user attributes configuration + */ + @JsonProperty("user_attributes") + public void setUserAttributes(Map userAttributes) { + this.userAttributes = userAttributes; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java new file mode 100644 index 000000000..a2a3247a6 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java @@ -0,0 +1,42 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Map; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserAttributeProfileTemplate { + @JsonProperty("name") + private String name; + @JsonProperty("user_id") + private UserId userId; + @JsonProperty("user_attributes") + private Map userAttributes; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public UserId getUserId() { + return userId; + } + + public void setUserId(UserId userId) { + this.userId = userId; + } + + public Map getUserAttributes() { + return userAttributes; + } + + public void setUserAttributes(Map userAttributes) { + this.userAttributes = userAttributes; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java new file mode 100644 index 000000000..501ea5da3 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java @@ -0,0 +1,71 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Class that represents a User Attribute Profile Template object. Related to + * the {@link com.auth0.client.mgmt.UserAttributeProfilesEntity} entity. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserAttributeProfileTemplateResponse { + + @JsonProperty("id") + private String id; + @JsonProperty("display_name") + private String displayName; + @JsonProperty("template") + private UserAttributeProfileTemplate template; + + /** + * Getter for the template ID. + * + * @return the template ID. + */ + @JsonProperty("id") + public String getId() { + return id; + } + + /** + * Getter for the display name. + * + * @return the display name. + */ + @JsonProperty("display_name") + public String getDisplayName() { + return displayName; + } + + /** + * Setter for the display name. + * + * @param displayName the display name to set. + */ + @JsonProperty("display_name") + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * Getter for the template. + * + * @return the template. + */ + @JsonProperty("template") + public UserAttributeProfileTemplate getTemplate() { + return template; + } + + /** + * Setter for the template. + * + * @param template the template to set. + */ + @JsonProperty("template") + public void setTemplate(UserAttributeProfileTemplate template) { + this.template = template; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributes.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributes.java new file mode 100644 index 000000000..cd1276084 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributes.java @@ -0,0 +1,174 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; +import java.util.Map; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserAttributes { + @JsonProperty("description") + private String description; + @JsonProperty("label") + private String label; + @JsonProperty("profile_required") + private boolean profileRequired; + @JsonProperty("auth0_mapping") + private String auth0Mapping; + @JsonProperty("oidc_mapping") + private OidcMapping oidcMapping; + @JsonProperty("saml_mapping") + private List samlMapping; + @JsonProperty("scim_mapping") + private String scimMapping; + @JsonProperty("strategy_overrides") + private Map strategyOverrides; + + /** + * Description of the user attribute. + * @return the description + */ + @JsonProperty("description") + public String getDescription() { + return description; + } + + /** + * Sets the description of the user attribute. + * @param description + */ + @JsonProperty("description") + public void setDescription(String description) { + this.description = description; + } + + /** + * Label of the user attribute. + * @return the label + */ + @JsonProperty("label") + public String getLabel() { + return label; + } + + /** + * Sets the label of the user attribute. + * @param label the label + */ + @JsonProperty("label") + public void setLabel(String label) { + this.label = label; + } + + /** + * Indicates if the user attribute is required in the profile. + * @return true if the user attribute is required in the profile, false otherwise + */ + @JsonProperty("profile_required") + public boolean isProfileRequired() { + return profileRequired; + } + + /** + * Sets if the user attribute is required in the profile. + * @param profileRequired true if the user attribute is required in the profile, false otherwise + */ + @JsonProperty("profile_required") + public void setProfileRequired(boolean profileRequired) { + this.profileRequired = profileRequired; + } + + /** + * Auth0 mapping. + * @return the Auth0 mapping + */ + @JsonProperty("auth0_mapping") + public String getAuth0Mapping() { + return auth0Mapping; + } + + /** + * Sets the Auth0 mapping. + * @param auth0Mapping the Auth0 mapping + */ + @JsonProperty("auth0_mapping") + public void setAuth0Mapping(String auth0Mapping) { + this.auth0Mapping = auth0Mapping; + } + + /** + * OIDC mapping. + * @return the OIDC mapping + */ + @JsonProperty("oidc_mapping") + public OidcMapping getOidcMapping() { + return oidcMapping; + } + + /** + * Sets the OIDC mapping. + * @param oidcMapping the OIDC mapping + */ + @JsonProperty("oidc_mapping") + public void setOidcMapping(OidcMapping oidcMapping) { + this.oidcMapping = oidcMapping; + } + + /** + * SAML mapping. + * @return the SAML mapping + */ + @JsonProperty("saml_mapping") + public List getSamlMapping() { + return samlMapping; + } + + /** + * Sets the SAML mapping. + * @param samlMapping the SAML mapping + */ + @JsonProperty("saml_mapping") + public void setSamlMapping(List samlMapping) { + this.samlMapping = samlMapping; + } + + /** + * SCIM mapping. + * @return the SCIM mapping + */ + @JsonProperty("scim_mapping") + public String getScimMapping() { + return scimMapping; + } + + /** + * Sets the SCIM mapping. + * @param scimMapping the SCIM mapping + */ + @JsonProperty("scim_mapping") + public void setScimMapping(String scimMapping) { + this.scimMapping = scimMapping; + } + + /** + * Strategy overrides mapping. + * @return the strategy overrides mapping + */ + @JsonProperty("strategy_overrides") + public Map getStrategyOverrides() { + return strategyOverrides; + } + + /** + * Sets the strategy overrides mapping. + * @param strategyOverrides the strategy overrides mapping + */ + @JsonProperty("strategy_overrides") + public void setStrategyOverrides(Map strategyOverrides) { + this.strategyOverrides = strategyOverrides; + } +} + diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserId.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserId.java new file mode 100644 index 000000000..41391d4e2 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserId.java @@ -0,0 +1,93 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; +import java.util.Map; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserId { + @JsonProperty("oidc_mapping") + private String oidcMapping; + @JsonProperty("saml_mapping") + private List samlMapping; + @JsonProperty("scim_mapping") + private String scimMapping; + @JsonProperty("strategy_overrides") + private Map strategyOverrides; + + /** + * OIDC mapping. + * @return the OIDC mapping + */ + @JsonProperty("oidc_mapping") + public String getOidcMapping() { + return oidcMapping; + } + + /** + * Sets the OIDC mapping. + * @param oidcMapping the OIDC mapping + */ + @JsonProperty("oidc_mapping") + public void setOidcMapping(String oidcMapping) { + this.oidcMapping = oidcMapping; + } + + /** + * SAML mapping. + * @return the SAML mapping + */ + @JsonProperty("saml_mapping") + public List getSamlMapping() { + return samlMapping; + } + + /** + * Sets the SAML mapping. + * @param samlMapping the SAML mapping + */ + @JsonProperty("saml_mapping") + public void setSamlMapping(List samlMapping) { + this.samlMapping = samlMapping; + } + + /** + * SCIM mapping. + * @return the SCIM mapping + */ + @JsonProperty("scim_mapping") + public String getScimMapping() { + return scimMapping; + } + + /** + * Sets the SCIM mapping. + * @param scimMapping the SCIM mapping + */ + @JsonProperty("scim_mapping") + public void setScimMapping(String scimMapping) { + this.scimMapping = scimMapping; + } + + /** + * Strategy overrides mapping. + * @return the strategy overrides mapping + */ + @JsonProperty("strategy_overrides") + public Map getStrategyOverrides() { + return strategyOverrides; + } + + /** + * Sets the strategy overrides mapping. + * @param strategyOverrides the strategy overrides mapping + */ + @JsonProperty("strategy_overrides") + public void setStrategyOverrides(Map strategyOverrides) { + this.strategyOverrides = strategyOverrides; + } +} diff --git a/src/test/java/com/auth0/client/MockServer.java b/src/test/java/com/auth0/client/MockServer.java index 7b86e527b..7dbe2217e 100644 --- a/src/test/java/com/auth0/client/MockServer.java +++ b/src/test/java/com/auth0/client/MockServer.java @@ -122,6 +122,10 @@ public class MockServer { public static final String MGMT_JOB_ERROR_DETAILS = "src/test/resources/mgmt/job_error_details.json"; public static final String MGMT_NETWORK_ACLS_LIST = "src/test/resources/mgmt/network_acls_list.json"; public static final String MGMT_NETWORK_ACLS = "src/test/resources/mgmt/network_acls.json"; + public static final String MGMT_USER_ATTRIBUTE_PROFILES_LIST = "src/test/resources/mgmt/user_attribute_profiles_list.json"; + public static final String MGMT_USER_ATTRIBUTE_PROFILE = "src/test/resources/mgmt/user_attribute_profile.json"; + public static final String MGMT_USER_ATTRIBUTE_PROFILE_TEMPLATE = "src/test/resources/mgmt/user_attribute_profile_template.json"; + public static final String MGMT_USER_ATTRIBUTE_PROFILE_TEMPLATES_LIST = "src/test/resources/mgmt/user_attribute_profile_templates_list.json"; public static final String MULTIPART_SAMPLE = "src/test/resources/mgmt/multipart_sample.json"; public static final String PASSWORDLESS_EMAIL_RESPONSE = "src/test/resources/auth/passwordless_email.json"; public static final String PASSWORDLESS_SMS_RESPONSE = "src/test/resources/auth/passwordless_sms.json"; @@ -207,9 +211,9 @@ public void jsonResponse(String path, int statusCode) throws IOException { public void noContentResponse() { MockResponse response = new MockResponse() - .setResponseCode(204) - .addHeader("Content-Type", "application/json") - .setBody(""); + .setResponseCode(204) + .addHeader("Content-Type", "application/json") + .setBody(""); server.enqueue(response); } @@ -229,7 +233,7 @@ public void rateLimitReachedResponse(long limit, long remaining, long reset, Str response.addHeader("x-ratelimit-reset", String.valueOf(reset)); } if (path != null) { - response + response .addHeader("Content-Type", "application/json") .setBody(readTextFile(path)); } @@ -237,11 +241,12 @@ public void rateLimitReachedResponse(long limit, long remaining, long reset, Str } public void rateLimitReachedResponse(long limit, long remaining, long reset, - String clientQuotaLimit, String organizationQuotaLimit, long retryAfter) throws IOException { + String clientQuotaLimit, String organizationQuotaLimit, long retryAfter) throws IOException { rateLimitReachedResponse(limit, remaining, reset, null, clientQuotaLimit, organizationQuotaLimit, retryAfter); } - public void rateLimitReachedResponse(long limit, long remaining, long reset, String path, String clientQuotaLimit, String organizationQuotaLimit, long retryAfter) throws IOException { + public void rateLimitReachedResponse(long limit, long remaining, long reset, String path, String clientQuotaLimit, + String organizationQuotaLimit, long retryAfter) throws IOException { MockResponse response = new MockResponse().setResponseCode(429); if (limit != -1) { response.addHeader("x-ratelimit-limit", String.valueOf(limit)); @@ -258,13 +263,13 @@ public void rateLimitReachedResponse(long limit, long remaining, long reset, Str if (organizationQuotaLimit != null) { response.addHeader("auth0-organization-quota-limit", organizationQuotaLimit); } - if(retryAfter != -1) { + if (retryAfter != -1) { response.addHeader("retry-after", String.valueOf(retryAfter)); } if (path != null) { response - .addHeader("Content-Type", "application/json") - .setBody(readTextFile(path)); + .addHeader("Content-Type", "application/json") + .setBody(readTextFile(path)); } server.enqueue(response); } diff --git a/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java b/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java new file mode 100644 index 000000000..b27a221e8 --- /dev/null +++ b/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java @@ -0,0 +1,302 @@ +package com.auth0.client.mgmt; + +import com.auth0.client.MockServer; +import com.auth0.client.mgmt.filter.UserAttributeProfilesFilter; +import com.auth0.json.mgmt.userAttributeProfiles.*; +import com.auth0.net.Request; +import com.auth0.net.client.HttpMethod; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static com.auth0.AssertsUtil.verifyThrows; +import static com.auth0.client.MockServer.*; +import static com.auth0.client.RecordedRequestMatcher.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class UserAttributeProfilesEntityTest extends BaseMgmtEntityTest { + + // User Attribute Profiles entity tests + + @Test + public void shouldThrowOnGetUserAttributeProfileWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.userAttributeProfiles().get(null), + "'id' cannot be null!"); + } + + @Test + public void shouldGetUserAttributeProfile() throws Exception { + Request request = api.userAttributeProfiles().get("uap_1234567890"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILE, 200); + UserAttributeProfile response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/user-attribute-profiles/uap_1234567890")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + assertThat(response.getId(), is("uap_1234567890")); + assertThat(response.getName(), is("This is just a test")); + } + + @Test + public void shouldGetAllUserAttributeProfilesWithoutFilter() throws Exception { + Request request = api.userAttributeProfiles().getAll(null); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILES_LIST, 200); + ListUserAttributeProfile response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/user-attribute-profiles")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + assertThat(response.getUserAttributeProfiles(), hasSize(3)); + } + + @Test + public void shouldGetAllUserAttributeProfilesWithFilter() throws Exception { + UserAttributeProfilesFilter filter = new UserAttributeProfilesFilter() + .withCheckpointPagination("uap_1234567890", 10); + + Request request = api.userAttributeProfiles().getAll(filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILES_LIST, 200); + ListUserAttributeProfile response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/user-attribute-profiles")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, hasQueryParameter("from", "uap_1234567890")); + assertThat(recordedRequest, hasQueryParameter("take", "10")); + + assertThat(response, is(notNullValue())); + assertThat(response.getUserAttributeProfiles(), hasSize(3)); + } + + @Test + public void shouldThrowOnUpdateUserAttributeProfileWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.userAttributeProfiles().update(null, new UserAttributeProfile()), + "'id' cannot be null!"); + } + + @Test + public void shouldThrowOnUpdateUserAttributeProfileWithNullProfile() { + verifyThrows(IllegalArgumentException.class, + () -> api.userAttributeProfiles().update("uap_1234567890", null), + "'userAttributeProfile' cannot be null!"); + } + + @Test + public void shouldUpdateUserAttributeProfile() throws Exception { + UserAttributeProfile profileToUpdate = new UserAttributeProfile(); + profileToUpdate.setName("This is just a test"); + + UserId userId = new UserId(); + userId.setOidcMapping("sub"); + userId.setSamlMapping(Arrays.asList("urn:oid:0.9.10.10.100.1.1")); // Replace List.of() with Arrays.asList() + userId.setScimMapping("userName"); + profileToUpdate.setUserId(userId); + + Map userAttributes = new HashMap<>(); + UserAttributes usernameAttr = new UserAttributes(); + usernameAttr.setLabel("test User"); + usernameAttr.setDescription("This is just a test"); + + OidcMapping oidcMapping = new OidcMapping(); + oidcMapping.setMapping("preferred_username"); + oidcMapping.setDisplayName("UserName"); + usernameAttr.setOidcMapping(oidcMapping); + + usernameAttr.setSamlMapping(Arrays.asList("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")); // Replace List.of() with Arrays.asList() + usernameAttr.setScimMapping("displayName"); + usernameAttr.setAuth0Mapping("testUser"); + usernameAttr.setProfileRequired(false); + + StrategyOverridesUserAttributes strategyOverridesUserAttributes = new StrategyOverridesUserAttributes(); + strategyOverridesUserAttributes.setScimMapping("name.givenName"); + Map strategyOverridesMap = new HashMap<>(); + strategyOverridesMap.put("oidc", strategyOverridesUserAttributes); + usernameAttr.setStrategyOverrides(strategyOverridesMap); + + userAttributes.put("username", usernameAttr); + profileToUpdate.setUserAttributes(userAttributes); + + Request request = api.userAttributeProfiles().update("uap_1csqEmz4TE2P1o7izaATmb", profileToUpdate); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILE, 200); + UserAttributeProfile response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, + hasMethodAndPath(HttpMethod.PATCH, "/api/v2/user-attribute-profiles/uap_1csqEmz4TE2P1o7izaATmb")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + Map body = bodyFromRequest(recordedRequest); + assertThat(body, hasEntry("name", "This is just a test")); + assertThat(body, hasEntry(is("user_id"), is(notNullValue()))); + assertThat(body, hasEntry(is("user_attributes"), is(notNullValue()))); + + assertThat(response, is(notNullValue())); + } + + @Test + public void shouldThrowOnCreateUserAttributeProfileWithNullName() { + UserAttributeProfile profile = new UserAttributeProfile(); + profile.setName(null); + Map userAttributes = new HashMap<>(); + profile.setUserAttributes(userAttributes); + + verifyThrows(IllegalArgumentException.class, + () -> api.userAttributeProfiles().create(profile), + "'name' cannot be null!"); + } + + @Test + public void shouldThrowOnCreateUserAttributeProfileWithNullUserAttributes() { + UserAttributeProfile profile = new UserAttributeProfile(); + profile.setName("Test Profile"); + profile.setUserAttributes(null); + + verifyThrows(IllegalArgumentException.class, + () -> api.userAttributeProfiles().create(profile), + "'userAttributes' cannot be null!"); + } + + @Test + public void shouldCreateUserAttributeProfile() throws Exception { + UserAttributeProfile profileToCreate = new UserAttributeProfile(); + profileToCreate.setName("This is just a test"); + + UserId userId = new UserId(); + userId.setOidcMapping("sub"); + userId.setSamlMapping(Arrays.asList("urn:oid:0.9.10.10.100.1.1")); + userId.setScimMapping("userName"); + profileToCreate.setUserId(userId); + + Map userAttributes = new HashMap<>(); + UserAttributes usernameAttr = new UserAttributes(); + usernameAttr.setLabel("test User"); + usernameAttr.setDescription("This is just a test"); + + OidcMapping oidcMapping = new OidcMapping(); + oidcMapping.setMapping("preferred_username"); + oidcMapping.setDisplayName("UserName"); + usernameAttr.setOidcMapping(oidcMapping); + + usernameAttr.setSamlMapping(Arrays.asList("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")); + usernameAttr.setScimMapping("displayName"); + usernameAttr.setAuth0Mapping("testUser"); + usernameAttr.setProfileRequired(false); + + StrategyOverridesUserAttributes strategyOverridesUserAttributes = new StrategyOverridesUserAttributes(); + strategyOverridesUserAttributes.setScimMapping("name.givenName"); + Map strategyOverridesMap = new HashMap<>(); + strategyOverridesMap.put("oidc", strategyOverridesUserAttributes); + usernameAttr.setStrategyOverrides(strategyOverridesMap); + + userAttributes.put("username", usernameAttr); + profileToCreate.setUserAttributes(userAttributes); + + Request request = api.userAttributeProfiles().create(profileToCreate); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILE, 201); + UserAttributeProfile response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/api/v2/user-attribute-profiles")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + Map body = bodyFromRequest(recordedRequest); + assertThat(body, aMapWithSize(3)); + assertThat(body, hasEntry("name", "This is just a test")); + assertThat(body, hasEntry(is("user_id"), is(notNullValue()))); + assertThat(body, hasEntry(is("user_attributes"), is(notNullValue()))); + + assertThat(response, is(notNullValue())); + } + + @Test + public void shouldThrowOnDeleteUserAttributeProfileWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.userAttributeProfiles().delete(null), + "'id' cannot be null!"); + } + + @Test + public void shouldDeleteUserAttributeProfile() throws Exception { + Request request = api.userAttributeProfiles().delete("uap_1234567890"); + assertThat(request, is(notNullValue())); + + server.emptyResponse(204); + request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, + hasMethodAndPath(HttpMethod.DELETE, "/api/v2/user-attribute-profiles/uap_1234567890")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + } + + // User Attribute Profile Templates tests + + @Test + public void shouldThrowOnGetUserAttributeProfileTemplateWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.userAttributeProfiles().getTemplate(null), + "'id' cannot be null!"); + } + + @Test + public void shouldGetUserAttributeProfileTemplate() throws Exception { + Request request = api.userAttributeProfiles().getTemplate("auth0-generic"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILE_TEMPLATE, 200); + UserAttributeProfileTemplate response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, + hasMethodAndPath(HttpMethod.GET, "/api/v2/user-attribute-profiles/templates/auth0-generic")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + assertThat(response.getId(), is("auth0-generic")); + assertThat(response.getDisplayName(), is("A standard user attribute profile template")); + } + + @Test + public void shouldGetAllUserAttributeProfileTemplates() throws Exception { + Request request = api.userAttributeProfiles().getAllTemplates(); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILE_TEMPLATES_LIST, 200); + ListUserAttributeProfileTemplate response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/user-attribute-profiles/templates")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + assertThat(response.getUserAttributeProfileTemplates(), hasSize(1)); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateResponseTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateResponseTest.java new file mode 100644 index 000000000..53d558032 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateResponseTest.java @@ -0,0 +1,223 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.auth0.json.JsonMatcher; +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.hasKey; + +public class ListUserAttributeProfileTemplateTest extends JsonTest { + + private static final String jsonWithTemplates = "{\n" + + " \"user_attribute_profile_templates\": [\n" + + " {\n" + + " \"id\": \"auth0-generic\",\n" + + " \"display_name\": \"Auth0 Generic User Attribute Profile Template\",\n" + + " \"template\": {\n" + + " \"name\": \"This is just a test\",\n" + + " \"user_id\": {\n" + + " \"oidc_mapping\": \"sub\",\n" + + " \"saml_mapping\": [\n" + + " \"urn:oid:0.9.10.10.100.1.1\"\n" + + " ],\n" + + " \"scim_mapping\": \"userName\"\n" + + " },\n" + + " \"user_attributes\": {\n" + + " \"username\": {\n" + + " \"label\": \"test User\",\n" + + " \"description\": \"This is just a test\",\n" + + " \"oidc_mapping\": {\n" + + " \"mapping\": \"preferred_username\",\n" + + " \"display_name\": \"UserName\"\n" + + " },\n" + + " \"saml_mapping\": [\n" + + " \"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\"\n" + + " ],\n" + + " \"scim_mapping\": \"displayName\",\n" + + " \"auth0_mapping\": \"testUser\",\n" + + " \"profile_required\": false,\n" + + " \"strategy_overrides\": {\n" + + " \"oidc\": {\n" + + " \"scim_mapping\": \"name.givenName\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " ]\n" + + "}"; + + private static final String emptyListJson = "{\n" + + " \"user_attribute_profile_templates\": []\n" + + "}"; + + @Test + public void shouldSerialize() throws Exception { + ListUserAttributeProfileTemplate listTemplates = new ListUserAttributeProfileTemplate(); + + // Create first template + UserAttributeProfileTemplate template1 = new UserAttributeProfileTemplate(); + template1.setDisplayName("Test Template 1"); + + // Create nested UserAttributeProfile for template1 + UserAttributeProfile userProfile1 = new UserAttributeProfile(); + userProfile1.setName("Profile 1"); + template1.setTemplate(userProfile1); + + // Create second template + UserAttributeProfileTemplate template2 = new UserAttributeProfileTemplate(); + template2.setDisplayName("Test Template 2"); + + listTemplates.setUserAttributeProfileTemplates(Arrays.asList(template1, template2)); + + String serialized = toJSON(listTemplates); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, JsonMatcher.hasEntry("user_attribute_profile_templates", listTemplates)); + } + + @Test + public void shouldDeserialize() throws Exception { + ListUserAttributeProfileTemplate listTemplates = fromJSON(jsonWithTemplates, + ListUserAttributeProfileTemplate.class); + + assertThat(listTemplates, is(notNullValue())); + assertThat(listTemplates.getUserAttributeProfileTemplates(), is(notNullValue())); + assertThat(listTemplates.getUserAttributeProfileTemplates(), hasSize(1)); + } + + @Test + public void shouldDeserializeWithFullTemplateDetails() throws Exception { + ListUserAttributeProfileTemplate listTemplates = fromJSON(jsonWithTemplates, + ListUserAttributeProfileTemplate.class); + + assertThat(listTemplates, is(notNullValue())); + List templates = listTemplates.getUserAttributeProfileTemplates(); + assertThat(templates, hasSize(1)); + + // Test template details + UserAttributeProfileTemplate template = templates.get(0); + assertThat(template.getId(), is("auth0-generic")); + assertThat(template.getDisplayName(), is("Auth0 Generic User Attribute Profile Template")); + + // Test nested UserAttributeProfile template + UserAttributeProfile userAttributeProfile = template.getTemplate(); + assertThat(userAttributeProfile, is(notNullValue())); + assertThat(userAttributeProfile.getName(), is("This is just a test")); + + // Test UserId in nested template + UserId userId = userAttributeProfile.getUserId(); + assertThat(userId, is(notNullValue())); + assertThat(userId.getOidcMapping(), is("sub")); + assertThat(userId.getSamlMapping(), hasSize(1)); + assertThat(userId.getSamlMapping().get(0), is("urn:oid:0.9.10.10.100.1.1")); + assertThat(userId.getScimMapping(), is("userName")); + + // Test UserAttributes in nested template + Map userAttributes = userAttributeProfile.getUserAttributes(); + assertThat(userAttributes, is(notNullValue())); + assertThat(userAttributes, hasKey("username")); + + UserAttributes usernameAttr = userAttributes.get("username"); + assertThat(usernameAttr, is(notNullValue())); + assertThat(usernameAttr.getLabel(), is("test User")); + assertThat(usernameAttr.getDescription(), is("This is just a test")); + assertThat(usernameAttr.getAuth0Mapping(), is("testUser")); + assertThat(usernameAttr.isProfileRequired(), is(false)); + + // Test OIDC mapping in nested template + assertThat(usernameAttr.getOidcMapping(), is(notNullValue())); + assertThat(usernameAttr.getOidcMapping().getMapping(), is("preferred_username")); + assertThat(usernameAttr.getOidcMapping().getDisplayName(), is("UserName")); + + // Test SAML mapping in nested template + assertThat(usernameAttr.getSamlMapping(), hasSize(1)); + assertThat(usernameAttr.getSamlMapping().get(0), + is("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")); + + // Test SCIM mapping in nested template + assertThat(usernameAttr.getScimMapping(), is("displayName")); + + // Test strategy overrides in nested template + assertThat(usernameAttr.getStrategyOverrides(), is(notNullValue())); + assertThat(usernameAttr.getStrategyOverrides(), hasKey("oidc")); + } + + @Test + public void shouldDeserializeEmptyList() throws Exception { + ListUserAttributeProfileTemplate listTemplates = fromJSON(emptyListJson, + ListUserAttributeProfileTemplate.class); + + assertThat(listTemplates, is(notNullValue())); + assertThat(listTemplates.getUserAttributeProfileTemplates(), is(notNullValue())); + assertThat(listTemplates.getUserAttributeProfileTemplates(), hasSize(0)); + } + + @Test + public void shouldHandleNullList() throws Exception { + ListUserAttributeProfileTemplate listTemplates = new ListUserAttributeProfileTemplate(); + listTemplates.setUserAttributeProfileTemplates(null); + + String serialized = toJSON(listTemplates); + assertThat(serialized, is(notNullValue())); + } + + @Test + public void shouldHandleTemplatesWithoutNestedProfile() throws Exception { + String minimalJson = "{\n" + + " \"user_attribute_profile_templates\": [\n" + + " {\n" + + " \"id\": \"minimal-template\",\n" + + " \"display_name\": \"Minimal Template\"\n" + + " }\n" + + " ]\n" + + "}"; + + ListUserAttributeProfileTemplate listTemplates = fromJSON(minimalJson, ListUserAttributeProfileTemplate.class); + + assertThat(listTemplates, is(notNullValue())); + List templates = listTemplates.getUserAttributeProfileTemplates(); + assertThat(templates, hasSize(1)); + + UserAttributeProfileTemplate template = templates.get(0); + assertThat(template.getId(), is("minimal-template")); + assertThat(template.getDisplayName(), is("Minimal Template")); + } + + @Test + public void shouldSerializeMultipleTemplates() throws Exception { + ListUserAttributeProfileTemplate listTemplates = new ListUserAttributeProfileTemplate(); + + // Create multiple templates with different structures + UserAttributeProfileTemplate template1 = new UserAttributeProfileTemplate(); + template1.setDisplayName("Template 1"); + + UserAttributeProfile profile1 = new UserAttributeProfile(); + profile1.setName("Profile 1"); + Map attrs1 = new HashMap<>(); + UserAttributes userAttr1 = new UserAttributes(); + userAttr1.setLabel("User 1"); + userAttr1.setDescription("Description 1"); + attrs1.put("user1", userAttr1); + profile1.setUserAttributes(attrs1); + template1.setTemplate(profile1); + + UserAttributeProfileTemplate template2 = new UserAttributeProfileTemplate(); + template2.setDisplayName("Template 2"); + + listTemplates.setUserAttributeProfileTemplates(Arrays.asList(template1, template2)); + + String serialized = toJSON(listTemplates); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, JsonMatcher.hasEntry("user_attribute_profile_templates", listTemplates)); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java new file mode 100644 index 000000000..bf1671209 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java @@ -0,0 +1,197 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.auth0.json.JsonMatcher; +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.hasKey; + +public class ListUserAttributeProfileTest extends JsonTest { + + private static final String jsonWithProfiles = "{\n" + + " \"user_attribute_profiles\": [\n" + + " {\n" + + " \"id\": \"uap_1234567890\",\n" + + " \"name\": \"This is just a test\",\n" + + " \"user_id\": {\n" + + " \"oidc_mapping\": \"sub\",\n" + + " \"saml_mapping\": [\n" + + " \"urn:oid:0.9.10.10.100.1.1\"\n" + + " ],\n" + + " \"scim_mapping\": \"userName\"\n" + + " },\n" + + " \"user_attributes\": {\n" + + " \"username\": {\n" + + " \"label\": \"test User\",\n" + + " \"description\": \"This is just a test\",\n" + + " \"oidc_mapping\": {\n" + + " \"mapping\": \"preferred_username\",\n" + + " \"display_name\": \"UserName\"\n" + + " },\n" + + " \"saml_mapping\":[\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\"],\n" + + " \"scim_mapping\":\"displayName\",\n" + + " \"auth0_mapping\": \"testUser\",\n" + + " \"profile_required\": false,\n" + + " \"strategy_overrides\": {\n" + + " \"oidc\": {\n" + + " \"scim_mapping\":\"name.givenName\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": \"uap_123456789012345\",\n" + + " \"name\": \"Updated Test Organization\",\n" + + " \"user_id\": {\n" + + " \"oidc_mapping\": \"sub\",\n" + + " \"saml_mapping\": [\n" + + " \"urn:oid:0.9.10.10.100.1.1\"\n" + + " ],\n" + + " \"scim_mapping\": \"userName\"\n" + + " },\n" + + " \"user_attributes\": {\n" + + " \"username\": {\n" + + " \"label\": \"test User\",\n" + + " \"description\": \"This is just a test\",\n" + + " \"oidc_mapping\": {\n" + + " \"mapping\": \"preferred_username\",\n" + + " \"display_name\": \"Display Name\"\n" + + " },\n" + + " \"auth0_mapping\": \"testUser\",\n" + + " \"profile_required\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": \"uap_1234\",\n" + + " \"name\": \"This is another test\",\n" + + " \"user_id\": {\n" + + " \"oidc_mapping\": \"sub\",\n" + + " \"saml_mapping\": [\n" + + " \"urn:oid:0.9.10.10.100.1.1\"\n" + + " ],\n" + + " \"scim_mapping\": \"userName\",\n" + + " \"strategy_overrides\": {\n" + + " \"google-apps\": {\n" + + " \"oidc_mapping\": \"email\"\n" + + " }\n" + + " }\n" + + " },\n" + + " \"user_attributes\": {\n" + + " \"username\": {\n" + + " \"label\": \"test User\",\n" + + " \"description\": \"This is just a test\",\n" + + " \"oidc_mapping\": {\n" + + " \"mapping\": \"preferred_username\",\n" + + " \"display_name\": \"Display Name\"\n" + + " },\n" + + " \"auth0_mapping\": \"testUser\",\n" + + " \"profile_required\": false,\n" + + " \"strategy_overrides\": {\n" + + " \"okta\": {\n" + + " \"oidc_mapping\": {\n" + + " \"mapping\": \"${context.userinfo.groups}\",\n" + + " \"display_name\": \"groups\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " ]\n" + + "}"; + + private static final String emptyListJson = "{\n" + + " \"user_attribute_profiles\": []\n" + + "}"; + + @Test + public void shouldSerialize() throws Exception { + ListUserAttributeProfile listProfiles = new ListUserAttributeProfile(); + + // Create first profile + UserAttributeProfile profile1 = new UserAttributeProfile(); + profile1.setName("Test Profile 1"); + + // Create second profile + UserAttributeProfile profile2 = new UserAttributeProfile(); + profile2.setName("Test Profile 2"); + + listProfiles.setUserAttributeProfiles(Arrays.asList(profile1, profile2)); + + String serialized = toJSON(listProfiles); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, JsonMatcher.hasEntry("user_attribute_profiles", listProfiles)); + } + + @Test + public void shouldDeserialize() throws Exception { + ListUserAttributeProfile listProfiles = fromJSON(jsonWithProfiles, ListUserAttributeProfile.class); + + assertThat(listProfiles, is(notNullValue())); + assertThat(listProfiles.getUserAttributeProfiles(), is(notNullValue())); + assertThat(listProfiles.getUserAttributeProfiles(), hasSize(3)); + + List profiles = listProfiles.getUserAttributeProfiles(); + + // Test first profile - full details + UserAttributeProfile firstProfile = profiles.get(0); + assertThat(firstProfile.getId(), is("uap_1234567890")); + assertThat(firstProfile.getName(), is("This is just a test")); + + // Test UserId of first profile + UserId userId = firstProfile.getUserId(); + assertThat(userId, is(notNullValue())); + assertThat(userId.getOidcMapping(), is("sub")); + assertThat(userId.getSamlMapping(), hasSize(1)); + assertThat(userId.getSamlMapping().get(0), is("urn:oid:0.9.10.10.100.1.1")); + assertThat(userId.getScimMapping(), is("userName")); + + // Test UserAttributes of first profile + Map userAttributes = firstProfile.getUserAttributes(); + assertThat(userAttributes, is(notNullValue())); + assertThat(userAttributes, hasKey("username")); + + UserAttributes usernameAttr = userAttributes.get("username"); + assertThat(usernameAttr.getLabel(), is("test User")); + assertThat(usernameAttr.getDescription(), is("This is just a test")); + assertThat(usernameAttr.getAuth0Mapping(), is("testUser")); + assertThat(usernameAttr.isProfileRequired(), is(false)); + + // Test strategy overrides in first profile + assertThat(usernameAttr.getStrategyOverrides(), is(notNullValue())); + assertThat(usernameAttr.getStrategyOverrides(), hasKey("oidc")); + + // Test second profile - basic details + UserAttributeProfile secondProfile = profiles.get(1); + assertThat(secondProfile.getId(), is("uap_123456789012345")); + assertThat(secondProfile.getName(), is("Updated Test Organization")); + + // Test third profile - with different strategy overrides + UserAttributeProfile thirdProfile = profiles.get(2); + assertThat(thirdProfile.getId(), is("uap_1234")); + assertThat(thirdProfile.getName(), is("This is another test")); + + // Test UserId strategy overrides in third profile + UserId thirdUserId = thirdProfile.getUserId(); + assertThat(thirdUserId.getStrategyOverrides(), is(notNullValue())); + assertThat(thirdUserId.getStrategyOverrides(), hasKey("google-apps")); + + // Test UserAttributes strategy overrides in third profile + Map thirdUserAttributes = thirdProfile.getUserAttributes(); + UserAttributes thirdUsernameAttr = thirdUserAttributes.get("username"); + assertThat(thirdUsernameAttr.getStrategyOverrides(), is(notNullValue())); + assertThat(thirdUsernameAttr.getStrategyOverrides(), hasKey("okta")); + } + +} diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponseTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponseTest.java new file mode 100644 index 000000000..6b78e3f17 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponseTest.java @@ -0,0 +1,139 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.auth0.json.JsonMatcher; +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.hasSize; + +public class UserAttributeProfileTemplateTest extends JsonTest { + + private static final String readOnlyJson = "{\"id\":\"auth0-generic\",\"display_name\":\"A standard user attribute profile template\"}"; + + private static final String fullJson = "{\n" + + " \"id\": \"auth0-generic\",\n" + + " \"display_name\": \"A standard user attribute profile template\",\n" + + " \"template\": {\n" + + " \"name\": \"This is just a test\",\n" + + " \"user_id\": {\n" + + " \"oidc_mapping\": \"sub\",\n" + + " \"saml_mapping\": [\n" + + " \"urn:oid:0.9.10.10.100.1.1\"\n" + + " ],\n" + + " \"scim_mapping\": \"userName\"\n" + + " },\n" + + " \"user_attributes\": {\n" + + " \"username\": {\n" + + " \"label\": \"test User\",\n" + + " \"description\": \"This is just a test\",\n" + + " \"oidc_mapping\": {\n" + + " \"mapping\": \"preferred_username\",\n" + + " \"display_name\": \"UserName\"\n" + + " },\n" + + " \"saml_mapping\":[\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\"],\n" + + " \"scim_mapping\":\"displayName\",\n" + + " \"auth0_mapping\": \"testUser\",\n" + + " \"profile_required\": false,\n" + + " \"strategy_overrides\": {\n" + + " \"oidc\": {\n" + + " \"scim_mapping\":\"name.givenName\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + + @Test + public void shouldSerialize() throws Exception { + UserAttributeProfileTemplate template = new UserAttributeProfileTemplate(); + template.setDisplayName("A standard user attribute profile template"); + + // Create nested UserAttributeProfile template + UserAttributeProfile userAttributeProfile = new UserAttributeProfile(); + userAttributeProfile.setName("Test Template Profile"); + + // Create and set UserId + UserId userId = new UserId(); + userId.setOidcMapping("sub"); + userId.setSamlMapping(Arrays.asList("urn:oid:0.9.10.10.100.1.1")); + userId.setScimMapping("userName"); + userAttributeProfile.setUserId(userId); + + // Create and set UserAttributes + Map userAttributesMap = new HashMap<>(); + UserAttributes userAttributes = new UserAttributes(); + userAttributes.setLabel("test User"); + userAttributes.setDescription("This is just a test"); + userAttributes.setAuth0Mapping("testUser"); + userAttributes.setProfileRequired(false); + userAttributesMap.put("username", userAttributes); + userAttributeProfile.setUserAttributes(userAttributesMap); + + template.setTemplate(userAttributeProfile); + + String serialized = toJSON(template); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, JsonMatcher.hasEntry("display_name", "A standard user attribute profile template")); + assertThat(serialized, JsonMatcher.hasEntry("template", userAttributeProfile)); + } + + @Test + public void shouldDeserialize() throws Exception { + UserAttributeProfileTemplate template = fromJSON(readOnlyJson, UserAttributeProfileTemplate.class); + + assertThat(template, is(notNullValue())); + assertThat(template.getId(), is("auth0-generic")); + assertThat(template.getDisplayName(), is("A standard user attribute profile template")); + + // Verify nested UserAttributeProfile template + UserAttributeProfile userAttributeProfile = template.getTemplate(); + assertThat(userAttributeProfile, is(notNullValue())); + assertThat(userAttributeProfile.getName(), is("This is just a test")); + + // Verify UserId in template + UserId userId = userAttributeProfile.getUserId(); + assertThat(userId, is(notNullValue())); + assertThat(userId.getOidcMapping(), is("sub")); + assertThat(userId.getSamlMapping(), hasSize(1)); + assertThat(userId.getSamlMapping().get(0), is("urn:oid:0.9.10.10.100.1.1")); + assertThat(userId.getScimMapping(), is("userName")); + + // Verify UserAttributes in template + Map userAttributes = userAttributeProfile.getUserAttributes(); + assertThat(userAttributes, is(notNullValue())); + assertThat(userAttributes, hasKey("username")); + + UserAttributes usernameAttr = userAttributes.get("username"); + assertThat(usernameAttr, is(notNullValue())); + assertThat(usernameAttr.getLabel(), is("test User")); + assertThat(usernameAttr.getDescription(), is("This is just a test")); + assertThat(usernameAttr.getAuth0Mapping(), is("testUser")); + assertThat(usernameAttr.isProfileRequired(), is(false)); + + // Verify OIDC mapping in template + assertThat(usernameAttr.getOidcMapping(), is(notNullValue())); + assertThat(usernameAttr.getOidcMapping().getMapping(), is("preferred_username")); + assertThat(usernameAttr.getOidcMapping().getDisplayName(), is("UserName")); + + // Verify SAML mapping in template + assertThat(usernameAttr.getSamlMapping(), hasSize(1)); + assertThat(usernameAttr.getSamlMapping().get(0), + is("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")); + + // Verify SCIM mapping in template + assertThat(usernameAttr.getScimMapping(), is("displayName")); + + // Verify strategy overrides in template + assertThat(usernameAttr.getStrategyOverrides(), is(notNullValue())); + assertThat(usernameAttr.getStrategyOverrides(), hasKey("oidc")); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java new file mode 100644 index 000000000..744d0b366 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java @@ -0,0 +1,127 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.auth0.json.JsonMatcher; +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.hasSize; + +public class UserAttributeProfileTest extends JsonTest { + + private static final String readOnlyJson = "{\"id\":\"uap_1234567890\",\"name\":\"This is just a test\"}"; + + private static final String fullJson = "{\n" + + " \"id\": \"uap_1234567890\",\n" + + " \"name\": \"This is just a test\",\n" + + " \"user_id\": {\n" + + " \"oidc_mapping\": \"sub\",\n" + + " \"saml_mapping\": [\n" + + " \"urn:oid:0.9.10.10.100.1.1\"\n" + + " ],\n" + + " \"scim_mapping\": \"userName\"\n" + + " },\n" + + " \"user_attributes\": {\n" + + " \"username\": {\n" + + " \"label\": \"test User\",\n" + + " \"description\": \"This is just a test\",\n" + + " \"oidc_mapping\": {\n" + + " \"mapping\": \"preferred_username\",\n" + + " \"display_name\": \"UserName\"\n" + + " },\n" + + " \"saml_mapping\":[\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\"],\n" + + " \"scim_mapping\":\"displayName\",\n" + + " \"auth0_mapping\": \"testUser\",\n" + + " \"profile_required\": false,\n" + + " \"strategy_overrides\": {\n" + + " \"oidc\": {\n" + + " \"scim_mapping\":\"name.givenName\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + + @Test + public void shouldSerialize() throws Exception { + UserAttributeProfile profile = new UserAttributeProfile(); + profile.setName("Test Profile"); + + // Create and set UserId + UserId userId = new UserId(); + userId.setOidcMapping("sub"); + userId.setSamlMapping(Arrays.asList("urn:oid:0.9.10.10.100.1.1")); + userId.setScimMapping("userName"); + profile.setUserId(userId); + + // Create and set UserAttributes + Map userAttributesMap = new HashMap<>(); + UserAttributes userAttributes = new UserAttributes(); + userAttributes.setLabel("test User"); + userAttributes.setDescription("This is just a test"); + userAttributes.setAuth0Mapping("testUser"); + userAttributes.setProfileRequired(false); + userAttributesMap.put("username", userAttributes); + profile.setUserAttributes(userAttributesMap); + + String serialized = toJSON(profile); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, JsonMatcher.hasEntry("name", "Test Profile")); + assertThat(serialized, JsonMatcher.hasEntry("user_id", userId)); + assertThat(serialized, JsonMatcher.hasEntry("user_attributes", userAttributes)); + } + + @Test + public void shouldDeserialize() throws Exception { + UserAttributeProfile profile = fromJSON(readOnlyJson, UserAttributeProfile.class); + + assertThat(profile, is(notNullValue())); + assertThat(profile.getId(), is("uap_1234567890")); + assertThat(profile.getName(), is("This is just a test")); + + // Verify UserId deserialization + UserId userId = profile.getUserId(); + assertThat(userId, is(notNullValue())); + assertThat(userId.getOidcMapping(), is("sub")); + assertThat(userId.getSamlMapping(), hasSize(1)); + assertThat(userId.getSamlMapping().get(0), is("urn:oid:0.9.10.10.100.1.1")); + assertThat(userId.getScimMapping(), is("userName")); + + // Verify UserAttributes deserialization + Map userAttributes = profile.getUserAttributes(); + assertThat(userAttributes, is(notNullValue())); + assertThat(userAttributes, hasKey("username")); + + UserAttributes usernameAttr = userAttributes.get("username"); + assertThat(usernameAttr, is(notNullValue())); + assertThat(usernameAttr.getLabel(), is("test User")); + assertThat(usernameAttr.getDescription(), is("This is just a test")); + assertThat(usernameAttr.getAuth0Mapping(), is("testUser")); + assertThat(usernameAttr.isProfileRequired(), is(false)); + + // Verify OIDC mapping + assertThat(usernameAttr.getOidcMapping(), is(notNullValue())); + assertThat(usernameAttr.getOidcMapping().getMapping(), is("preferred_username")); + assertThat(usernameAttr.getOidcMapping().getDisplayName(), is("UserName")); + + // Verify SAML mapping + assertThat(usernameAttr.getSamlMapping(), hasSize(1)); + assertThat(usernameAttr.getSamlMapping().get(0), + is("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")); + + // Verify SCIM mapping + assertThat(usernameAttr.getScimMapping(), is("displayName")); + + // Verify strategy overrides + assertThat(usernameAttr.getStrategyOverrides(), is(notNullValue())); + assertThat(usernameAttr.getStrategyOverrides(), hasKey("oidc")); + } + +} diff --git a/src/test/resources/mgmt/user_attribute_profile.json b/src/test/resources/mgmt/user_attribute_profile.json new file mode 100644 index 000000000..fb73013ec --- /dev/null +++ b/src/test/resources/mgmt/user_attribute_profile.json @@ -0,0 +1,30 @@ +{ + "id": "uap_1234567890", + "name": "This is just a test", + "user_id": { + "oidc_mapping": "sub", + "saml_mapping": [ + "urn:oid:0.9.10.10.100.1.1" + ], + "scim_mapping": "userName" + }, + "user_attributes": { + "username": { + "label": "test User", + "description": "This is just a test", + "oidc_mapping": { + "mapping": "preferred_username", + "display_name": "UserName" + }, + "saml_mapping":["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"], + "scim_mapping":"displayName", + "auth0_mapping": "testUser", + "profile_required": false, + "strategy_overrides": { + "oidc": { + "scim_mapping":"name.givenName" + } + } + } + } +} diff --git a/src/test/resources/mgmt/user_attribute_profile_template.json b/src/test/resources/mgmt/user_attribute_profile_template.json new file mode 100644 index 000000000..0034bbfa6 --- /dev/null +++ b/src/test/resources/mgmt/user_attribute_profile_template.json @@ -0,0 +1,33 @@ +{ + "id": "auth0-generic", + "display_name": "A standard user attribute profile template", + "template": { + "name": "This is just a test", + "user_id": { + "oidc_mapping": "sub", + "saml_mapping": [ + "urn:oid:0.9.10.10.100.1.1" + ], + "scim_mapping": "userName" + }, + "user_attributes": { + "username": { + "label": "test User", + "description": "This is just a test", + "oidc_mapping": { + "mapping": "preferred_username", + "display_name": "UserName" + }, + "saml_mapping":["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"], + "scim_mapping":"displayName", + "auth0_mapping": "testUser", + "profile_required": false, + "strategy_overrides": { + "oidc": { + "scim_mapping":"name.givenName" + } + } + } + } + } +} diff --git a/src/test/resources/mgmt/user_attribute_profile_templates_list.json b/src/test/resources/mgmt/user_attribute_profile_templates_list.json new file mode 100644 index 000000000..a21ae3d3d --- /dev/null +++ b/src/test/resources/mgmt/user_attribute_profile_templates_list.json @@ -0,0 +1,39 @@ +{ + "user_attribute_profile_templates": [ + { + "id": "auth0-generic", + "display_name": "Auth0 Generic User Attribute Profile Template", + "template": { + "name": "This is just a test", + "user_id": { + "oidc_mapping": "sub", + "saml_mapping": [ + "urn:oid:0.9.10.10.100.1.1" + ], + "scim_mapping": "userName" + }, + "user_attributes": { + "username": { + "label": "test User", + "description": "This is just a test", + "oidc_mapping": { + "mapping": "preferred_username", + "display_name": "UserName" + }, + "saml_mapping": [ + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ], + "scim_mapping": "displayName", + "auth0_mapping": "testUser", + "profile_required": false, + "strategy_overrides": { + "oidc": { + "scim_mapping": "name.givenName" + } + } + } + } + } + } + ] +} diff --git a/src/test/resources/mgmt/user_attribute_profiles_list.json b/src/test/resources/mgmt/user_attribute_profiles_list.json new file mode 100644 index 000000000..2dcbc462a --- /dev/null +++ b/src/test/resources/mgmt/user_attribute_profiles_list.json @@ -0,0 +1,93 @@ +{ + "user_attribute_profiles": [ + { + "id": "uap_1234567890", + "name": "This is just a test", + "user_id": { + "oidc_mapping": "sub", + "saml_mapping": [ + "urn:oid:0.9.10.10.100.1.1" + ], + "scim_mapping": "userName" + }, + "user_attributes": { + "username": { + "label": "test User", + "description": "This is just a test", + "oidc_mapping": { + "mapping": "preferred_username", + "display_name": "UserName" + }, + "saml_mapping":["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"], + "scim_mapping":"displayName", + "auth0_mapping": "testUser", + "profile_required": false, + "strategy_overrides": { + "oidc": { + "scim_mapping":"name.givenName" + } + } + } + } + }, + { + "id": "uap_123456789012345", + "name": "Updated Test Organization", + "user_id": { + "oidc_mapping": "sub", + "saml_mapping": [ + "urn:oid:0.9.10.10.100.1.1" + ], + "scim_mapping": "userName" + }, + "user_attributes": { + "username": { + "label": "test User", + "description": "This is just a test", + "oidc_mapping": { + "mapping": "preferred_username", + "display_name": "Display Name" + }, + "auth0_mapping": "testUser", + "profile_required": false + } + } + }, + { + "id": "uap_1234", + "name": "This is another test", + "user_id": { + "oidc_mapping": "sub", + "saml_mapping": [ + "urn:oid:0.9.10.10.100.1.1" + ], + "scim_mapping": "userName", + "strategy_overrides": { + "google-apps": { + "oidc_mapping": "email" + } + } + }, + "user_attributes": { + "username": { + "label": "test User", + "description": "This is just a test", + "oidc_mapping": { + "mapping": "preferred_username", + "display_name": "Display Name" + }, + "auth0_mapping": "testUser", + "profile_required": false, + "strategy_overrides": { + "okta": { + "oidc_mapping": { + "mapping": "${context.userinfo.groups}", + "display_name": "groups" + } + } + } + } + } + } + ] +} From 5be537389c977c4c526debe22384c28f04a07c3c Mon Sep 17 00:00:00 2001 From: tanya732 Date: Thu, 25 Sep 2025 11:02:49 +0530 Subject: [PATCH 2/6] Updated tests --- .../mgmt/UserAttributeProfilesEntity.java | 4 +- .../ListUserAttributeProfileTemplate.java | 6 +- .../UserAttributeProfileTemplate.java | 73 +++++++++----- .../UserAttributeProfileTemplateResponse.java | 71 -------------- ...ListUserAttributeProfileTemplateTest.java} | 97 ++----------------- .../ListUserAttributeProfileTest.java | 23 ++++- ... => UserAttributeProfileTemplateTest.java} | 37 +++---- .../UserAttributeProfileTest.java | 19 ++-- 8 files changed, 110 insertions(+), 220 deletions(-) delete mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java rename src/test/java/com/auth0/json/mgmt/userAttributeProfiles/{ListUserAttributeProfileTemplateResponseTest.java => ListUserAttributeProfileTemplateTest.java} (60%) rename src/test/java/com/auth0/json/mgmt/userAttributeProfiles/{UserAttributeProfileTemplateResponseTest.java => UserAttributeProfileTemplateTest.java} (79%) diff --git a/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java index 0b42bbbf3..5b679a9af 100644 --- a/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java +++ b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java @@ -126,7 +126,7 @@ public Request delete(String id) { * @param id the ID of the user attribute profile template to retrieve. * @return a Request to execute. */ - public Request getTemplate(String id) { + public Request getTemplate(String id) { Asserts.assertNotNull(id, "id"); String url = baseUrl.newBuilder() @@ -135,7 +135,7 @@ public Request getTemplate(String id) { .addPathSegment(id) .build().toString(); - return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { }); } diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java index c3515a65a..34d108839 100644 --- a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java @@ -10,14 +10,14 @@ @JsonInclude(JsonInclude.Include.NON_NULL) public class ListUserAttributeProfileTemplate { @JsonProperty("user_attribute_profile_templates") - private List userAttributeProfileTemplateResponses; + private List userAttributeProfileTemplateResponses; /** * Gets the user attribute profile templates * @return the user attribute profile templates */ @JsonProperty("user_attribute_profile_templates") - public List getUserAttributeProfileTemplates() { + public List getUserAttributeProfileTemplates() { return userAttributeProfileTemplateResponses; } @@ -26,7 +26,7 @@ public List getUserAttributeProfileTemplat * @param userAttributeProfileTemplateResponses the user attribute profile templates */ @JsonProperty("user_attribute_profile_templates") - public void setUserAttributeProfileTemplates(List userAttributeProfileTemplateResponses) { + public void setUserAttributeProfileTemplates(List userAttributeProfileTemplateResponses) { this.userAttributeProfileTemplateResponses = userAttributeProfileTemplateResponses; } } diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java index a2a3247a6..1934a521d 100644 --- a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java @@ -4,39 +4,68 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; - +/** + * Class that represents a User Attribute Profile Template object. Related to + * the {@link com.auth0.client.mgmt.UserAttributeProfilesEntity} entity. + */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class UserAttributeProfileTemplate { - @JsonProperty("name") - private String name; - @JsonProperty("user_id") - private UserId userId; - @JsonProperty("user_attributes") - private Map userAttributes; - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; + @JsonProperty("id") + private String id; + @JsonProperty("display_name") + private String displayName; + @JsonProperty("template") + private UserAttributeProfile template; + + /** + * Getter for the template ID. + * + * @return the template ID. + */ + @JsonProperty("id") + public String getId() { + return id; } - public UserId getUserId() { - return userId; + /** + * Getter for the display name. + * + * @return the display name. + */ + @JsonProperty("display_name") + public String getDisplayName() { + return displayName; } - public void setUserId(UserId userId) { - this.userId = userId; + /** + * Setter for the display name. + * + * @param displayName the display name to set. + */ + @JsonProperty("display_name") + public void setDisplayName(String displayName) { + this.displayName = displayName; } - public Map getUserAttributes() { - return userAttributes; + /** + * Getter for the template. + * + * @return the template. + */ + @JsonProperty("template") + public UserAttributeProfile getTemplate() { + return template; } - public void setUserAttributes(Map userAttributes) { - this.userAttributes = userAttributes; + /** + * Setter for the template. + * + * @param template the template to set. + */ + @JsonProperty("template") + public void setTemplate(UserAttributeProfile template) { + this.template = template; } } diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java deleted file mode 100644 index 501ea5da3..000000000 --- a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.auth0.json.mgmt.userAttributeProfiles; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Class that represents a User Attribute Profile Template object. Related to - * the {@link com.auth0.client.mgmt.UserAttributeProfilesEntity} entity. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class UserAttributeProfileTemplateResponse { - - @JsonProperty("id") - private String id; - @JsonProperty("display_name") - private String displayName; - @JsonProperty("template") - private UserAttributeProfileTemplate template; - - /** - * Getter for the template ID. - * - * @return the template ID. - */ - @JsonProperty("id") - public String getId() { - return id; - } - - /** - * Getter for the display name. - * - * @return the display name. - */ - @JsonProperty("display_name") - public String getDisplayName() { - return displayName; - } - - /** - * Setter for the display name. - * - * @param displayName the display name to set. - */ - @JsonProperty("display_name") - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - /** - * Getter for the template. - * - * @return the template. - */ - @JsonProperty("template") - public UserAttributeProfileTemplate getTemplate() { - return template; - } - - /** - * Setter for the template. - * - * @param template the template to set. - */ - @JsonProperty("template") - public void setTemplate(UserAttributeProfileTemplate template) { - this.template = template; - } -} diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateResponseTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateTest.java similarity index 60% rename from src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateResponseTest.java rename to src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateTest.java index 53d558032..2c7c69be9 100644 --- a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateResponseTest.java +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateTest.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; +import static com.auth0.json.JsonMatcher.hasEntry; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -65,24 +66,20 @@ public class ListUserAttributeProfileTemplateTest extends JsonTest templates = listTemplates.getUserAttributeProfileTemplates(); assertThat(templates, hasSize(1)); @@ -151,73 +141,4 @@ public void shouldDeserializeWithFullTemplateDetails() throws Exception { assertThat(usernameAttr.getStrategyOverrides(), is(notNullValue())); assertThat(usernameAttr.getStrategyOverrides(), hasKey("oidc")); } - - @Test - public void shouldDeserializeEmptyList() throws Exception { - ListUserAttributeProfileTemplate listTemplates = fromJSON(emptyListJson, - ListUserAttributeProfileTemplate.class); - - assertThat(listTemplates, is(notNullValue())); - assertThat(listTemplates.getUserAttributeProfileTemplates(), is(notNullValue())); - assertThat(listTemplates.getUserAttributeProfileTemplates(), hasSize(0)); - } - - @Test - public void shouldHandleNullList() throws Exception { - ListUserAttributeProfileTemplate listTemplates = new ListUserAttributeProfileTemplate(); - listTemplates.setUserAttributeProfileTemplates(null); - - String serialized = toJSON(listTemplates); - assertThat(serialized, is(notNullValue())); - } - - @Test - public void shouldHandleTemplatesWithoutNestedProfile() throws Exception { - String minimalJson = "{\n" + - " \"user_attribute_profile_templates\": [\n" + - " {\n" + - " \"id\": \"minimal-template\",\n" + - " \"display_name\": \"Minimal Template\"\n" + - " }\n" + - " ]\n" + - "}"; - - ListUserAttributeProfileTemplate listTemplates = fromJSON(minimalJson, ListUserAttributeProfileTemplate.class); - - assertThat(listTemplates, is(notNullValue())); - List templates = listTemplates.getUserAttributeProfileTemplates(); - assertThat(templates, hasSize(1)); - - UserAttributeProfileTemplate template = templates.get(0); - assertThat(template.getId(), is("minimal-template")); - assertThat(template.getDisplayName(), is("Minimal Template")); - } - - @Test - public void shouldSerializeMultipleTemplates() throws Exception { - ListUserAttributeProfileTemplate listTemplates = new ListUserAttributeProfileTemplate(); - - // Create multiple templates with different structures - UserAttributeProfileTemplate template1 = new UserAttributeProfileTemplate(); - template1.setDisplayName("Template 1"); - - UserAttributeProfile profile1 = new UserAttributeProfile(); - profile1.setName("Profile 1"); - Map attrs1 = new HashMap<>(); - UserAttributes userAttr1 = new UserAttributes(); - userAttr1.setLabel("User 1"); - userAttr1.setDescription("Description 1"); - attrs1.put("user1", userAttr1); - profile1.setUserAttributes(attrs1); - template1.setTemplate(profile1); - - UserAttributeProfileTemplate template2 = new UserAttributeProfileTemplate(); - template2.setDisplayName("Template 2"); - - listTemplates.setUserAttributeProfileTemplates(Arrays.asList(template1, template2)); - - String serialized = toJSON(listTemplates); - assertThat(serialized, is(notNullValue())); - assertThat(serialized, JsonMatcher.hasEntry("user_attribute_profile_templates", listTemplates)); - } } diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java index bf1671209..a2345d41f 100644 --- a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java @@ -2,6 +2,7 @@ import com.auth0.json.JsonMatcher; import com.auth0.json.JsonTest; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -9,6 +10,7 @@ import java.util.List; import java.util.Map; +import static com.auth0.json.JsonMatcher.hasEntry; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -120,18 +122,29 @@ public void shouldSerialize() throws Exception { ListUserAttributeProfile listProfiles = new ListUserAttributeProfile(); // Create first profile - UserAttributeProfile profile1 = new UserAttributeProfile(); - profile1.setName("Test Profile 1"); + UserAttributeProfile profile = new UserAttributeProfile(); + profile.setName("This is just a test"); // Create second profile UserAttributeProfile profile2 = new UserAttributeProfile(); - profile2.setName("Test Profile 2"); + profile2.setName("Updated Test Organization"); - listProfiles.setUserAttributeProfiles(Arrays.asList(profile1, profile2)); + listProfiles.setUserAttributeProfiles(Arrays.asList(profile, profile2)); String serialized = toJSON(listProfiles); assertThat(serialized, is(notNullValue())); - assertThat(serialized, JsonMatcher.hasEntry("user_attribute_profiles", listProfiles)); + + // Parse the serialized JSON into a Map + ObjectMapper objectMapper = new ObjectMapper(); + Map jsonMap = objectMapper.readValue(serialized, Map.class); + + // Validate the structure + assertThat(jsonMap, hasKey("user_attribute_profiles")); + List> profiles = (List>) jsonMap.get("user_attribute_profiles"); + assertThat(profiles, hasSize(2)); + assertThat(profiles.get(0).get("name"), is("This is just a test")); + assertThat(profiles.get(1).get("name"), is("Updated Test Organization")); + } @Test diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponseTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateTest.java similarity index 79% rename from src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponseTest.java rename to src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateTest.java index 6b78e3f17..67c0dbccc 100644 --- a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponseTest.java +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateTest.java @@ -1,7 +1,7 @@ package com.auth0.json.mgmt.userAttributeProfiles; -import com.auth0.json.JsonMatcher; import com.auth0.json.JsonTest; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -16,7 +16,6 @@ public class UserAttributeProfileTemplateTest extends JsonTest { - private static final String readOnlyJson = "{\"id\":\"auth0-generic\",\"display_name\":\"A standard user attribute profile template\"}"; private static final String fullJson = "{\n" + " \"id\": \"auth0-generic\",\n" + @@ -82,13 +81,24 @@ public void shouldSerialize() throws Exception { String serialized = toJSON(template); assertThat(serialized, is(notNullValue())); - assertThat(serialized, JsonMatcher.hasEntry("display_name", "A standard user attribute profile template")); - assertThat(serialized, JsonMatcher.hasEntry("template", userAttributeProfile)); + + // Parse the serialized JSON into a Map + ObjectMapper objectMapper = new ObjectMapper(); + Map jsonMap = objectMapper.readValue(serialized, Map.class); + + // Validate the structure + assertThat(jsonMap, hasKey("display_name")); + assertThat(jsonMap.get("display_name"), is("A standard user attribute profile template")); + assertThat(jsonMap, hasKey("template")); + + Map templateMap = (Map) jsonMap.get("template"); + assertThat(templateMap, hasKey("name")); + assertThat(templateMap.get("name"), is("Test Template Profile")); } @Test public void shouldDeserialize() throws Exception { - UserAttributeProfileTemplate template = fromJSON(readOnlyJson, UserAttributeProfileTemplate.class); + UserAttributeProfileTemplate template = fromJSON(fullJson, UserAttributeProfileTemplate.class); assertThat(template, is(notNullValue())); assertThat(template.getId(), is("auth0-generic")); @@ -118,22 +128,5 @@ public void shouldDeserialize() throws Exception { assertThat(usernameAttr.getDescription(), is("This is just a test")); assertThat(usernameAttr.getAuth0Mapping(), is("testUser")); assertThat(usernameAttr.isProfileRequired(), is(false)); - - // Verify OIDC mapping in template - assertThat(usernameAttr.getOidcMapping(), is(notNullValue())); - assertThat(usernameAttr.getOidcMapping().getMapping(), is("preferred_username")); - assertThat(usernameAttr.getOidcMapping().getDisplayName(), is("UserName")); - - // Verify SAML mapping in template - assertThat(usernameAttr.getSamlMapping(), hasSize(1)); - assertThat(usernameAttr.getSamlMapping().get(0), - is("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")); - - // Verify SCIM mapping in template - assertThat(usernameAttr.getScimMapping(), is("displayName")); - - // Verify strategy overrides in template - assertThat(usernameAttr.getStrategyOverrides(), is(notNullValue())); - assertThat(usernameAttr.getStrategyOverrides(), hasKey("oidc")); } } diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java index 744d0b366..28cbf9e4e 100644 --- a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java @@ -1,7 +1,7 @@ package com.auth0.json.mgmt.userAttributeProfiles; -import com.auth0.json.JsonMatcher; import com.auth0.json.JsonTest; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -16,8 +16,6 @@ public class UserAttributeProfileTest extends JsonTest { - private static final String readOnlyJson = "{\"id\":\"uap_1234567890\",\"name\":\"This is just a test\"}"; - private static final String fullJson = "{\n" + " \"id\": \"uap_1234567890\",\n" + " \"name\": \"This is just a test\",\n" + @@ -73,14 +71,21 @@ public void shouldSerialize() throws Exception { String serialized = toJSON(profile); assertThat(serialized, is(notNullValue())); - assertThat(serialized, JsonMatcher.hasEntry("name", "Test Profile")); - assertThat(serialized, JsonMatcher.hasEntry("user_id", userId)); - assertThat(serialized, JsonMatcher.hasEntry("user_attributes", userAttributes)); + + // Parse the serialized JSON into a Map + ObjectMapper objectMapper = new ObjectMapper(); + Map jsonMap = objectMapper.readValue(serialized, Map.class); + + // Validate the structure + assertThat(jsonMap, hasKey("name")); + assertThat(jsonMap.get("name"), is("Test Profile")); + assertThat(jsonMap, hasKey("user_id")); + assertThat(jsonMap, hasKey("user_attributes")); } @Test public void shouldDeserialize() throws Exception { - UserAttributeProfile profile = fromJSON(readOnlyJson, UserAttributeProfile.class); + UserAttributeProfile profile = fromJSON(fullJson, UserAttributeProfile.class); assertThat(profile, is(notNullValue())); assertThat(profile.getId(), is("uap_1234567890")); From 9b6c743847006847f87692dc6ebe81e38a40db74 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Fri, 26 Sep 2025 15:56:58 +0530 Subject: [PATCH 3/6] Updated Schema --- .../ListUserAttributeProfile.java | 13 +++++++++++++ .../mgmt/user_attribute_profiles_list.json | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java index 282e08cd9..d0c9e391a 100644 --- a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java @@ -12,6 +12,9 @@ public class ListUserAttributeProfile { @JsonProperty("user_attribute_profiles") private List userAttributeProfiles; + @JsonProperty("next") + private String next; + /** * Gets the user attribute profiles. * @return the user attribute profiles @@ -29,4 +32,14 @@ public List getUserAttributeProfiles() { public void setUserAttributeProfiles(List userAttributeProfiles) { this.userAttributeProfiles = userAttributeProfiles; } + + @JsonProperty("next") + public String getNext() { + return next; + } + + @JsonProperty("next") + public void setNext(String next) { + this.next = next; + } } diff --git a/src/test/resources/mgmt/user_attribute_profiles_list.json b/src/test/resources/mgmt/user_attribute_profiles_list.json index 2dcbc462a..6eb4f57d6 100644 --- a/src/test/resources/mgmt/user_attribute_profiles_list.json +++ b/src/test/resources/mgmt/user_attribute_profiles_list.json @@ -89,5 +89,7 @@ } } } - ] + ], + "next": "Fe26.2*API2_1758785444*34b68e78fd693520c028d0ea61ae32653a36ca05d3da972107bb12a581eea9bb*" + } From 6a034ca23debd91b08bebad8472542bb75840851 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Mon, 29 Sep 2025 13:03:31 +0530 Subject: [PATCH 4/6] Added minor modification --- .../client/mgmt/UserAttributeProfilesEntity.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java index 5b679a9af..8081a98be 100644 --- a/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java +++ b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java @@ -47,7 +47,9 @@ public Request getAll(UserAttributeProfilesFilter filt HttpUrl.Builder builder = baseUrl.newBuilder() .addPathSegments(ORGS_PATH); - applyFilter(filter, builder); + if (filter != null) { + filter.getAsMap().forEach((k, v) -> builder.addQueryParameter(k, String.valueOf(v))); + } String url = builder.build().toString(); @@ -55,13 +57,6 @@ public Request getAll(UserAttributeProfilesFilter filt }); } - private void applyFilter(UserAttributeProfilesFilter filter, HttpUrl.Builder builder) { - if (filter != null) { - filter.getAsMap().forEach((k, v) -> builder.addQueryParameter(k, String.valueOf(v))); - } - } - - /** * Update a user attribute profile. A token with {@code update:user_attribute_profiles} scope is required. * From ca22649a06f04660380203f827b90d216ac1a65d Mon Sep 17 00:00:00 2001 From: tanya732 Date: Tue, 30 Sep 2025 11:13:27 +0530 Subject: [PATCH 5/6] Added UserAttributeProfilePage and Deserializer --- .../mgmt/UserAttributeProfilesEntity.java | 4 +- .../ListUserAttributeProfile.java | 45 ---- .../UserAttributeProfilePage.java | 26 +++ .../UserAttributeProfilePageDeserializer.java | 28 +++ .../mgmt/UserAttributeProfilesEntityTest.java | 14 +- .../ListUserAttributeProfileTest.java | 210 ------------------ 6 files changed, 63 insertions(+), 264 deletions(-) delete mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfilePage.java create mode 100644 src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfilePageDeserializer.java delete mode 100644 src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java diff --git a/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java index 8081a98be..053f89877 100644 --- a/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java +++ b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java @@ -43,7 +43,7 @@ public Request get(String id) { * @return a Request to execute * */ - public Request getAll(UserAttributeProfilesFilter filter) { + public Request getAll(UserAttributeProfilesFilter filter) { HttpUrl.Builder builder = baseUrl.newBuilder() .addPathSegments(ORGS_PATH); @@ -53,7 +53,7 @@ public Request getAll(UserAttributeProfilesFilter filt String url = builder.build().toString(); - return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { }); } diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java deleted file mode 100644 index d0c9e391a..000000000 --- a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.auth0.json.mgmt.userAttributeProfiles; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class ListUserAttributeProfile { - @JsonProperty("user_attribute_profiles") - private List userAttributeProfiles; - - @JsonProperty("next") - private String next; - - /** - * Gets the user attribute profiles. - * @return the user attribute profiles - */ - @JsonProperty("user_attribute_profiles") - public List getUserAttributeProfiles() { - return userAttributeProfiles; - } - - /** - * Sets the user attribute profiles. - * @param userAttributeProfiles the user attribute profiles - */ - @JsonProperty("user_attribute_profiles") - public void setUserAttributeProfiles(List userAttributeProfiles) { - this.userAttributeProfiles = userAttributeProfiles; - } - - @JsonProperty("next") - public String getNext() { - return next; - } - - @JsonProperty("next") - public void setNext(String next) { - this.next = next; - } -} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfilePage.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfilePage.java new file mode 100644 index 000000000..3cdca2a6d --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfilePage.java @@ -0,0 +1,26 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.auth0.json.mgmt.Page; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.List; + +@SuppressWarnings({"unused", "WeakerAccess"}) +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonDeserialize(using = UserAttributeProfilePageDeserializer.class) +public class UserAttributeProfilePage extends Page { + public UserAttributeProfilePage(List items) { + super(items); + } + + protected UserAttributeProfilePage(Integer start, Integer length, Integer total, Integer limit, List items) { + super(start, length, total, limit, items); + } + + protected UserAttributeProfilePage(Integer start, Integer length, Integer total, Integer limit, String next, List items){ + super(start, length, total, limit, next, items); + } +} diff --git a/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfilePageDeserializer.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfilePageDeserializer.java new file mode 100644 index 000000000..d4a89bf7b --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfilePageDeserializer.java @@ -0,0 +1,28 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +import com.auth0.json.mgmt.PageDeserializer; + +import java.util.List; + + +@SuppressWarnings({"unused", "WeakerAccess"}) +class UserAttributeProfilePageDeserializer extends PageDeserializer { + UserAttributeProfilePageDeserializer() { + super(UserAttributeProfile.class, "user_attribute_profiles"); + } + + @Override + protected UserAttributeProfilePage createPage(List items) { + return new UserAttributeProfilePage(items); + } + + @Override + protected UserAttributeProfilePage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { + return new UserAttributeProfilePage(start, length, total, limit, items); + } + + @Override + protected UserAttributeProfilePage createPage(Integer start, Integer length, Integer total, Integer limit, String next, List items) { + return new UserAttributeProfilePage(start, length, total, limit, next, items); + } +} diff --git a/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java b/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java index b27a221e8..635cfe9f2 100644 --- a/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java @@ -49,11 +49,11 @@ public void shouldGetUserAttributeProfile() throws Exception { @Test public void shouldGetAllUserAttributeProfilesWithoutFilter() throws Exception { - Request request = api.userAttributeProfiles().getAll(null); + Request request = api.userAttributeProfiles().getAll(null); assertThat(request, is(notNullValue())); server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILES_LIST, 200); - ListUserAttributeProfile response = request.execute().getBody(); + UserAttributeProfilePage response = request.execute().getBody(); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/user-attribute-profiles")); @@ -61,19 +61,19 @@ public void shouldGetAllUserAttributeProfilesWithoutFilter() throws Exception { assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); assertThat(response, is(notNullValue())); - assertThat(response.getUserAttributeProfiles(), hasSize(3)); + assertThat(response.getItems(), hasSize(3)); } @Test public void shouldGetAllUserAttributeProfilesWithFilter() throws Exception { UserAttributeProfilesFilter filter = new UserAttributeProfilesFilter() - .withCheckpointPagination("uap_1234567890", 10); + .withCheckpointPagination("uap_1234567890", 2); - Request request = api.userAttributeProfiles().getAll(filter); + Request request = api.userAttributeProfiles().getAll(filter); assertThat(request, is(notNullValue())); server.jsonResponse(MockServer.MGMT_USER_ATTRIBUTE_PROFILES_LIST, 200); - ListUserAttributeProfile response = request.execute().getBody(); + UserAttributeProfilePage response = request.execute().getBody(); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/user-attribute-profiles")); @@ -83,7 +83,7 @@ public void shouldGetAllUserAttributeProfilesWithFilter() throws Exception { assertThat(recordedRequest, hasQueryParameter("take", "10")); assertThat(response, is(notNullValue())); - assertThat(response.getUserAttributeProfiles(), hasSize(3)); + assertThat(response.getItems(), hasSize(2)); } @Test diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java deleted file mode 100644 index a2345d41f..000000000 --- a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java +++ /dev/null @@ -1,210 +0,0 @@ -package com.auth0.json.mgmt.userAttributeProfiles; - -import com.auth0.json.JsonMatcher; -import com.auth0.json.JsonTest; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.auth0.json.JsonMatcher.hasEntry; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.hasKey; - -public class ListUserAttributeProfileTest extends JsonTest { - - private static final String jsonWithProfiles = "{\n" + - " \"user_attribute_profiles\": [\n" + - " {\n" + - " \"id\": \"uap_1234567890\",\n" + - " \"name\": \"This is just a test\",\n" + - " \"user_id\": {\n" + - " \"oidc_mapping\": \"sub\",\n" + - " \"saml_mapping\": [\n" + - " \"urn:oid:0.9.10.10.100.1.1\"\n" + - " ],\n" + - " \"scim_mapping\": \"userName\"\n" + - " },\n" + - " \"user_attributes\": {\n" + - " \"username\": {\n" + - " \"label\": \"test User\",\n" + - " \"description\": \"This is just a test\",\n" + - " \"oidc_mapping\": {\n" + - " \"mapping\": \"preferred_username\",\n" + - " \"display_name\": \"UserName\"\n" + - " },\n" + - " \"saml_mapping\":[\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\"],\n" + - " \"scim_mapping\":\"displayName\",\n" + - " \"auth0_mapping\": \"testUser\",\n" + - " \"profile_required\": false,\n" + - " \"strategy_overrides\": {\n" + - " \"oidc\": {\n" + - " \"scim_mapping\":\"name.givenName\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": \"uap_123456789012345\",\n" + - " \"name\": \"Updated Test Organization\",\n" + - " \"user_id\": {\n" + - " \"oidc_mapping\": \"sub\",\n" + - " \"saml_mapping\": [\n" + - " \"urn:oid:0.9.10.10.100.1.1\"\n" + - " ],\n" + - " \"scim_mapping\": \"userName\"\n" + - " },\n" + - " \"user_attributes\": {\n" + - " \"username\": {\n" + - " \"label\": \"test User\",\n" + - " \"description\": \"This is just a test\",\n" + - " \"oidc_mapping\": {\n" + - " \"mapping\": \"preferred_username\",\n" + - " \"display_name\": \"Display Name\"\n" + - " },\n" + - " \"auth0_mapping\": \"testUser\",\n" + - " \"profile_required\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": \"uap_1234\",\n" + - " \"name\": \"This is another test\",\n" + - " \"user_id\": {\n" + - " \"oidc_mapping\": \"sub\",\n" + - " \"saml_mapping\": [\n" + - " \"urn:oid:0.9.10.10.100.1.1\"\n" + - " ],\n" + - " \"scim_mapping\": \"userName\",\n" + - " \"strategy_overrides\": {\n" + - " \"google-apps\": {\n" + - " \"oidc_mapping\": \"email\"\n" + - " }\n" + - " }\n" + - " },\n" + - " \"user_attributes\": {\n" + - " \"username\": {\n" + - " \"label\": \"test User\",\n" + - " \"description\": \"This is just a test\",\n" + - " \"oidc_mapping\": {\n" + - " \"mapping\": \"preferred_username\",\n" + - " \"display_name\": \"Display Name\"\n" + - " },\n" + - " \"auth0_mapping\": \"testUser\",\n" + - " \"profile_required\": false,\n" + - " \"strategy_overrides\": {\n" + - " \"okta\": {\n" + - " \"oidc_mapping\": {\n" + - " \"mapping\": \"${context.userinfo.groups}\",\n" + - " \"display_name\": \"groups\"\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - " ]\n" + - "}"; - - private static final String emptyListJson = "{\n" + - " \"user_attribute_profiles\": []\n" + - "}"; - - @Test - public void shouldSerialize() throws Exception { - ListUserAttributeProfile listProfiles = new ListUserAttributeProfile(); - - // Create first profile - UserAttributeProfile profile = new UserAttributeProfile(); - profile.setName("This is just a test"); - - // Create second profile - UserAttributeProfile profile2 = new UserAttributeProfile(); - profile2.setName("Updated Test Organization"); - - listProfiles.setUserAttributeProfiles(Arrays.asList(profile, profile2)); - - String serialized = toJSON(listProfiles); - assertThat(serialized, is(notNullValue())); - - // Parse the serialized JSON into a Map - ObjectMapper objectMapper = new ObjectMapper(); - Map jsonMap = objectMapper.readValue(serialized, Map.class); - - // Validate the structure - assertThat(jsonMap, hasKey("user_attribute_profiles")); - List> profiles = (List>) jsonMap.get("user_attribute_profiles"); - assertThat(profiles, hasSize(2)); - assertThat(profiles.get(0).get("name"), is("This is just a test")); - assertThat(profiles.get(1).get("name"), is("Updated Test Organization")); - - } - - @Test - public void shouldDeserialize() throws Exception { - ListUserAttributeProfile listProfiles = fromJSON(jsonWithProfiles, ListUserAttributeProfile.class); - - assertThat(listProfiles, is(notNullValue())); - assertThat(listProfiles.getUserAttributeProfiles(), is(notNullValue())); - assertThat(listProfiles.getUserAttributeProfiles(), hasSize(3)); - - List profiles = listProfiles.getUserAttributeProfiles(); - - // Test first profile - full details - UserAttributeProfile firstProfile = profiles.get(0); - assertThat(firstProfile.getId(), is("uap_1234567890")); - assertThat(firstProfile.getName(), is("This is just a test")); - - // Test UserId of first profile - UserId userId = firstProfile.getUserId(); - assertThat(userId, is(notNullValue())); - assertThat(userId.getOidcMapping(), is("sub")); - assertThat(userId.getSamlMapping(), hasSize(1)); - assertThat(userId.getSamlMapping().get(0), is("urn:oid:0.9.10.10.100.1.1")); - assertThat(userId.getScimMapping(), is("userName")); - - // Test UserAttributes of first profile - Map userAttributes = firstProfile.getUserAttributes(); - assertThat(userAttributes, is(notNullValue())); - assertThat(userAttributes, hasKey("username")); - - UserAttributes usernameAttr = userAttributes.get("username"); - assertThat(usernameAttr.getLabel(), is("test User")); - assertThat(usernameAttr.getDescription(), is("This is just a test")); - assertThat(usernameAttr.getAuth0Mapping(), is("testUser")); - assertThat(usernameAttr.isProfileRequired(), is(false)); - - // Test strategy overrides in first profile - assertThat(usernameAttr.getStrategyOverrides(), is(notNullValue())); - assertThat(usernameAttr.getStrategyOverrides(), hasKey("oidc")); - - // Test second profile - basic details - UserAttributeProfile secondProfile = profiles.get(1); - assertThat(secondProfile.getId(), is("uap_123456789012345")); - assertThat(secondProfile.getName(), is("Updated Test Organization")); - - // Test third profile - with different strategy overrides - UserAttributeProfile thirdProfile = profiles.get(2); - assertThat(thirdProfile.getId(), is("uap_1234")); - assertThat(thirdProfile.getName(), is("This is another test")); - - // Test UserId strategy overrides in third profile - UserId thirdUserId = thirdProfile.getUserId(); - assertThat(thirdUserId.getStrategyOverrides(), is(notNullValue())); - assertThat(thirdUserId.getStrategyOverrides(), hasKey("google-apps")); - - // Test UserAttributes strategy overrides in third profile - Map thirdUserAttributes = thirdProfile.getUserAttributes(); - UserAttributes thirdUsernameAttr = thirdUserAttributes.get("username"); - assertThat(thirdUsernameAttr.getStrategyOverrides(), is(notNullValue())); - assertThat(thirdUsernameAttr.getStrategyOverrides(), hasKey("okta")); - } - -} From b3fe7ab4abf0d63ac6091b30a5418a17f6987d49 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Tue, 30 Sep 2025 12:45:05 +0530 Subject: [PATCH 6/6] Fixed Tests --- .../auth0/client/mgmt/UserAttributeProfilesEntityTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java b/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java index 635cfe9f2..0ef82f5ce 100644 --- a/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/UserAttributeProfilesEntityTest.java @@ -80,10 +80,10 @@ public void shouldGetAllUserAttributeProfilesWithFilter() throws Exception { assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); assertThat(recordedRequest, hasQueryParameter("from", "uap_1234567890")); - assertThat(recordedRequest, hasQueryParameter("take", "10")); + assertThat(recordedRequest, hasQueryParameter("take", "2")); assertThat(response, is(notNullValue())); - assertThat(response.getItems(), hasSize(2)); + assertThat(response.getItems(), hasSize(3)); } @Test