diff --git a/src/main/java/com/auth0/client/mgmt/SelfServiceProfilesEntity.java b/src/main/java/com/auth0/client/mgmt/SelfServiceProfilesEntity.java index cf1cbdfe5..38d9373b3 100644 --- a/src/main/java/com/auth0/client/mgmt/SelfServiceProfilesEntity.java +++ b/src/main/java/com/auth0/client/mgmt/SelfServiceProfilesEntity.java @@ -1,10 +1,8 @@ package com.auth0.client.mgmt; +import com.auth0.client.auth.AuthAPI; import com.auth0.client.mgmt.filter.PageBasedPaginationFilter; -import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfile; -import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponse; -import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponsePage; -import com.auth0.json.mgmt.selfserviceprofiles.SsoAccessTicketResponse; +import com.auth0.json.mgmt.selfserviceprofiles.*; import com.auth0.net.*; import com.auth0.net.client.Auth0HttpClient; import com.auth0.net.client.HttpMethod; @@ -187,6 +185,32 @@ public Request setCustomText(String id, String language, String page, Ob return request; } + /** + * Create a new SSO access ticket. + * A token with {@code create:sso_access_tickets} scope is needed + * @see https://auth0.com/docs/api/management/v2#!/self-service-profiles/post-sso-ticket + * @param id the self-service profile ID. + * @param requestBody the payload. + * @return a Request to execute. + */ + public Request createSsoAccessTicket(String id, SsoAccessTicketRequest requestBody) { + Asserts.assertNotNull(id, "id"); + Asserts.assertNotNull(requestBody, "request body"); + + HttpUrl.Builder builder = baseUrl.newBuilder() + .addPathSegments(ORGS_PATH) + .addPathSegment(id) + .addPathSegment("sso-ticket"); + + String url = builder.build().toString(); + + BaseRequest request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference() { + }); + request.setBody(requestBody); + return request; + } + + /** * Create a new SSO access ticket. * A token with {@code create:sso_access_tickets} scope is needed @@ -194,7 +218,10 @@ public Request setCustomText(String id, String language, String page, Ob * @param id the self-service profile ID. * @param payload the payload. * @return a Request to execute. + * + * @deprecated Use {@link #createSsoAccessTicket(String, SsoAccessTicketRequest)} to create sso access ticket. */ + @Deprecated public Request createSsoAccessTicket(String id, Object payload) { Asserts.assertNotNull(id, "id"); Asserts.assertNotNull(payload, "payload"); @@ -203,7 +230,6 @@ public Request createSsoAccessTicket(String id, Object .addPathSegments(ORGS_PATH) .addPathSegment(id) .addPathSegment("sso-ticket"); - String url = builder.build().toString(); BaseRequest request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference() { diff --git a/src/main/java/com/auth0/json/mgmt/connections/Connection.java b/src/main/java/com/auth0/json/mgmt/connections/Connection.java index d39574a53..5cf63cc8d 100644 --- a/src/main/java/com/auth0/json/mgmt/connections/Connection.java +++ b/src/main/java/com/auth0/json/mgmt/connections/Connection.java @@ -34,6 +34,10 @@ public class Connection { private Map metadata; @JsonProperty("realms") private List realms; + @JsonProperty("show_as_button") + private boolean showAsButton; + @JsonProperty("is_domain_connection") + private boolean isDomainConnection; public Connection() { } @@ -183,4 +187,38 @@ public List getRealms() { public void setRealms(List realms) { this.realms = realms; } + + /** + * Getter for the show as button flag. + * + * @return the show as button flag. + */ + public boolean isShowAsButton() { + return showAsButton; + } + + /** + * Setter for the show as button flag. + * + * @param showAsButton the show as button flag to set. + */ + public void setShowAsButton(boolean showAsButton) { + this.showAsButton = showAsButton; + } + + /** + * Getter for the domain connection flag. + * @return the domain connection flag. + */ + public boolean isDomainConnection() { + return isDomainConnection; + } + + /** + * Setter for the domain connection flag. + * @param domainConnection the domain connection flag to set. + */ + public void setDomainConnection(boolean domainConnection) { + isDomainConnection = domainConnection; + } } diff --git a/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/DomainAliasesConfig.java b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/DomainAliasesConfig.java new file mode 100644 index 000000000..2502578b3 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/DomainAliasesConfig.java @@ -0,0 +1,29 @@ +package com.auth0.json.mgmt.selfserviceprofiles; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class DomainAliasesConfig { + @JsonProperty("domain_verification") + private String domainVerification; + + /** + * Creates a new instance of the DomainAliasesConfig class. + */ + @JsonCreator + public DomainAliasesConfig(@JsonProperty("domain_verification") String domainVerification) { + this.domainVerification = domainVerification; + } + + /** + * Getter for the domain verification. + * @return the domain verification. + */ + public String getDomainVerification() { + return domainVerification; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/EnabledOrganizations.java b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/EnabledOrganizations.java new file mode 100644 index 000000000..fada60683 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/EnabledOrganizations.java @@ -0,0 +1,64 @@ +package com.auth0.json.mgmt.selfserviceprofiles; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnabledOrganizations { + @JsonProperty("organization_id") + private String organizationId; + @JsonProperty("assign_membership_on_login") + private boolean assignMembershipOnLogin; + @JsonProperty("show_as_button") + private boolean showAsButton; + + /** + * Getter for the organization id. + * @return the organization id. + */ + public String getOrganizationId() { + return organizationId; + } + + /** + * Setter for the organization id. + * @param organizationId the organization id to set. + */ + public void setOrganizationId(String organizationId) { + this.organizationId = organizationId; + } + + /** + * Getter for the assign membership on login. + * @return the assign membership on login. + */ + public boolean isAssignMembershipOnLogin() { + return assignMembershipOnLogin; + } + + /** + * Setter for the assign membership on login. + * @param assignMembershipOnLogin the assign membership on login to set. + */ + public void setAssignMembershipOnLogin(boolean assignMembershipOnLogin) { + this.assignMembershipOnLogin = assignMembershipOnLogin; + } + + /** + * Getter for the show as button. + * @return the show as button. + */ + public boolean isShowAsButton() { + return showAsButton; + } + + /** + * Setter for the show as button. + * @param showAsButton the show as button to set. + */ + public void setShowAsButton(boolean showAsButton) { + this.showAsButton = showAsButton; + } +} diff --git a/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequest.java b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequest.java new file mode 100644 index 000000000..d521bec42 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequest.java @@ -0,0 +1,121 @@ +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; +import java.util.Map; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class SsoAccessTicketRequest { + @JsonProperty("connection_id") + private String connectionId; + @JsonProperty("connection_config") + private Map connectionConfig; + @JsonProperty("enabled_clients") + private List enabledClients; + @JsonProperty("enabled_organizations") + private List enabledOrganizations; + @JsonProperty("ttl_sec") + private int ttlSec; + @JsonProperty("domain_aliases_config") + private DomainAliasesConfig domainAliasesConfig; + + /** + * Creates a new instance. + * @return the new instance. + */ + public String getConnectionId() { + return connectionId; + } + + /** + * Sets the connection ID. + * @param connectionId the connection ID to set. + */ + public void setConnectionId(String connectionId) { + this.connectionId = connectionId; + } + + /** + * Getter for the connection configuration. + * @return the connection configuration. + */ + public Map getConnectionConfig() { + return connectionConfig; + } + + /** + * Setter for the connection configuration. + * @param connectionConfig the connection configuration to set. + */ + public void setConnectionConfig(Map connectionConfig) { + this.connectionConfig = connectionConfig; + } + + /** + * Getter for the enabled clients. + * @return the enabled clients. + */ + public List getEnabledClients() { + return enabledClients; + } + + /** + * Setter for the enabled clients. + * @param enabledClients the enabled clients to set. + */ + public void setEnabledClients(List enabledClients) { + this.enabledClients = enabledClients; + } + + /** + * Getter for the enabled organizations. + * @return the enabled organizations. + */ + public List getEnabledOrganizations() { + return enabledOrganizations; + } + + /** + * Setter for the enabled organizations. + * @param enabledOrganizations the enabled organizations to set. + */ + public void setEnabledOrganizations(List enabledOrganizations) { + this.enabledOrganizations = enabledOrganizations; + } + + /** + * Getter for the TTL in seconds. + * @return the TTL in seconds. + */ + public int getTtlSec() { + return ttlSec; + } + + /** + * Setter for the TTL in seconds. + * @param ttlSec the TTL in seconds to set. + */ + public void setTtlSec(int ttlSec) { + this.ttlSec = ttlSec; + } + + /** + * Getter for the domain aliases configuration. + * @return the domain aliases configuration. + */ + public DomainAliasesConfig getDomainAliasesConfig() { + return domainAliasesConfig; + } + + /** + * Setter for the domain aliases configuration. + * @param domainAliasesConfig the domain aliases configuration to set. + */ + public void setDomainAliasesConfig(DomainAliasesConfig domainAliasesConfig) { + this.domainAliasesConfig = domainAliasesConfig; + } +} diff --git a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java index 4e1149334..afcd0457f 100644 --- a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java @@ -188,7 +188,7 @@ public void shouldCreateConnection() throws Exception { assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); Map body = bodyFromRequest(recordedRequest); - assertThat(body.size(), is(2)); + assertThat(body.size(), is(5)); assertThat(body, hasEntry("name", "my-connection")); assertThat(body, hasEntry("strategy", "auth0")); @@ -244,7 +244,7 @@ public void shouldUpdateConnection() throws Exception { assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); Map body = bodyFromRequest(recordedRequest); - assertThat(body.size(), is(2)); + assertThat(body.size(), is(5)); assertThat(body, hasEntry("name", "my-connection")); assertThat(body, hasEntry("strategy", "auth0")); diff --git a/src/test/java/com/auth0/client/mgmt/SelfServiceProfilesEntityTest.java b/src/test/java/com/auth0/client/mgmt/SelfServiceProfilesEntityTest.java index 227bcfe07..08d66d578 100644 --- a/src/test/java/com/auth0/client/mgmt/SelfServiceProfilesEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/SelfServiceProfilesEntityTest.java @@ -1,10 +1,7 @@ package com.auth0.client.mgmt; import com.auth0.client.mgmt.filter.PageBasedPaginationFilter; -import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfile; -import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponse; -import com.auth0.json.mgmt.selfserviceprofiles.SelfServiceProfileResponsePage; -import com.auth0.json.mgmt.selfserviceprofiles.SsoAccessTicketResponse; +import com.auth0.json.mgmt.selfserviceprofiles.*; import com.auth0.net.Request; import com.auth0.net.client.HttpMethod; import okhttp3.mockwebserver.RecordedRequest; @@ -268,22 +265,21 @@ public void shouldSetCustomText() throws Exception { @Test public void shouldThrowOnCreateSsoAccessTicketWhenIdIsNull() { verifyThrows(IllegalArgumentException.class, - () -> api.selfServiceProfiles().createSsoAccessTicket(null, new Object()), "'id' cannot be null!"); + () -> api.selfServiceProfiles().createSsoAccessTicket(null, new SsoAccessTicketRequest()), "'id' cannot be null!"); } @Test public void shouldThrowOnCreateSsoAccessTicketWhenPayloadIsNull() { verifyThrows(IllegalArgumentException.class, - () -> api.selfServiceProfiles().createSsoAccessTicket("id", null), "'payload' cannot be null!"); + () -> api.selfServiceProfiles().createSsoAccessTicket("id", null), "'request body' cannot be null!"); } @Test public void shouldCreateSsoAccessTicket() throws Exception{ - Map payload = new HashMap<>(); + SsoAccessTicketRequest requestBody = new SsoAccessTicketRequest(); + requestBody.setConnectionId("test-connection"); - payload.put("connection_id", "test-connection"); - - Request request = api.selfServiceProfiles().createSsoAccessTicket("id", payload); + Request request = api.selfServiceProfiles().createSsoAccessTicket("id", requestBody); assertThat(request, is(notNullValue())); server.jsonResponse(SELF_SERVICE_PROFILE_SSO_TICKET, 200); diff --git a/src/test/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequestTest.java b/src/test/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequestTest.java new file mode 100644 index 000000000..41097b646 --- /dev/null +++ b/src/test/java/com/auth0/json/mgmt/selfserviceprofiles/SsoAccessTicketRequestTest.java @@ -0,0 +1,88 @@ +package com.auth0.json.mgmt.selfserviceprofiles; + +import com.auth0.json.JsonTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +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.*; + +public class SsoAccessTicketRequestTest extends JsonTest { + private final static String SELF_SERVICE_PROFILE_SSO_ACCESS_TICKET_REQUEST_JSON = "src/test/resources/mgmt/self_service_profile_sso_ticket_request.json"; + + @Test + public void deserialize() throws Exception { + SsoAccessTicketRequest deserialized = fromJSON(readTextFile(SELF_SERVICE_PROFILE_SSO_ACCESS_TICKET_REQUEST_JSON), SsoAccessTicketRequest.class); + + assertThat(deserialized.getConnectionConfig(), is(notNullValue())); + assertThat(deserialized.getEnabledClients().get(0), is("client-1")); + + assertThat(deserialized.getEnabledOrganizations().get(0).getOrganizationId(), is("org_1")); + assertThat(deserialized.getEnabledOrganizations().get(0).isAssignMembershipOnLogin(), is(true)); + assertThat(deserialized.getEnabledOrganizations().get(0).isShowAsButton(), is(true)); + + assertThat(deserialized.getTtlSec(), is(0)); + + assertThat(deserialized.getDomainAliasesConfig().getDomainVerification(), is("none")); + } + + @Test + public void serialize() throws Exception { + + Map connectionConfig = new HashMap<>(); + connectionConfig.put("name", "okta"); + connectionConfig.put("display_name", "okta connection"); + connectionConfig.put("is_domain_connection", true); + connectionConfig.put("show_as_button", true); + connectionConfig.put("metadata", new HashMap<>()); + + Map idpInitiated = new HashMap<>(); + idpInitiated.put("enabled", true); + idpInitiated.put("client_id", "client-1"); + idpInitiated.put("client_protocol", "oauth2"); + idpInitiated.put("client_authorizequery", "response_type=code&scope=openid%20profile%20email"); + + Map options = new HashMap<>(); + options.put("idpinitiated", idpInitiated); + options.put("icon_url", "https://cdn.auth0.com/connections/okta.png"); + options.put("domain_aliases", new ArrayList() {{ + add("acme.corp"); + }}); + + connectionConfig.put("options", options); + + SsoAccessTicketRequest ssoAccessTicketRequest = new SsoAccessTicketRequest(); + + ssoAccessTicketRequest.setConnectionConfig(connectionConfig); + ssoAccessTicketRequest.setEnabledClients(new ArrayList() {{ + add("client-1"); + }}); + + EnabledOrganizations enabledOrganizations = new EnabledOrganizations(); + enabledOrganizations.setOrganizationId("org_1"); + enabledOrganizations.setAssignMembershipOnLogin(true); + enabledOrganizations.setShowAsButton(true); + + ssoAccessTicketRequest.setEnabledOrganizations(new ArrayList() {{ + add(enabledOrganizations); + }}); + + ssoAccessTicketRequest.setTtlSec(0); + + ssoAccessTicketRequest.setDomainAliasesConfig(new DomainAliasesConfig("none")); + + String serialized = toJSON(ssoAccessTicketRequest); + assertThat(ssoAccessTicketRequest, is(notNullValue())); + assertThat(serialized, containsString("{\"connection_config\":{\"metadata\":{},\"is_domain_connection\":true,\"show_as_button\":true,\"name\":\"okta\",\"options\":{\"icon_url\":\"https://cdn.auth0.com/connections/okta.png\",\"domain_aliases\":[\"acme.corp\"],\"idpinitiated\":{\"client_authorizequery\":\"response_type=code&scope=openid%20profile%20email\",\"client_protocol\":\"oauth2\",\"enabled\":true,\"client_id\":\"client-1\"}},\"display_name\":\"okta connection\"},\"enabled_clients\":[\"client-1\"],\"enabled_organizations\":[{\"organization_id\":\"org_1\",\"assign_membership_on_login\":true,\"show_as_button\":true}],\"ttl_sec\":0,\"domain_aliases_config\":{\"domain_verification\":\"none\"}}")); + assertThat(serialized, containsString("\"enabled_clients\":[\"client-1\"]")); + assertThat(serialized, containsString("\"enabled_organizations\":[{\"organization_id\":\"org_1\",\"assign_membership_on_login\":true,\"show_as_button\":true}]")); + assertThat(serialized, containsString("\"ttl_sec\":0")); + assertThat(serialized, containsString("\"domain_aliases_config\":{\"domain_verification\":\"none\"}")); + + } +} diff --git a/src/test/resources/mgmt/self_service_profile_sso_ticket_request.json b/src/test/resources/mgmt/self_service_profile_sso_ticket_request.json new file mode 100644 index 000000000..cd18124f4 --- /dev/null +++ b/src/test/resources/mgmt/self_service_profile_sso_ticket_request.json @@ -0,0 +1,38 @@ +{ + "connection_config": { + "name": "okta", + "display_name": "okta connection", + "is_domain_connection": true, + "show_as_button": true, + "metadata": { + "key1":"value1" + }, + "options":{ + "icon_url":"url", + "domain_aliases":[ + "acme.corp", + "okta.com" + ], + "idpinitiated": { + "enabled": true, + "client_id": "client-1", + "client_protocol": "oauth2", + "client_authorizequery": "response_type=code&scope=openid%20profile%20email" + } + } + }, + "enabled_clients": [ + "client-1" + ], + "enabled_organizations": [ + { + "organization_id": "org_1", + "assign_membership_on_login": true, + "show_as_button": true + } + ], + "ttl_sec": 0, + "domain_aliases_config": { + "domain_verification": "none" + } +}