Skip to content

Commit

Permalink
Improve push device endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiyamSanthosh committed Jan 22, 2025
1 parent 32e981b commit 989ae93
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.api.user.push.common;

import org.wso2.carbon.identity.notification.push.device.handler.DeviceHandlerService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.api.user.push.common.factory;

import org.springframework.beans.factory.config.AbstractFactoryBean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -27,7 +27,6 @@
import org.wso2.carbon.identity.rest.api.user.push.v1.model.DeviceDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.Error;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RegistrationRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RegistrationResponseDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RemoveRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.DevicesApiService;

Expand Down Expand Up @@ -108,9 +107,9 @@ public Response getDevices() {

@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Register mobile devices to receive push notifications.", notes = "This API is used to register a push notification device into the Identity Server. This API will be invoked from the mobile device. ", response = RegistrationResponseDTO.class, tags={ "mobile", })
@ApiOperation(value = "Register mobile devices to receive push notifications.", notes = "This API is used to register a push notification device into the Identity Server. This API will be invoked from the mobile device. ", response = Void.class, tags={ "mobile", })
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Registered a new device", response = RegistrationResponseDTO.class),
@ApiResponse(code = 201, message = "Registered a new device", response = Void.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 401, message = "Authentication information is missing or invalid.", response = Void.class),
@ApiResponse(code = 403, message = "Access forbidden.", response = Void.class),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -27,7 +27,6 @@
import org.wso2.carbon.identity.rest.api.user.push.v1.model.DeviceDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.Error;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RegistrationRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RegistrationResponseDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RemoveRequestDTO;
import javax.ws.rs.core.Response;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public class DiscoveryDataDTO {
private String username;
private String host;
private String tenantDomain;
private String tenantPath;
private String organizationId;
private String organizationName;
private String organizationPath;
private String challenge;

/**
Expand Down Expand Up @@ -121,25 +119,6 @@ public void setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
}

/**
* Tenanted path
**/
public DiscoveryDataDTO tenantPath(String tenantPath) {

this.tenantPath = tenantPath;
return this;
}

@ApiModelProperty(example = "/t/carbon.super", value = "Tenanted path")
@JsonProperty("tenantPath")
@Valid
public String getTenantPath() {
return tenantPath;
}
public void setTenantPath(String tenantPath) {
this.tenantPath = tenantPath;
}

/**
* Organization ID
**/
Expand Down Expand Up @@ -178,25 +157,6 @@ 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
**/
Expand Down Expand Up @@ -232,16 +192,14 @@ public boolean equals(java.lang.Object o) {
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(deviceId, username, host, tenantDomain, tenantPath, organizationId, organizationName, organizationPath, challenge);
return Objects.hash(deviceId, username, host, tenantDomain, organizationId, organizationName, challenge);
}

@Override
Expand All @@ -254,10 +212,8 @@ public String toString() {
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.rest.api.user.push.v1.core;

import com.google.gson.Gson;
Expand All @@ -16,11 +34,11 @@
import org.wso2.carbon.identity.rest.api.user.push.v1.model.DeviceDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.DiscoveryDataDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RegistrationRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RegistrationResponseDTO;

import java.util.ArrayList;
import java.util.List;

import static org.wso2.carbon.identity.notification.push.device.handler.constant.PushDeviceHandlerConstants.ErrorMessages.ERROR_CODE_DEVICE_NOT_FOUND_FOR_USER_ID;
import static org.wso2.carbon.identity.rest.api.user.push.v1.util.Util.handlePushDeviceHandlerException;

/**
Expand Down Expand Up @@ -74,18 +92,20 @@ public DeviceDTO getDevice(String deviceId) {
*/
public List<DeviceDTO> getDeviceByUserId() {

List<DeviceDTO> deviceDTOList = new ArrayList<>();
try {
User user = ContextLoader.getUserFromContext();
String tenantDomain = user.getTenantDomain();
String userId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserId();
Device device = PushDeviceManagerServiceDataHolder.getDeviceHandlerService().getDeviceByUserId(userId,
tenantDomain);
List<DeviceDTO> deviceDTOList = new ArrayList<>();
deviceDTOList.add(buildDeviceDTO(device));
return deviceDTOList;
} catch (PushDeviceHandlerException e) {
throw handlePushDeviceHandlerException(e);
if (!ERROR_CODE_DEVICE_NOT_FOUND_FOR_USER_ID.getCode().equals(e.getErrorCode())) {
throw handlePushDeviceHandlerException(e);
}
}
return deviceDTOList;
}

/**
Expand Down Expand Up @@ -121,18 +141,14 @@ public void removeDeviceFromMobile(String deviceId, String token) {
* Register a device.
*
* @param registrationRequestDTO Registration request DTO.
* @return Registration response DTO.
*/
public RegistrationResponseDTO registerDevice(RegistrationRequestDTO registrationRequestDTO) {
public void registerDevice(RegistrationRequestDTO registrationRequestDTO) {

String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
RegistrationRequest request = buildRegistrationRequest(registrationRequestDTO);
try {
Device device = PushDeviceManagerServiceDataHolder.getDeviceHandlerService()
PushDeviceManagerServiceDataHolder.getDeviceHandlerService()
.registerDevice(request, tenantDomain);
RegistrationResponseDTO responseDTO = new RegistrationResponseDTO();
responseDTO.setDeviceId(device.getDeviceId());
return responseDTO;
} catch (PushDeviceHandlerException e) {
throw handlePushDeviceHandlerException(e);
}
Expand All @@ -151,11 +167,9 @@ private DiscoveryDataDTO buildDiscoveryDataDTO(RegistrationDiscoveryData data) {
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.setChallenge(data.getChallenge());
return discoveryDataDTO;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.rest.api.user.push.v1.exception;

import javax.ws.rs.WebApplicationException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -23,7 +23,6 @@
import org.wso2.carbon.identity.rest.api.user.push.v1.core.PushDeviceManagementService;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.DeviceDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RegistrationRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RegistrationResponseDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.RemoveRequestDTO;

import java.util.List;
Expand Down Expand Up @@ -62,8 +61,8 @@ public Response getDevices() {
@Override
public Response registerDevice(RegistrationRequestDTO registrationRequestDTO) {

RegistrationResponseDTO responseDTO = pushDeviceManagementService.registerDevice(registrationRequestDTO);
return Response.ok().entity(responseDTO).build();
pushDeviceManagementService.registerDevice(registrationRequestDTO);
return Response.created(null).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Loading

0 comments on commit 989ae93

Please sign in to comment.