From 8f13c8dbcdaa713bd52477356e393f63cca35fd4 Mon Sep 17 00:00:00 2001 From: ZiyamSanthosh Date: Mon, 2 Dec 2024 12:16:29 +0530 Subject: [PATCH] Improve push device management APIs --- .../pom.xml | 2 +- .../pom.xml | 2 +- .../user/push/v1/model/DiscoveryDataDTO.java | 202 +++++++++++------- .../v1/core/PushDeviceManagementService.java | 27 ++- .../v1/impl/DiscoveryDataApiServiceImpl.java | 3 +- .../src/main/resources/push.yaml | 39 ++-- .../pom.xml | 2 +- 7 files changed, 165 insertions(+), 112 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.api.user.push.common/pom.xml b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.api.user.push.common/pom.xml index 11597cd6..73205068 100644 --- a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.api.user.push.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.api.user.push.common/pom.xml @@ -6,7 +6,7 @@ org.wso2.carbon.identity.user.api org.wso2.carbon.identity.api.user.push - 1.3.39 + 1.3.46-SNAPSHOT org.wso2.carbon.identity.api.user.push.common diff --git a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/pom.xml index 46eb4b6f..573db023 100644 --- a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/pom.xml @@ -6,7 +6,7 @@ org.wso2.carbon.identity.user.api org.wso2.carbon.identity.api.user.push - 1.3.39 + 1.3.46-SNAPSHOT org.wso2.carbon.identity.rest.api.user.push.v1 diff --git a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/push/v1/model/DiscoveryDataDTO.java b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/push/v1/model/DiscoveryDataDTO.java index 66ea3cc0..d9852f20 100644 --- a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/push/v1/model/DiscoveryDataDTO.java +++ b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/push/v1/model/DiscoveryDataDTO.java @@ -35,145 +35,185 @@ @ApiModel(description = "Device registration information") public class DiscoveryDataDTO { - private String did; - private String un; - private String td; - private String ae; - private String re; - private String rde; - private String chg; + private String deviceId; + private String username; + private String host; + private String tenantDomain; + private String tenantPath; + private String organizationId; + private String organizationName; + private String organizationPath; + private String challenge; /** * Device ID **/ - public DiscoveryDataDTO did(String did) { + public DiscoveryDataDTO deviceId(String deviceId) { - this.did = did; + this.deviceId = deviceId; return this; } @ApiModelProperty(example = "b03f90c9-6723-48f6-863b-a35f1ac77f57", value = "Device ID") - @JsonProperty("did") + @JsonProperty("deviceId") @Valid - public String getDid() { - return did; + public String getDeviceId() { + return deviceId; } - public void setDid(String did) { - this.did = did; + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; } /** * Username **/ - public DiscoveryDataDTO un(String un) { + public DiscoveryDataDTO username(String username) { - this.un = un; + this.username = username; return this; } @ApiModelProperty(example = "admin", value = "Username") - @JsonProperty("un") + @JsonProperty("username") @Valid - public String getUn() { - return un; + public String getUsername() { + return username; } - public void setUn(String un) { - this.un = un; + public void setUsername(String username) { + this.username = username; } /** - * Tenant domain or Organization + * Host **/ - public DiscoveryDataDTO td(String td) { + public DiscoveryDataDTO host(String host) { - this.td = td; + this.host = host; return this; } - @ApiModelProperty(example = "carbon.super", value = "Tenant domain or Organization") - @JsonProperty("td") + @ApiModelProperty(example = "https://localhost:9443", value = "Host") + @JsonProperty("host") @Valid - public String getTd() { - return td; + public String getHost() { + return host; } - public void setTd(String td) { - this.td = td; + public void setHost(String host) { + this.host = host; } /** - * Authentication endpoint + * Tenant domain **/ - public DiscoveryDataDTO ae(String ae) { + public DiscoveryDataDTO tenantDomain(String tenantDomain) { - this.ae = ae; + this.tenantDomain = tenantDomain; return this; } - @ApiModelProperty(example = "https://localhost:9443/push-auth/authenticate", value = "Authentication endpoint") - @JsonProperty("ae") + @ApiModelProperty(example = "carbon.super", value = "Tenant domain") + @JsonProperty("tenantDomain") @Valid - public String getAe() { - return ae; + public String getTenantDomain() { + return tenantDomain; } - public void setAe(String ae) { - this.ae = ae; + public void setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; } /** - * Registration endpoint + * Tenanted path **/ - public DiscoveryDataDTO re(String re) { + public DiscoveryDataDTO tenantPath(String tenantPath) { - this.re = re; + this.tenantPath = tenantPath; return this; } - @ApiModelProperty(example = "https://localhost:9443/api/users/v1/me/push/devices", value = "Registration endpoint") - @JsonProperty("re") + @ApiModelProperty(example = "/t/carbon.super", value = "Tenanted path") + @JsonProperty("tenantPath") @Valid - public String getRe() { - return re; + public String getTenantPath() { + return tenantPath; } - public void setRe(String re) { - this.re = re; + public void setTenantPath(String tenantPath) { + this.tenantPath = tenantPath; } /** - * Remove device endpoint + * Organization ID **/ - public DiscoveryDataDTO rde(String rde) { + public DiscoveryDataDTO organizationId(String organizationId) { - this.rde = rde; + this.organizationId = organizationId; return this; } - @ApiModelProperty(example = "https://localhost:9443/api/users/v1/me/push/devices/deviceId/remove", value = "Remove device endpoint") - @JsonProperty("rde") + @ApiModelProperty(example = "b03f90c9-6723-48f6-863b-a35f1ac77f57", value = "Organization ID") + @JsonProperty("organizationId") @Valid - public String getRde() { - return rde; + public String getOrganizationId() { + return organizationId; } - public void setRde(String rde) { - this.rde = rde; + public void setOrganizationId(String organizationId) { + this.organizationId = organizationId; + } + + /** + * Organization name + **/ + public DiscoveryDataDTO organizationName(String organizationName) { + + this.organizationName = organizationName; + return this; + } + + @ApiModelProperty(example = "sampleOrg", value = "Organization name") + @JsonProperty("organizationName") + @Valid + public String getOrganizationName() { + return organizationName; + } + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } + + /** + * Organization path + **/ + public DiscoveryDataDTO organizationPath(String organizationPath) { + + this.organizationPath = organizationPath; + return this; + } + + @ApiModelProperty(example = "/o/sampleOrg", value = "Organization path") + @JsonProperty("organizationPath") + @Valid + public String getOrganizationPath() { + return organizationPath; + } + public void setOrganizationPath(String organizationPath) { + this.organizationPath = organizationPath; } /** * Challenge **/ - public DiscoveryDataDTO chg(String chg) { + public DiscoveryDataDTO challenge(String challenge) { - this.chg = chg; + this.challenge = challenge; return this; } @ApiModelProperty(example = "b03f90c9-6723-48f6-863b-a35f1ac77f57", value = "Challenge") - @JsonProperty("chg") + @JsonProperty("challenge") @Valid - public String getChg() { - return chg; + public String getChallenge() { + return challenge; } - public void setChg(String chg) { - this.chg = chg; + public void setChallenge(String challenge) { + this.challenge = challenge; } @@ -188,18 +228,20 @@ public boolean equals(java.lang.Object o) { return false; } DiscoveryDataDTO discoveryDataDTO = (DiscoveryDataDTO) o; - return Objects.equals(this.did, discoveryDataDTO.did) && - Objects.equals(this.un, discoveryDataDTO.un) && - Objects.equals(this.td, discoveryDataDTO.td) && - Objects.equals(this.ae, discoveryDataDTO.ae) && - Objects.equals(this.re, discoveryDataDTO.re) && - Objects.equals(this.rde, discoveryDataDTO.rde) && - Objects.equals(this.chg, discoveryDataDTO.chg); + return Objects.equals(this.deviceId, discoveryDataDTO.deviceId) && + Objects.equals(this.username, discoveryDataDTO.username) && + Objects.equals(this.host, discoveryDataDTO.host) && + Objects.equals(this.tenantDomain, discoveryDataDTO.tenantDomain) && + Objects.equals(this.tenantPath, discoveryDataDTO.tenantPath) && + Objects.equals(this.organizationId, discoveryDataDTO.organizationId) && + Objects.equals(this.organizationName, discoveryDataDTO.organizationName) && + Objects.equals(this.organizationPath, discoveryDataDTO.organizationPath) && + Objects.equals(this.challenge, discoveryDataDTO.challenge); } @Override public int hashCode() { - return Objects.hash(did, un, td, ae, re, rde, chg); + return Objects.hash(deviceId, username, host, tenantDomain, tenantPath, organizationId, organizationName, organizationPath, challenge); } @Override @@ -208,13 +250,15 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class DiscoveryDataDTO {\n"); - sb.append(" did: ").append(toIndentedString(did)).append("\n"); - sb.append(" un: ").append(toIndentedString(un)).append("\n"); - sb.append(" td: ").append(toIndentedString(td)).append("\n"); - sb.append(" ae: ").append(toIndentedString(ae)).append("\n"); - sb.append(" re: ").append(toIndentedString(re)).append("\n"); - sb.append(" rde: ").append(toIndentedString(rde)).append("\n"); - sb.append(" chg: ").append(toIndentedString(chg)).append("\n"); + sb.append(" deviceId: ").append(toIndentedString(deviceId)).append("\n"); + sb.append(" username: ").append(toIndentedString(username)).append("\n"); + sb.append(" host: ").append(toIndentedString(host)).append("\n"); + sb.append(" tenantDomain: ").append(toIndentedString(tenantDomain)).append("\n"); + sb.append(" tenantPath: ").append(toIndentedString(tenantPath)).append("\n"); + sb.append(" organizationId: ").append(toIndentedString(organizationId)).append("\n"); + sb.append(" organizationName: ").append(toIndentedString(organizationName)).append("\n"); + sb.append(" organizationPath: ").append(toIndentedString(organizationPath)).append("\n"); + sb.append(" challenge: ").append(toIndentedString(challenge)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java index 6347567b..8e80ae2a 100644 --- a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java +++ b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java @@ -1,5 +1,7 @@ package org.wso2.carbon.identity.rest.api.user.push.v1.core; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,7 +32,7 @@ public class PushDeviceManagementService { * * @return Registration discovery data. */ - public DiscoveryDataDTO getRegistrationDiscoveryData() { + public String getRegistrationDiscoveryData() { User user = ContextLoader.getUserFromContext(); String username = user.toFullQualifiedUsername(); @@ -38,7 +40,9 @@ public DiscoveryDataDTO getRegistrationDiscoveryData() { try { RegistrationDiscoveryData data = PushDeviceManagerServiceDataHolder.getDeviceHandlerService() .getRegistrationDiscoveryData(username, tenantDomain); - return buildDiscoveryDataDTO(data); + DiscoveryDataDTO discoveryDataDTO = buildDiscoveryDataDTO(data); + Gson gson = new GsonBuilder().create(); + return gson.toJson(discoveryDataDTO); } catch (PushDeviceHandlerException e) { throw handlePushDeviceHandlerException(e); } @@ -90,16 +94,17 @@ public RegistrationResponseDTO registerDevice(RegistrationRequestDTO registratio private DiscoveryDataDTO buildDiscoveryDataDTO(RegistrationDiscoveryData data) { DiscoveryDataDTO discoveryDataDTO = new DiscoveryDataDTO(); - discoveryDataDTO.setDid(data.getDeviceId()); - discoveryDataDTO.setUn(data.getUsername()); - discoveryDataDTO.setTd(data.getTenantDomain()); - if (StringUtils.isNotBlank(data.getOrganizationName())) { - discoveryDataDTO.setTd(data.getOrganizationName()); + discoveryDataDTO.setDeviceId(data.getDeviceId()); + discoveryDataDTO.setUsername(data.getUsername()); + discoveryDataDTO.setHost(data.getHost()); + discoveryDataDTO.setTenantDomain(data.getTenantDomain()); + discoveryDataDTO.setTenantPath(data.getTenantPath()); + if (StringUtils.isNotBlank(data.getOrganizationId())) { + discoveryDataDTO.setOrganizationId(data.getOrganizationId()); + discoveryDataDTO.setOrganizationName(data.getOrganizationName()); + discoveryDataDTO.setOrganizationPath(data.getOrganizationPath()); } - discoveryDataDTO.setChg(data.getChallenge()); - discoveryDataDTO.setRe(data.getRegistrationEndpoint()); - discoveryDataDTO.setAe(data.getAuthenticationEndpoint()); - discoveryDataDTO.setRde(data.getRemoveDeviceEndpoint()); + discoveryDataDTO.setChallenge(data.getChallenge()); return discoveryDataDTO; } diff --git a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/impl/DiscoveryDataApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/impl/DiscoveryDataApiServiceImpl.java index 21950600..7d9fb338 100644 --- a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/impl/DiscoveryDataApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/impl/DiscoveryDataApiServiceImpl.java @@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.user.push.v1.DiscoveryDataApiService; import org.wso2.carbon.identity.rest.api.user.push.v1.core.PushDeviceManagementService; -import org.wso2.carbon.identity.rest.api.user.push.v1.model.DiscoveryDataDTO; import javax.ws.rs.core.Response; @@ -36,7 +35,7 @@ public class DiscoveryDataApiServiceImpl implements DiscoveryDataApiService { @Override public Response getRegistrationDiscoveryData() { - DiscoveryDataDTO responseDTO = pushDeviceManagementService.getRegistrationDiscoveryData(); + String responseDTO = pushDeviceManagementService.getRegistrationDiscoveryData(); return Response.ok().entity(responseDTO).build(); } } diff --git a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/resources/push.yaml b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/resources/push.yaml index 6fa4a1cf..f2689c66 100644 --- a/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/resources/push.yaml +++ b/components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/resources/push.yaml @@ -183,34 +183,39 @@ components: type: object description: Device registration information properties: - did: + deviceId: description: Device ID type: string example: b03f90c9-6723-48f6-863b-a35f1ac77f57 - un: + username: description: Username type: string example: admin - td: - description: Tenant domain or Organization + host: + description: Host + type: string + example: https://localhost:9443 + tenantDomain: + description: Tenant domain type: string example: carbon.super - ae: - description: Authentication endpoint + tenantPath: + description: Tenanted path type: string - format: url - example: https://localhost:9443/push-auth/authenticate - re: - description: Registration endpoint + example: /t/carbon.super + organizationId: + description: Organization ID + type: string + example: b03f90c9-6723-48f6-863b-a35f1ac77f57 + organizationName: + description: Organization name type: string - format: url - example: https://localhost:9443/api/users/v1/me/push/devices - rde: - description: Remove device endpoint + example: sampleOrg + organizationPath: + description: Organization path type: string - format: url - example: https://localhost:9443/api/users/v1/me/push/devices/deviceId/remove - chg: + example: /o/sampleOrg + challenge: description: Challenge type: string example: b03f90c9-6723-48f6-863b-a35f1ac77f57 diff --git a/components/org.wso2.carbon.identity.api.user.push/pom.xml b/components/org.wso2.carbon.identity.api.user.push/pom.xml index bb32a1ba..1034f303 100644 --- a/components/org.wso2.carbon.identity.api.user.push/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.push/pom.xml @@ -6,7 +6,7 @@ org.wso2.carbon.identity.user.api identity-api-user - 1.3.39 + 1.3.46-SNAPSHOT ../../pom.xml