Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025-2026, 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 @@ -28,6 +28,7 @@
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.RemoveRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.UpdateRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.DevicesApiService;

import javax.validation.Valid;
Expand Down Expand Up @@ -144,4 +145,22 @@ public Response removeDeviceFromMobile(@ApiParam(value = "ID of the device to be
return delegate.removeDeviceFromMobile(deviceId, removeRequestDTO );
}

@Valid
@POST
@Path("/{deviceId}/update")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Update a registered device from the mobile device.", notes = "This API is used to update a registered device through the mobile device. ", response = Void.class, tags={ "device" })
@ApiResponses(value = {
@ApiResponse(code = 204, message = "The device was updated successfully.", 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),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response updateDeviceFromMobile(@ApiParam(value = "ID of the device to be updated",required=true) @PathParam("deviceId") String deviceId, @ApiParam(value = "Update request sent from the mobile device." ,required=true) @Valid UpdateRequestDTO updateRequestDTO) {

return delegate.updateDeviceFromMobile(deviceId, updateRequestDTO );
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025-2026, 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 @@ -28,6 +28,7 @@
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.RemoveRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.UpdateRequestDTO;
import javax.ws.rs.core.Response;


Expand All @@ -42,4 +43,6 @@ public interface DevicesApiService {
public Response registerDevice(RegistrationRequestDTO registrationRequestDTO);

public Response removeDeviceFromMobile(String deviceId, RemoveRequestDTO removeRequestDTO);

public Response updateDeviceFromMobile(String deviceId, UpdateRequestDTO updateRequestDTO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2026, 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.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.*;

/**
* Update device request body sent from the mobile device
**/

import io.swagger.annotations.*;
import java.util.Objects;
import javax.validation.Valid;
import javax.xml.bind.annotation.*;
@ApiModel(description = "Update device request body sent from the mobile device")
public class UpdateRequestDTO {

private String token;

/**
* JWT containing the device information to be updated signed with the unique private key
**/
public UpdateRequestDTO token(String token) {

this.token = token;
return this;
}

@ApiModelProperty(example = "signedJWTToken", required = true, value = "JWT containing the device information to be updated signed with the unique private key")
@JsonProperty("token")
@Valid
@NotNull(message = "Property token cannot be null.")

public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}



@Override
public boolean equals(java.lang.Object o) {

if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
UpdateRequestDTO updateRequestDTO = (UpdateRequestDTO) o;
return Objects.equals(this.token, updateRequestDTO.token);
}

@Override
public int hashCode() {
return Objects.hash(token);
}

@Override
public String toString() {

StringBuilder sb = new StringBuilder();
sb.append("class UpdateRequestDTO {\n");

sb.append(" token: ").append(toIndentedString(token)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {

if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ public void removeDeviceFromMobile(String deviceId, String token) {
}
}

/**
* Update device from mobile.
*
* @param deviceId Device ID.
* @param token Token.
*/
public void updateDeviceFromMobile(String deviceId, String token) {

try {
deviceHandlerService.editDeviceMobile(deviceId, token);
Comment on lines +158 to +161

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
public void updateDeviceFromMobile(String deviceId, String token) {
try {
deviceHandlerService.editDeviceMobile(deviceId, token);
public void updateDeviceFromMobile(String deviceId, String token) {
if (log.isDebugEnabled()) {
log.debug("Updating device from mobile for deviceId: " + deviceId);
}
try {
deviceHandlerService.editDeviceMobile(deviceId, token);

} catch (PushDeviceHandlerException e) {
Comment on lines +161 to +162

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
deviceHandlerService.editDeviceMobile(deviceId, token);
} catch (PushDeviceHandlerException e) {
deviceHandlerService.editDeviceMobile(deviceId, token);
log.info("Successfully updated device from mobile for deviceId: " + deviceId);
} catch (PushDeviceHandlerException e) {
log.error("Failed to update device from mobile for deviceId: " + deviceId + ". Error: " + e.getMessage());

throw handlePushDeviceHandlerException(e);
}
}

/**
* Register a device.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025-2026, 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 @@ -24,6 +24,7 @@
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.RemoveRequestDTO;
import org.wso2.carbon.identity.rest.api.user.push.v1.model.UpdateRequestDTO;

import java.util.List;

Expand Down Expand Up @@ -73,6 +74,14 @@ public Response registerDevice(RegistrationRequestDTO registrationRequestDTO) {
return Response.status(Response.Status.CREATED).build();
}

@Override
public Response updateDeviceFromMobile(String deviceId, UpdateRequestDTO updateRequestDTO) {

Comment on lines +77 to +79

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 3

Suggested change
@Override
public Response updateDeviceFromMobile(String deviceId, UpdateRequestDTO updateRequestDTO) {
public Response updateDeviceFromMobile(String deviceId, UpdateRequestDTO updateRequestDTO) {
log.info("Updating device from mobile. Device ID: " + deviceId);
String token = updateRequestDTO.getToken();

String token = updateRequestDTO.getToken();
pushDeviceManagementService.updateDeviceFromMobile(deviceId, token);
Comment on lines +80 to +81

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 4

Suggested change
String token = updateRequestDTO.getToken();
pushDeviceManagementService.updateDeviceFromMobile(deviceId, token);
pushDeviceManagementService.updateDeviceFromMobile(deviceId, token);
log.debug("Successfully updated device. Device ID: " + deviceId);
return Response.status(Response.Status.OK).build();

return Response.noContent().build();
}

@Override
public Response removeDeviceFromMobile(String deviceId, RemoveRequestDTO removeRequestDTO) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,39 @@ paths:
$ref: '#/components/responses/Forbidden'
'500':
$ref: '#/components/responses/ServerError'
/devices/{deviceId}/update:
post:
tags:
- device
description: |
This API is used to update a registered device through the mobile device.
summary: Update a registered device from the mobile device.
operationId: updateDeviceFromMobile
parameters:
- name: deviceId
in: path
description: ID of the device to be updated
required: true
schema:
type: string
requestBody:
description: Update request sent from the mobile device.
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateRequestDTO'
responses:
'204':
description: The device was updated successfully.
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'500':
$ref: '#/components/responses/ServerError'
/devices/{deviceId}/remove:
post:
tags:
Expand Down Expand Up @@ -285,6 +318,16 @@ components:
description: Provider metadata as key-value pairs
additionalProperties:
type: string
UpdateRequestDTO:
type: object
description: Update device request body sent from the mobile device
required:
- token
properties:
token:
type: string
description: JWT containing the device information to be updated signed with the unique private key
example: 'signedJWTToken'
RemoveRequestDTO:
type: object
description: Remove device request body sent from the device
Expand Down
Loading