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..8081a98be --- /dev/null +++ b/src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java @@ -0,0 +1,151 @@ +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); + + if (filter != null) { + filter.getAsMap().forEach((k, v) -> builder.addQueryParameter(k, String.valueOf(v))); + } + + String url = builder.build().toString(); + + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * 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..d0c9e391a --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfile.java @@ -0,0 +1,45 @@ +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/ListUserAttributeProfileTemplate.java b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java new file mode 100644 index 000000000..34d108839 --- /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..1934a521d --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.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 UserAttributeProfileTemplate { + + @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; + } + + /** + * 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 UserAttributeProfile getTemplate() { + return template; + } + + /** + * 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/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/ListUserAttributeProfileTemplateTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateTest.java new file mode 100644 index 000000000..2c7c69be9 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateTest.java @@ -0,0 +1,144 @@ +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 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 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(); + + UserAttributeProfileTemplate template = new UserAttributeProfileTemplate(); + template.setDisplayName("Auth0 Generic User Attribute Profile Template"); + + // Create nested UserAttributeProfile for template1 + UserAttributeProfile userProfile = new UserAttributeProfile(); + userProfile.setName("This is just a test"); + template.setTemplate(userProfile); + + listTemplates.setUserAttributeProfileTemplates(Arrays.asList(template)); + + String serialized = toJSON(listTemplates); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, hasEntry("display_name", "Auth0 Generic User Attribute Profile Template")); + assertThat(serialized, hasEntry("template", notNullValue())); + } + + @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)); + + 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")); + } +} 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..a2345d41f --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java @@ -0,0 +1,210 @@ +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")); + } + +} diff --git a/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateTest.java b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateTest.java new file mode 100644 index 000000000..67c0dbccc --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateTest.java @@ -0,0 +1,132 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +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.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 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())); + + // 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(fullJson, 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)); + } +} 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..28cbf9e4e --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTest.java @@ -0,0 +1,132 @@ +package com.auth0.json.mgmt.userAttributeProfiles; + +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.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 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())); + + // 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(fullJson, 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..6eb4f57d6 --- /dev/null +++ b/src/test/resources/mgmt/user_attribute_profiles_list.json @@ -0,0 +1,95 @@ +{ + "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" + } + } + } + } + } + } + ], + "next": "Fe26.2*API2_1758785444*34b68e78fd693520c028d0ea61ae32653a36ca05d3da972107bb12a581eea9bb*" + +}