From 5c647e956423c78e5938b2d9ef3f76fb0adcfbc8 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Fri, 24 Jan 2025 11:27:30 +0530 Subject: [PATCH 1/3] Added Connection's SCIM Server Support --- .../auth0/client/mgmt/ConnectionsEntity.java | 211 ++++++++++++- .../auth0/json/mgmt/connections/Mapping.java | 66 ++++ .../connections/ScimConfigurationRequest.java | 65 ++++ .../ScimConfigurationResponse.java | 156 ++++++++++ .../connections/ScimTokenBaseResponse.java | 84 +++++ .../connections/ScimTokenCreateResponse.java | 28 ++ .../mgmt/connections/ScimTokenRequest.java | 48 +++ .../mgmt/connections/ScimTokenResponse.java | 28 ++ .../java/com/auth0/client/MockServer.java | 4 + .../client/mgmt/ConnectionsEntityTest.java | 290 +++++++++++++++++- .../{ => connections}/ConnectionTest.java | 3 +- .../ScimConfigurationRequestTest.java | 51 +++ .../ScimConfigurationResponseTest.java | 66 ++++ .../ScimTokenBaseResponseTest.java | 56 ++++ .../ScimTokenCreateResponseTest.java | 48 +++ .../connections/ScimTokenRequestTest.java | 44 +++ .../connections/ScimTokenResponseTest.java | 60 ++++ .../mgmt/connection_scim_configuration.json | 19 ++ .../resources/mgmt/connection_scim_token.json | 9 + .../mgmt/connection_scim_tokens.json | 21 ++ ...default_connection_scim_configuration.json | 12 + 21 files changed, 1363 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/auth0/json/mgmt/connections/Mapping.java create mode 100644 src/main/java/com/auth0/json/mgmt/connections/ScimConfigurationRequest.java create mode 100644 src/main/java/com/auth0/json/mgmt/connections/ScimConfigurationResponse.java create mode 100644 src/main/java/com/auth0/json/mgmt/connections/ScimTokenBaseResponse.java create mode 100644 src/main/java/com/auth0/json/mgmt/connections/ScimTokenCreateResponse.java create mode 100644 src/main/java/com/auth0/json/mgmt/connections/ScimTokenRequest.java create mode 100644 src/main/java/com/auth0/json/mgmt/connections/ScimTokenResponse.java rename src/test/java/com/auth0/json/mgmt/{ => connections}/ConnectionTest.java (97%) create mode 100644 src/test/java/com/auth0/json/mgmt/connections/ScimConfigurationRequestTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/connections/ScimConfigurationResponseTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/connections/ScimTokenBaseResponseTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/connections/ScimTokenCreateResponseTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/connections/ScimTokenRequestTest.java create mode 100644 src/test/java/com/auth0/json/mgmt/connections/ScimTokenResponseTest.java create mode 100644 src/test/resources/mgmt/connection_scim_configuration.json create mode 100644 src/test/resources/mgmt/connection_scim_token.json create mode 100644 src/test/resources/mgmt/connection_scim_tokens.json create mode 100644 src/test/resources/mgmt/default_connection_scim_configuration.json diff --git a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java index 80b935abe..b19775a2f 100644 --- a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java +++ b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java @@ -1,8 +1,7 @@ package com.auth0.client.mgmt; import com.auth0.client.mgmt.filter.ConnectionFilter; -import com.auth0.json.mgmt.connections.Connection; -import com.auth0.json.mgmt.connections.ConnectionsPage; +import com.auth0.json.mgmt.connections.*; import com.auth0.net.BaseRequest; import com.auth0.net.Request; import com.auth0.net.VoidRequest; @@ -163,4 +162,212 @@ public Request deleteUser(String connectionId, String email) { .toString(); return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE); } + + /** + * Get the Connections Scim Configuration. + * A token with scope read:scim_config is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/get-scim-configuration + * @param connectionId the connection id. + * @return a Request to execute. + */ + public Request getScimConfiguration( String connectionId) { + Asserts.assertNotNull(connectionId, "connection id"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegment("scim-configuration") + .build() + .toString(); + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * Delete the Connections Scim Configuration. + * A token with scope delete:scim_config is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/delete-scim-configuration + * @param connectionId the connection id. + * @return a Request to execute. + */ + public Request deleteScimConfiguration(String connectionId) { + Asserts.assertNotNull(connectionId, "connection id"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegment("scim-configuration") + .build() + .toString(); + return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); + } + + /** + * Update the Connections Scim Configuration. + * A token with scope update:scim_config is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/patch-scim-configuration + * @param connectionId the connection id. + * @param scimConfigurationRequest the scim configuration request. + * @return a Request to execute. + */ + public Request updateScimConfiguration(String connectionId, ScimConfigurationRequest scimConfigurationRequest){ + Asserts.assertNotNull(connectionId, "connection id"); + Asserts.assertNotNull(scimConfigurationRequest, "scim configuration request"); + Asserts.assertNotNull(scimConfigurationRequest.getUserIdAttribute(), "user id attribute"); + Asserts.assertNotNull(scimConfigurationRequest.getMapping(), "mapping"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegment("scim-configuration") + .build() + .toString(); + + BaseRequest request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PATCH, new TypeReference() { + }); + request.setBody(scimConfigurationRequest); + return request; + } + + /** + * Create the Connections Scim Configuration. + * A token with scope create:scim_config is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/post-scim-configuration + * @param connectionId the connection id. + * @param request the scim configuration request. + * @return a Request to execute. + */ + public Request createScimConfiguration(String connectionId, ScimConfigurationRequest request){ + Asserts.assertNotNull(connectionId, "connection id"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegment("scim-configuration") + .build() + .toString(); + + BaseRequest baseRequest = new BaseRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference() { + }); + baseRequest.setBody(request); + return baseRequest; + } + + /** + * Get the Scim Configuration default mapping by its connection Id. + * A token with scope read:scim_config is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/get-default-mapping + * @param connectionId the connection id. + * @return a Request to execute. + */ + public Request getDefaultScimConfiguration(String connectionId){ + Asserts.assertNotNull(connectionId, "connection id"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegment("scim-configuration") + .addPathSegment("default-mapping") + .build() + .toString(); + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference() { + }); + } + + /** + * Get the Connections Scim Tokens. + * A token with scope read:scim_token is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/get-scim-tokens + * @param connectionId the connection id. + * @return a Request to execute. + */ + public Request> getScimToken(String connectionId){ + Asserts.assertNotNull(connectionId, "connection id"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegments("scim-configuration/tokens") + .build() + .toString(); + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference>() { + }); + } + + /** + * Create a Connections Scim Token. + * A token with scope create:scim_token is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/post-scim-token + * @param connectionId the connection id. + * @param scimTokenRequest the scim token request. + * @return a Request to execute. + */ + public Request createScimToken(String connectionId, ScimTokenRequest scimTokenRequest){ + Asserts.assertNotNull(connectionId, "connection id"); + Asserts.assertNotNull(scimTokenRequest, "scim token request"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegments("scim-configuration/tokens") + .build() + .toString(); + + BaseRequest request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference() { + }); + request.setBody(scimTokenRequest); + return request; + } + + /** + * Delete a Connections Scim Token. + * A token with scope delete:scim_token is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/delete-tokens-by-token-id + * @param connectionId the connection id. + * @param tokenId the token id. + * @return a Request to execute. + */ + public Request deleteScimToken(String connectionId, String tokenId){ + Asserts.assertNotNull(connectionId, "connection id"); + Asserts.assertNotNull(tokenId, "token id"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegments("scim-configuration/tokens") + .addPathSegment(tokenId) + .build() + .toString(); + + return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); + } + + /** + * Check the Connection Status. + * A token with scope read:connections is needed. + * @see https://auth0.com/docs/api/management/v2#!/connections/get-status + * @param connectionId the connection id. + * @return a Request to execute. + */ + public Request checkConnectionStatus(String connectionId){ + Asserts.assertNotNull(connectionId, "connection id"); + + String url = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections") + .addPathSegment(connectionId) + .addPathSegments("status") + .build() + .toString(); + + return new VoidRequest(client, tokenProvider, url, HttpMethod.GET); + } } diff --git a/src/main/java/com/auth0/json/mgmt/connections/Mapping.java b/src/main/java/com/auth0/json/mgmt/connections/Mapping.java new file mode 100644 index 000000000..868c6e7d8 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/connections/Mapping.java @@ -0,0 +1,66 @@ +package com.auth0.json.mgmt.connections; + +import com.fasterxml.jackson.annotation.JsonCreator; +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 Mapping { + @JsonProperty("auth0") + private String auth0; + @JsonProperty("scim") + private String scim; + + /** + * Creates a new instance. + */ + @JsonCreator + public Mapping() { + + } + + /** + * Creates a new instance with the given Auth0 and SCIM attributes. + * @param auth0 the Auth0 attribute. + * @param scim the SCIM attribute. + */ + @JsonCreator + public Mapping(@JsonProperty("auth0") String auth0, @JsonProperty("scim") String scim) { + this.auth0 = auth0; + this.scim = scim; + } + + /** + * Getter for the Auth0 attribute. + * @return the Auth0 attribute. + */ + public String getAuth0() { + return auth0; + } + + /** + * Setter for the Auth0 attribute. + * @param auth0 the Auth0 attribute to set. + */ + public void setAuth0(String auth0) { + this.auth0 = auth0; + } + + /** + * Getter for the SCIM attribute. + * @return the SCIM attribute. + */ + public String getScim() { + return scim; + } + + /** + * Setter for the SCIM attribute. + * @param scim the SCIM attribute to set. + */ + public void setScim(String scim) { + this.scim = scim; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/connections/ScimConfigurationRequest.java b/src/main/java/com/auth0/json/mgmt/connections/ScimConfigurationRequest.java new file mode 100644 index 000000000..337d5288b --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/connections/ScimConfigurationRequest.java @@ -0,0 +1,65 @@ +package com.auth0.json.mgmt.connections; + +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 ScimConfigurationRequest { + @JsonProperty("user_id_attribute") + private String userIdAttribute; + @JsonProperty("mapping") + private List mapping; + + /** + * Creates a new instance. + */ + public ScimConfigurationRequest() { + + } + + /** + * Creates a new instance with the given user id attribute and mapping. + * @param userIdAttribute the user id attribute. + * @param mapping the mappings. + */ + public ScimConfigurationRequest(String userIdAttribute, List mapping) { + this.userIdAttribute = userIdAttribute; + this.mapping = mapping; + } + + /** + * Getter for the user id attribute. + * @return the user id attribute. + */ + public String getUserIdAttribute() { + return userIdAttribute; + } + + /** + * Setter for the user id attribute. + * @param userIdAttribute the user id attribute to set. + */ + public void setUserIdAttribute(String userIdAttribute) { + this.userIdAttribute = userIdAttribute; + } + + /** + * Getter for the mapping. + * @return the mapping. + */ + public List getMapping() { + return mapping; + } + + /** + * Setter for the mapping. + * @param mapping the mapping to set. + */ + public void setMapping(List mapping) { + this.mapping = mapping; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/connections/ScimConfigurationResponse.java b/src/main/java/com/auth0/json/mgmt/connections/ScimConfigurationResponse.java new file mode 100644 index 000000000..1133fa590 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/connections/ScimConfigurationResponse.java @@ -0,0 +1,156 @@ +package com.auth0.json.mgmt.connections; + +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 ScimConfigurationResponse { + @JsonProperty("connection_id") + private String connectionId; + @JsonProperty("connection_name") + private String connectionName; + @JsonProperty("strategy") + private String strategy; + @JsonProperty("tenant_name") + private String tenantName; + @JsonProperty("user_id_attribute") + private String userIdAttribute; + @JsonProperty("mapping") + private List mapping; + @JsonProperty("created_at") + private String createdAt; + @JsonProperty("updated_on") + private String updatedOn; + + /** + * Getter for the connection id. + * @return the connection id. + */ + public String getConnectionId() { + return connectionId; + } + + /** + * Setter for the connection id. + * @param connectionId the connection id to set. + */ + public void setConnectionId(String connectionId) { + this.connectionId = connectionId; + } + + /** + * Getter for the connection name. + * @return the connection name. + */ + public String getConnectionName() { + return connectionName; + } + + /** + * Setter for the connection name. + * @param connectionName the connection name to set. + */ + public void setConnectionName(String connectionName) { + this.connectionName = connectionName; + } + + /** + * Getter for the strategy. + * @return the strategy. + */ + public String getStrategy() { + return strategy; + } + + /** + * Setter for the strategy. + * @param strategy the strategy to set. + */ + public void setStrategy(String strategy) { + this.strategy = strategy; + } + + /** + * Getter for the tenant name. + * @return the tenant name. + */ + public String getTenantName() { + return tenantName; + } + + /** + * Setter for the tenant name. + * @param tenantName the tenant name to set. + */ + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + /** + * Getter for the user id attribute. + * @return the user id attribute. + */ + public String getUserIdAttribute() { + return userIdAttribute; + } + + /** + * Setter for the user id attribute. + * @param userIdAttribute the user id attribute to set. + */ + public void setUserIdAttribute(String userIdAttribute) { + this.userIdAttribute = userIdAttribute; + } + + /** + * Getter for the mapping. + * @return the mapping. + */ + public List getMapping() { + return mapping; + } + + /** + * Setter for the mapping. + * @param mapping the mapping to set. + */ + public void setMapping(List mapping) { + this.mapping = mapping; + } + + /** + * Getter for the created at. + * @return the created at. + */ + public String getCreatedAt() { + return createdAt; + } + + /** + * Setter for the created at. + * @param createdAt the created at to set. + */ + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + /** + * Getter for the updated on. + * @return the updated on. + */ + public String getUpdatedOn() { + return updatedOn; + } + + /** + * Setter for the updated on. + * @param updatedOn the updated on to set. + */ + public void setUpdatedOn(String updatedOn) { + this.updatedOn = updatedOn; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/connections/ScimTokenBaseResponse.java b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenBaseResponse.java new file mode 100644 index 000000000..951461054 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenBaseResponse.java @@ -0,0 +1,84 @@ +package com.auth0.json.mgmt.connections; + +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 ScimTokenBaseResponse { + @JsonProperty("token_id") + private String tokenId; + @JsonProperty("scopes") + private List scopes; + @JsonProperty("created_at") + private String createdAt; + @JsonProperty("valid_until") + private String validUntil; + + /** + * Getter for the token id. + * @return the token id. + */ + public String getTokenId() { + return tokenId; + } + + /** + * Setter for the token id. + * @param tokenId the token id to set. + */ + public void setTokenId(String tokenId) { + this.tokenId = tokenId; + } + + /** + * Getter for the scopes. + * @return the scopes. + */ + public List getScopes() { + return scopes; + } + + /** + * Setter for the scopes. + * @param scopes the scopes to set. + */ + public void setScopes(List scopes) { + this.scopes = scopes; + } + + /** + * Getter for the created at. + * @return the created at. + */ + public String getCreatedAt() { + return createdAt; + } + + /** + * Setter for the created at. + * @param createdAt the created at to set. + */ + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + /** + * Getter for the valid until. + * @return the valid until. + */ + public String getValidUntil() { + return validUntil; + } + + /** + * Setter for the valid until. + * @param validUntil the valid until to set. + */ + public void setValidUntil(String validUntil) { + this.validUntil = validUntil; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/connections/ScimTokenCreateResponse.java b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenCreateResponse.java new file mode 100644 index 000000000..ce332e0be --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenCreateResponse.java @@ -0,0 +1,28 @@ +package com.auth0.json.mgmt.connections; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class ScimTokenCreateResponse extends ScimTokenBaseResponse { + @JsonProperty("token") + private String token; + + /** + * Getter for the token. + * @return the token. + */ + public String getToken() { + return token; + } + + /** + * Setter for the token. + * @param token the token to set. + */ + public void setToken(String token) { + this.token = token; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/connections/ScimTokenRequest.java b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenRequest.java new file mode 100644 index 000000000..4a0f11e41 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenRequest.java @@ -0,0 +1,48 @@ +package com.auth0.json.mgmt.connections; + +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 ScimTokenRequest { + @JsonProperty("scopes") + private List scopes; + @JsonProperty("token_lifetime") + private Integer token_lifetime; + + /** + * Getter for the scopes. + * @return the scopes. + */ + public List getScopes() { + return scopes; + } + + /** + * Setter for the scopes. + * @param scopes the scopes to set. + */ + public void setScopes(List scopes) { + this.scopes = scopes; + } + + /** + * Getter for the token lifetime. + * @return the token lifetime. + */ + public Integer getToken_lifetime() { + return token_lifetime; + } + + /** + * Setter for the token lifetime. + * @param token_lifetime the token lifetime to set. + */ + public void setToken_lifetime(Integer token_lifetime) { + this.token_lifetime = token_lifetime; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/connections/ScimTokenResponse.java b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenResponse.java new file mode 100644 index 000000000..1cbea6390 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenResponse.java @@ -0,0 +1,28 @@ +package com.auth0.json.mgmt.connections; + +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 ScimTokenResponse extends ScimTokenBaseResponse { + @JsonProperty("last_used_at") + private String lastUsedAt; + + /** + * Getter for the last used at. + * @return the last used at. + */ + public String getLastUsedAt() { + return lastUsedAt; + } + + /** + * Setter for the last used at. + * @param lastUsedAt the last used at to set. + */ + public void setLastUsedAt(String lastUsedAt) { + this.lastUsedAt = lastUsedAt; + } +} diff --git a/src/test/java/com/auth0/client/MockServer.java b/src/test/java/com/auth0/client/MockServer.java index 78899bad2..93193de93 100644 --- a/src/test/java/com/auth0/client/MockServer.java +++ b/src/test/java/com/auth0/client/MockServer.java @@ -44,6 +44,10 @@ public class MockServer { public static final String MGMT_CONNECTIONS_LIST = "src/test/resources/mgmt/connections_list.json"; public static final String MGMT_CONNECTIONS_PAGED_LIST = "src/test/resources/mgmt/connections_paged_list.json"; public static final String MGMT_CONNECTION = "src/test/resources/mgmt/connection.json"; + public static final String MGMT_CONNECTION_SCIM_CONFIGURATION = "src/test/resources/mgmt/connection_scim_configuration.json"; + public static final String MGMT_CONNECTION_DEFAULT_SCIM_CONFIGURATION = "src/test/resources/mgmt/default_connection_scim_configuration.json"; + public static final String MGMT_CONNECTION_SCIM_TOKENS = "src/test/resources/mgmt/connection_scim_tokens.json"; + public static final String MGMT_CONNECTION_SCIM_TOKEN = "src/test/resources/mgmt/connection_scim_token.json"; public static final String MGMT_DEVICE_CREDENTIALS_LIST = "src/test/resources/mgmt/device_credentials_list.json"; public static final String MGMT_DEVICE_CREDENTIALS = "src/test/resources/mgmt/device_credentials.json"; public static final String MGMT_GRANTS_LIST = "src/test/resources/mgmt/grants_list.json"; diff --git a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java index f4cbf1cfe..fbb6bdfb8 100644 --- a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java @@ -1,13 +1,14 @@ package com.auth0.client.mgmt; import com.auth0.client.mgmt.filter.ConnectionFilter; -import com.auth0.json.mgmt.connections.Connection; -import com.auth0.json.mgmt.connections.ConnectionsPage; +import com.auth0.json.mgmt.connections.*; import com.auth0.net.Request; import com.auth0.net.client.HttpMethod; import okhttp3.mockwebserver.RecordedRequest; import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import static com.auth0.AssertsUtil.verifyThrows; @@ -232,4 +233,289 @@ public void shouldDeleteConnectionUser() throws Exception { assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); assertThat(recordedRequest, hasQueryParameter("email", "user@domain.com")); } + + @Test + public void shouldThrowOnGetScimConfigurationWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().getScimConfiguration(null), + "'connection id' cannot be null!"); + } + + @Test + public void shouldGetScimConfiguration() throws Exception { + Request request = api.connections().getScimConfiguration("1"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTION_SCIM_CONFIGURATION, 200); + ScimConfigurationResponse response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections/1/scim-configuration")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + } + + @Test + public void shouldThrowOnDeleteScimConfigurationWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().deleteScimConfiguration(null), + "'connection id' cannot be null!"); + } + + @Test + public void shouldDeleteScimConfiguration() throws Exception { + Request request = api.connections().deleteScimConfiguration("1"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTION_SCIM_CONFIGURATION, 200); + request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/connections/1/scim-configuration")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + } + + @Test + public void shouldThrowOnUpdateScimConfigurationWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().updateScimConfiguration(null, null), + "'connection id' cannot be null!"); + } + + @Test + public void shouldThrowOnUpdateScimConfigurationWithNullScimConfigurationRequest() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().updateScimConfiguration("1", null), + "'scim configuration request' cannot be null!"); + } + + @Test + public void shouldThrowOnUpdateScimConfigurationWithNullUserIdAttribute() { + ScimConfigurationRequest request = new ScimConfigurationRequest(); + request.setMapping(getMappings()); + + verifyThrows(IllegalArgumentException.class, + () -> api.connections().updateScimConfiguration("1", request), + "'user id attribute' cannot be null!"); + } + + @Test + public void shouldThrowOnUpdateScimConfigurationWithNullMapping() { + ScimConfigurationRequest request = new ScimConfigurationRequest(); + request.setUserIdAttribute("externalId"); + + verifyThrows(IllegalArgumentException.class, + () -> api.connections().updateScimConfiguration("1", request), + "'mapping' cannot be null!"); + } + + @Test + public void shouldUpdateScimConfiguration() throws Exception { + ScimConfigurationRequest scimConfigurationRequest = getScimConfiguration(); + Request request = api.connections().updateScimConfiguration("1", scimConfigurationRequest); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTION_SCIM_CONFIGURATION, 200); + ScimConfigurationResponse response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.PATCH, "/api/v2/connections/1/scim-configuration")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + Map body = bodyFromRequest(recordedRequest); + assertThat(body.size(), is(2)); + assertThat(body, hasEntry("user_id_attribute", "externalId")); + assertThat(body, hasKey("mapping")); + + assertThat(response, is(notNullValue())); + } + + @Test + public void shouldThrowOnCreateScimConfigurationWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().createScimConfiguration(null, getScimConfiguration()), + "'connection id' cannot be null!"); + } + + @Test + public void shouldCreateScimConfiguration() throws Exception { + ScimConfigurationRequest scimConfigurationRequest = getScimConfiguration(); + Request request = api.connections().createScimConfiguration("1", scimConfigurationRequest); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTION_SCIM_CONFIGURATION, 200); + ScimConfigurationResponse response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/api/v2/connections/1/scim-configuration")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + Map body = bodyFromRequest(recordedRequest); + assertThat(body.size(), is(2)); + assertThat(body, hasEntry("user_id_attribute", "externalId")); + assertThat(body, hasKey("mapping")); + + assertThat(response, is(notNullValue())); + } + + @Test + public void shouldThrowOnGetDefaultScimConfigurationWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().createScimConfiguration(null, getScimConfiguration()), + "'connection id' cannot be null!"); + } + + @Test + public void shouldGetDefaultScimConfiguration() throws Exception { + Request request = api.connections().getDefaultScimConfiguration("1"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTION_DEFAULT_SCIM_CONFIGURATION, 200); + Mapping response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections/1/scim-configuration/default-mapping")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + } + + @Test + public void shouldThrowOnGetScimTokenWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().getScimToken(null), + "'connection id' cannot be null!"); + } + + @Test + public void shouldGetScimToken() throws Exception { + Request> request = api.connections().getScimToken("1"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTION_SCIM_TOKENS, 200); + List response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections/1/scim-configuration/tokens")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + assertThat(response.size(), is(2)); + } + + @Test + public void shouldThrowOnCreateScimTokenWithNullId() { + ScimTokenRequest request = getScimToken(); + + verifyThrows(IllegalArgumentException.class, + () -> api.connections().createScimToken(null, request), + "'connection id' cannot be null!"); + } + + @Test + public void shouldThrowOnCreateScimTokenWithNullScimTokenRequest() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().createScimToken("1", null), + "'scim token request' cannot be null!"); + } + + @Test + public void shouldCreateScimToken() throws Exception { + ScimTokenRequest scimTokenRequest = getScimToken(); + Request request = api.connections().createScimToken("1", scimTokenRequest); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTION_SCIM_TOKEN, 200); + ScimTokenBaseResponse response = request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/api/v2/connections/1/scim-configuration/tokens")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + Map body = bodyFromRequest(recordedRequest); + assertThat(body.size(), is(2)); + assertThat(body, hasKey("scopes")); + + assertThat(response, is(notNullValue())); + } + + @Test + public void shouldThrowOnDeleteScimTokenWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().deleteScimToken(null, "1"), + "'connection id' cannot be null!"); + } + + @Test + public void shouldThrowOnDeleteScimTokenWithNullTokenId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().deleteScimToken("1", null), + "'token id' cannot be null!"); + } + + @Test + public void shouldDeleteScimToken() throws Exception { + Request request = api.connections().deleteScimToken("1", "1"); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTION_SCIM_CONFIGURATION, 200); + request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/connections/1/scim-configuration/tokens/1")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + } + + @Test + public void shouldThrowOnCheckConnectionStatusWithNullId() { + verifyThrows(IllegalArgumentException.class, + () -> api.connections().checkConnectionStatus(null), + "'connection id' cannot be null!"); + } + + @Test + public void shouldCheckConnectionStatus() throws Exception { + Request request = api.connections().checkConnectionStatus("1"); + assertThat(request, is(notNullValue())); + + server.emptyResponse(204); + request.execute().getBody(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections/1/status")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + } + + private ScimTokenRequest getScimToken() { + ScimTokenRequest request = new ScimTokenRequest(); + List scopes = new ArrayList<>(); + scopes.add("get:users"); + request.setScopes(scopes); + request.setToken_lifetime(1000); + return request; + } + + private ScimConfigurationRequest getScimConfiguration() { + ScimConfigurationRequest request = new ScimConfigurationRequest(); + request.setUserIdAttribute("externalId"); + request.setMapping(getMappings()); + return request; + } + + private List getMappings() { + List mappingList = new ArrayList<>(); + mappingList.add(new Mapping("user_id", "id")); + return mappingList; + } + } diff --git a/src/test/java/com/auth0/json/mgmt/ConnectionTest.java b/src/test/java/com/auth0/json/mgmt/connections/ConnectionTest.java similarity index 97% rename from src/test/java/com/auth0/json/mgmt/ConnectionTest.java rename to src/test/java/com/auth0/json/mgmt/connections/ConnectionTest.java index f0d133e37..2d994bcd0 100644 --- a/src/test/java/com/auth0/json/mgmt/ConnectionTest.java +++ b/src/test/java/com/auth0/json/mgmt/connections/ConnectionTest.java @@ -1,8 +1,7 @@ -package com.auth0.json.mgmt; +package com.auth0.json.mgmt.connections; import com.auth0.json.JsonMatcher; import com.auth0.json.JsonTest; -import com.auth0.json.mgmt.connections.Connection; import org.junit.jupiter.api.Test; import java.util.Arrays; diff --git a/src/test/java/com/auth0/json/mgmt/connections/ScimConfigurationRequestTest.java b/src/test/java/com/auth0/json/mgmt/connections/ScimConfigurationRequestTest.java new file mode 100644 index 000000000..2eaf80151 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/connections/ScimConfigurationRequestTest.java @@ -0,0 +1,51 @@ +package com.auth0.json.mgmt.connections; + +import com.auth0.json.JsonMatcher; +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class ScimConfigurationRequestTest extends JsonTest { + + private final static String json = "{\n" + + " \"user_id_attribute\": \"externalId\",\n" + + " \"mapping\": [\n" + + " {\n" + + " \"auth0\": \"preferred_username\",\n" + + " \"scim\": \"userName\"\n" + + " }\n" + + " ]\n" + + "}"; + + @Test + public void serialize() throws Exception { + ScimConfigurationRequest request = new ScimConfigurationRequest(); + request.setUserIdAttribute("externalId"); + List mappingList = new ArrayList<>(); + Mapping mapping = new Mapping("preferred_username", "userName"); + mappingList.add(mapping); + request.setMapping(mappingList); + + String serialized = toJSON(request); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, JsonMatcher.hasEntry("user_id_attribute", "externalId")); + assertThat(serialized, JsonMatcher.hasEntry("mapping", notNullValue())); + assertThat(serialized, containsString("\"mapping\":[{\"auth0\":\"preferred_username\",\"scim\":\"userName\"}]")); + } + + @Test + public void deserialize() throws Exception { + ScimConfigurationRequest deserialized = fromJSON(json, ScimConfigurationRequest.class); + + assertThat(deserialized, is(notNullValue())); + + assertThat(deserialized.getUserIdAttribute(), is("externalId")); + assertThat(deserialized.getMapping().get(0).getAuth0(), is("preferred_username")); + assertThat(deserialized.getMapping().get(0).getScim(), is("userName")); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/connections/ScimConfigurationResponseTest.java b/src/test/java/com/auth0/json/mgmt/connections/ScimConfigurationResponseTest.java new file mode 100644 index 000000000..5aa5f5855 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/connections/ScimConfigurationResponseTest.java @@ -0,0 +1,66 @@ +package com.auth0.json.mgmt.connections; + +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static com.auth0.json.JsonMatcher.hasEntry; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class ScimConfigurationResponseTest extends JsonTest { + private final static String SCIM_CONFIGURATION_RESPONSE_JSON = "src/test/resources/mgmt/connection_scim_configuration.json"; + + @Test + public void deserialize() throws Exception { + ScimConfigurationResponse deserialized = fromJSON(readTextFile(SCIM_CONFIGURATION_RESPONSE_JSON), ScimConfigurationResponse.class); + + assertThat(deserialized.getTenantName(), is("dev-1")); + assertThat(deserialized.getConnectionId(), is("con_0000000000000001")); + assertThat(deserialized.getConnectionName(), is("New Connection")); + assertThat(deserialized.getStrategy(), is("okta")); + assertThat(deserialized.getMapping().get(0).getAuth0(), is("preferred_username")); + assertThat(deserialized.getMapping().get(0).getScim(), is("userName")); + assertThat(deserialized.getMapping().get(1).getAuth0(), is("email")); + assertThat(deserialized.getMapping().get(1).getScim(), is("emails[primary eq true].value")); + assertThat(deserialized.getUpdatedOn(), is("2025-01-22T11:56:24.461Z")); + assertThat(deserialized.getCreatedAt(), is("2025-01-22T11:56:24.461Z")); + assertThat(deserialized.getUserIdAttribute(), is("externalId")); + } + + @Test + public void serialize() throws Exception { + ScimConfigurationResponse scimConfigurationResponse = new ScimConfigurationResponse(); + scimConfigurationResponse.setTenantName("dev-1"); + scimConfigurationResponse.setConnectionId("con_0000000000000001"); + scimConfigurationResponse.setConnectionName("New Connection"); + scimConfigurationResponse.setStrategy("okta"); + + List mappingList = new ArrayList<>(); + Mapping mapping1 = new Mapping("preferred_username", "userName"); + mappingList.add(mapping1); + Mapping mapping2 = new Mapping("email", "emails[primary eq true].value"); + mappingList.add(mapping2); + scimConfigurationResponse.setMapping(mappingList); + + scimConfigurationResponse.setUpdatedOn("2025-01-22T11:56:24.461Z"); + scimConfigurationResponse.setCreatedAt("2025-01-22T11:56:24.461Z"); + scimConfigurationResponse.setUserIdAttribute("externalId"); + + String serialized = toJSON(scimConfigurationResponse); + assertThat(serialized, is(notNullValue())); + + assertThat(serialized, hasEntry("tenant_name", "dev-1")); + assertThat(serialized, hasEntry("connection_id", "con_0000000000000001")); + assertThat(serialized, hasEntry("connection_name", "New Connection")); + assertThat(serialized, hasEntry("strategy", "okta")); + assertThat(serialized, hasEntry("mapping", notNullValue())); + assertThat(serialized, containsString("\"mapping\":[{\"auth0\":\"preferred_username\",\"scim\":\"userName\"},{\"auth0\":\"email\",\"scim\":\"emails[primary eq true].value\"}]")); + assertThat(serialized, hasEntry("updated_on", "2025-01-22T11:56:24.461Z")); + assertThat(serialized, hasEntry("created_at", "2025-01-22T11:56:24.461Z")); + assertThat(serialized, hasEntry("user_id_attribute", "externalId")); + } +} + diff --git a/src/test/java/com/auth0/json/mgmt/connections/ScimTokenBaseResponseTest.java b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenBaseResponseTest.java new file mode 100644 index 000000000..98716f53d --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenBaseResponseTest.java @@ -0,0 +1,56 @@ +package com.auth0.json.mgmt.connections; + +import com.auth0.json.JsonMatcher; +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static com.auth0.json.JsonMatcher.hasEntry; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class ScimTokenBaseResponseTest extends JsonTest { + + private final static String json = "{\n" + + " \"token_id\": \"tok_000000001\",\n" + + " \"scopes\": [\n" + + " \"get:users\"\n" + + " ],\n" + + " \"created_at\": \"2025-01-23T12:34:46.321Z\",\n" + + " \"valid_until\": \"2025-01-23T12:51:26.321Z\"\n" + + "}"; + + + @Test + public void serialize() throws Exception { + ScimTokenBaseResponse request = new ScimTokenBaseResponse(); + request.setTokenId("tok_000000001"); + List scopes = new ArrayList<>(); + scopes.add("get:users"); + request.setScopes(scopes); + request.setCreatedAt("2025-01-23T12:34:46.321Z"); + request.setValidUntil("2025-01-23T12:51:26.321Z"); + + String serialized = toJSON(request); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, JsonMatcher.hasEntry("token_id", "tok_000000001")); + assertThat(serialized, hasEntry("scopes", notNullValue())); + assertThat(serialized, containsString("\"scopes\":[\"get:users\"]")); + assertThat(serialized, JsonMatcher.hasEntry("created_at", "2025-01-23T12:34:46.321Z")); + assertThat(serialized, JsonMatcher.hasEntry("valid_until", "2025-01-23T12:51:26.321Z")); + } + + @Test + public void deserialize() throws Exception { + ScimTokenBaseResponse deserialized = fromJSON(json, ScimTokenBaseResponse.class); + + assertThat(deserialized, is(notNullValue())); + + assertThat(deserialized.getTokenId(), is("tok_000000001")); + assertThat(deserialized.getScopes().get(0), is("get:users")); + assertThat(deserialized.getCreatedAt(), is("2025-01-23T12:34:46.321Z")); + assertThat(deserialized.getValidUntil(), is("2025-01-23T12:51:26.321Z")); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/connections/ScimTokenCreateResponseTest.java b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenCreateResponseTest.java new file mode 100644 index 000000000..45287acb8 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenCreateResponseTest.java @@ -0,0 +1,48 @@ +package com.auth0.json.mgmt.connections; + +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static com.auth0.json.JsonMatcher.hasEntry; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class ScimTokenCreateResponseTest extends JsonTest { + public static final String CONNECTION_SCIM_TOKEN = "src/test/resources/mgmt/connection_scim_token.json"; + + @Test + public void deserialize() throws Exception { + ScimTokenCreateResponse deserialized = fromJSON(readTextFile(CONNECTION_SCIM_TOKEN), ScimTokenCreateResponse.class); + + assertThat(deserialized.getTokenId(), is("tok_000000001")); + assertThat(deserialized.getToken(), is("tok_iwioqiwoqoqiwqoiwqwi")); + assertThat(deserialized.getScopes().get(0), is("get:users")); + assertThat(deserialized.getCreatedAt(), is("2025-01-23T12:34:46.321Z")); + assertThat(deserialized.getValidUntil(), is("2025-01-23T12:51:26.321Z")); + } + + @Test + public void serialize() throws Exception { + ScimTokenCreateResponse serialize = new ScimTokenCreateResponse(); + serialize.setTokenId("tok_000000001"); + serialize.setToken("tok_iwioqiwoqoqiwqoiwqwi"); + List scopes = new ArrayList<>(); + scopes.add("get:users"); + serialize.setScopes(scopes); + serialize.setCreatedAt("2025-01-23T12:34:46.321Z"); + serialize.setValidUntil("2025-01-23T12:51:26.321Z"); + + String serialized = toJSON(serialize); + assertThat(serialized, is(notNullValue())); + + assertThat(serialized, hasEntry("token_id", "tok_000000001")); + assertThat(serialized, hasEntry("token", "tok_iwioqiwoqoqiwqoiwqwi")); + assertThat(serialized, hasEntry("scopes", notNullValue())); + assertThat(serialized, containsString("\"scopes\":[\"get:users\"]")); + assertThat(serialized, hasEntry("created_at", "2025-01-23T12:34:46.321Z")); + assertThat(serialized, hasEntry("valid_until", "2025-01-23T12:51:26.321Z")); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/connections/ScimTokenRequestTest.java b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenRequestTest.java new file mode 100644 index 000000000..3b20ad92a --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenRequestTest.java @@ -0,0 +1,44 @@ +package com.auth0.json.mgmt.connections; + +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static com.auth0.json.JsonMatcher.hasEntry; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class ScimTokenRequestTest extends JsonTest { + + public static final String json = "{\n" + + " \"scopes\": [\"get:users\"],\n" + + " \"token_lifetime\": 1000\n" + + "}"; + + @Test + public void serialize() throws Exception { + ScimTokenRequest request = new ScimTokenRequest(); + request.setToken_lifetime(1000); + List scopes = new ArrayList<>(); + scopes.add("get:users"); + request.setScopes(scopes); + + String serialized = toJSON(request); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, hasEntry("scopes", notNullValue())); + assertThat(serialized, containsString("\"scopes\":[\"get:users\"]")); + assertThat(serialized, hasEntry("token_lifetime", 1000)); + } + + @Test + public void deserialize() throws Exception { + ScimTokenRequest deserialized = fromJSON(json, ScimTokenRequest.class); + + assertThat(deserialized, is(notNullValue())); + + assertThat(deserialized.getToken_lifetime(), is(1000)); + assertThat(deserialized.getScopes().get(0), is("get:users")); + } +} diff --git a/src/test/java/com/auth0/json/mgmt/connections/ScimTokenResponseTest.java b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenResponseTest.java new file mode 100644 index 000000000..5924570b2 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenResponseTest.java @@ -0,0 +1,60 @@ +package com.auth0.json.mgmt.connections; + +import com.auth0.json.JsonMatcher; +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static com.auth0.json.JsonMatcher.hasEntry; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; + +public class ScimTokenResponseTest extends JsonTest { + private final static String json = "{\n" + + " \"token_id\": \"tok_000000001\",\n" + + " \"scopes\": [\n" + + " \"get:users\"\n" + + " ],\n" + + " \"created_at\": \"2025-01-23T12:34:46.321Z\",\n" + + " \"valid_until\": \"2025-01-23T12:51:26.321Z\",\n" + + " \"last_used_at\": \"2025-01-23T12:51:26.321Z\"\n" + + "}"; + + + @Test + public void serialize() throws Exception { + ScimTokenResponse request = new ScimTokenResponse(); + request.setTokenId("tok_000000001"); + List scopes = new ArrayList<>(); + scopes.add("get:users"); + request.setScopes(scopes); + request.setCreatedAt("2025-01-23T12:34:46.321Z"); + request.setValidUntil("2025-01-23T12:51:26.321Z"); + request.setLastUsedAt("2025-01-23T12:51:26.321Z"); + + String serialized = toJSON(request); + assertThat(serialized, is(notNullValue())); + assertThat(serialized, JsonMatcher.hasEntry("token_id", "tok_000000001")); + assertThat(serialized, hasEntry("scopes", notNullValue())); + assertThat(serialized, containsString("\"scopes\":[\"get:users\"]")); + assertThat(serialized, JsonMatcher.hasEntry("created_at", "2025-01-23T12:34:46.321Z")); + assertThat(serialized, JsonMatcher.hasEntry("valid_until", "2025-01-23T12:51:26.321Z")); + assertThat(serialized, JsonMatcher.hasEntry("last_used_at", "2025-01-23T12:51:26.321Z")); + } + + @Test + public void deserialize() throws Exception { + ScimTokenResponse deserialized = fromJSON(json, ScimTokenResponse.class); + + assertThat(deserialized, is(notNullValue())); + + assertThat(deserialized.getTokenId(), is("tok_000000001")); + assertThat(deserialized.getScopes().get(0), is("get:users")); + assertThat(deserialized.getCreatedAt(), is("2025-01-23T12:34:46.321Z")); + assertThat(deserialized.getValidUntil(), is("2025-01-23T12:51:26.321Z")); + assertThat(deserialized.getLastUsedAt(), is("2025-01-23T12:51:26.321Z")); + } +} diff --git a/src/test/resources/mgmt/connection_scim_configuration.json b/src/test/resources/mgmt/connection_scim_configuration.json new file mode 100644 index 000000000..e975aba6f --- /dev/null +++ b/src/test/resources/mgmt/connection_scim_configuration.json @@ -0,0 +1,19 @@ +{ + "tenant_name": "dev-1", + "connection_id": "con_0000000000000001", + "connection_name": "New Connection", + "strategy": "okta", + "mapping": [ + { + "scim": "userName", + "auth0": "preferred_username" + }, + { + "scim": "emails[primary eq true].value", + "auth0": "email" + } + ], + "updated_on": "2025-01-22T11:56:24.461Z", + "created_at": "2025-01-22T11:56:24.461Z", + "user_id_attribute": "externalId" +} diff --git a/src/test/resources/mgmt/connection_scim_token.json b/src/test/resources/mgmt/connection_scim_token.json new file mode 100644 index 000000000..13de59eed --- /dev/null +++ b/src/test/resources/mgmt/connection_scim_token.json @@ -0,0 +1,9 @@ +{ + "token_id": "tok_000000001", + "token": "tok_iwioqiwoqoqiwqoiwqwi", + "scopes": [ + "get:users" + ], + "created_at": "2025-01-23T12:34:46.321Z", + "valid_until": "2025-01-23T12:51:26.321Z" +} diff --git a/src/test/resources/mgmt/connection_scim_tokens.json b/src/test/resources/mgmt/connection_scim_tokens.json new file mode 100644 index 000000000..421689d93 --- /dev/null +++ b/src/test/resources/mgmt/connection_scim_tokens.json @@ -0,0 +1,21 @@ +[ + { + "token_id": "tok_000000001", + "created_at": "2025-01-23T12:34:46.321Z", + "scopes": [ + "get:users" + ], + "valid_until": "2025-01-23T12:51:26.321Z" + }, + { + "token_id": "tok_000000002", + "created_at": "2025-01-22T12:09:23.313Z", + "scopes": [ + "get:users", + "post:users", + "patch:users", + "delete:users", + "put:users" + ] + } +] diff --git a/src/test/resources/mgmt/default_connection_scim_configuration.json b/src/test/resources/mgmt/default_connection_scim_configuration.json new file mode 100644 index 000000000..ceccc8793 --- /dev/null +++ b/src/test/resources/mgmt/default_connection_scim_configuration.json @@ -0,0 +1,12 @@ +{ + "mapping": [ + { + "auth0": "preferred_username", + "scim": "userName" + }, + { + "auth0": "email", + "scim": "emails[primary eq true].value" + } + ] +} From 7b85db04a058e2dc271e5d307c4745b24d210e6e Mon Sep 17 00:00:00 2001 From: tanya732 Date: Fri, 24 Jan 2025 13:53:23 +0530 Subject: [PATCH 2/3] modified name --- .../json/mgmt/connections/ScimTokenRequest.java | 12 ++++++------ .../com/auth0/client/mgmt/ConnectionsEntityTest.java | 2 +- .../json/mgmt/connections/ScimTokenRequestTest.java | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/auth0/json/mgmt/connections/ScimTokenRequest.java b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenRequest.java index 4a0f11e41..3d2d387b8 100644 --- a/src/main/java/com/auth0/json/mgmt/connections/ScimTokenRequest.java +++ b/src/main/java/com/auth0/json/mgmt/connections/ScimTokenRequest.java @@ -12,7 +12,7 @@ public class ScimTokenRequest { @JsonProperty("scopes") private List scopes; @JsonProperty("token_lifetime") - private Integer token_lifetime; + private Integer tokenLifetime; /** * Getter for the scopes. @@ -34,15 +34,15 @@ public void setScopes(List scopes) { * Getter for the token lifetime. * @return the token lifetime. */ - public Integer getToken_lifetime() { - return token_lifetime; + public Integer getTokenLifetime() { + return tokenLifetime; } /** * Setter for the token lifetime. - * @param token_lifetime the token lifetime to set. + * @param tokenLifetime the token lifetime to set. */ - public void setToken_lifetime(Integer token_lifetime) { - this.token_lifetime = token_lifetime; + public void setTokenLifetime(Integer tokenLifetime) { + this.tokenLifetime = tokenLifetime; } } diff --git a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java index fbb6bdfb8..49613f0ae 100644 --- a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java @@ -501,7 +501,7 @@ private ScimTokenRequest getScimToken() { List scopes = new ArrayList<>(); scopes.add("get:users"); request.setScopes(scopes); - request.setToken_lifetime(1000); + request.setTokenLifetime(1000); return request; } diff --git a/src/test/java/com/auth0/json/mgmt/connections/ScimTokenRequestTest.java b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenRequestTest.java index 3b20ad92a..ca2769794 100644 --- a/src/test/java/com/auth0/json/mgmt/connections/ScimTokenRequestTest.java +++ b/src/test/java/com/auth0/json/mgmt/connections/ScimTokenRequestTest.java @@ -20,7 +20,7 @@ public class ScimTokenRequestTest extends JsonTest { @Test public void serialize() throws Exception { ScimTokenRequest request = new ScimTokenRequest(); - request.setToken_lifetime(1000); + request.setTokenLifetime(1000); List scopes = new ArrayList<>(); scopes.add("get:users"); request.setScopes(scopes); @@ -38,7 +38,7 @@ public void deserialize() throws Exception { assertThat(deserialized, is(notNullValue())); - assertThat(deserialized.getToken_lifetime(), is(1000)); + assertThat(deserialized.getTokenLifetime(), is(1000)); assertThat(deserialized.getScopes().get(0), is("get:users")); } } From 7eb5e985ef4cda65f5b84b2892ba355f6edbd469 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Fri, 24 Jan 2025 14:52:58 +0530 Subject: [PATCH 3/3] small fix --- .../auth0/client/mgmt/ConnectionsEntity.java | 4 +- .../DefaultScimMappingResponse.java | 47 +++++++++++++++++++ .../client/mgmt/ConnectionsEntityTest.java | 4 +- 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/auth0/json/mgmt/connections/DefaultScimMappingResponse.java diff --git a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java index b19775a2f..43c07cfaa 100644 --- a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java +++ b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java @@ -264,7 +264,7 @@ public Request createScimConfiguration(String connect * @param connectionId the connection id. * @return a Request to execute. */ - public Request getDefaultScimConfiguration(String connectionId){ + public Request getDefaultScimConfiguration(String connectionId){ Asserts.assertNotNull(connectionId, "connection id"); String url = baseUrl @@ -275,7 +275,7 @@ public Request getDefaultScimConfiguration(String connectionId){ .addPathSegment("default-mapping") .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/connections/DefaultScimMappingResponse.java b/src/main/java/com/auth0/json/mgmt/connections/DefaultScimMappingResponse.java new file mode 100644 index 000000000..481e7df75 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/connections/DefaultScimMappingResponse.java @@ -0,0 +1,47 @@ +package com.auth0.json.mgmt.connections; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class DefaultScimMappingResponse { + @JsonProperty("mapping") + private List mapping; + + /** + * Creates a new instance. + */ + @JsonCreator + public DefaultScimMappingResponse() { + } + + /** + * Creates a new instance with the given mapping. + * @param mapping the mapping attribute. + */ + @JsonCreator + public DefaultScimMappingResponse(@JsonProperty("mapping") List mapping) { + this.mapping = mapping; + } + + /** + * Getter for the mapping attribute. + * @return the mapping attribute. + */ + public List getMapping() { + return mapping; + } + + /** + * Setter for the mapping attribute. + * @param mapping the mapping attribute to set. + */ + public void setMapping(List mapping) { + this.mapping = mapping; + } +} diff --git a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java index 49613f0ae..211d13cb3 100644 --- a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java @@ -372,11 +372,11 @@ public void shouldThrowOnGetDefaultScimConfigurationWithNullId() { @Test public void shouldGetDefaultScimConfiguration() throws Exception { - Request request = api.connections().getDefaultScimConfiguration("1"); + Request request = api.connections().getDefaultScimConfiguration("1"); assertThat(request, is(notNullValue())); server.jsonResponse(MGMT_CONNECTION_DEFAULT_SCIM_CONFIGURATION, 200); - Mapping response = request.execute().getBody(); + DefaultScimMappingResponse response = request.execute().getBody(); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections/1/scim-configuration/default-mapping"));