Skip to content

Commit

Permalink
Merge pull request #1118 from /issues/1107-update-activation-name
Browse files Browse the repository at this point in the history
Fix #1107: Update activation name (backport)
  • Loading branch information
banterCZ authored Nov 9, 2023
2 parents 91b76eb + 0e524e4 commit d46fa95
Show file tree
Hide file tree
Showing 23 changed files with 572 additions and 85 deletions.
47 changes: 39 additions & 8 deletions docs/WebServices-Methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The following `v3` methods are published using the service:
- [prepareActivation](#method-prepareactivation)
- [createActivation](#method-createactivation)
- [updateActivationOtp](#method-updateactivationotp)
- [updateActivationName](#method-updateactivationname)
- [commitActivation](#method-commitactivation)
- [getActivationStatus](#method-getactivationstatus)
- [removeActivation](#method-removeactivation)
Expand Down Expand Up @@ -519,6 +520,35 @@ REST endpoint: `POST /rest/v3/activation/otp/update`
| `String` | `activationId` | An identifier of an activation |
| `boolean` | `updated` | Flag indicating that OTP has been updated |

### Method 'updateActivationName'

Update activation name for activation with given ID.
No allowed for activation in status `CREATED`, `REMOVED`, or `BLOCKED`.

After successful, activation name is updated.

#### Request

REST endpoint: `POST /rest/v3/activation/name/update`

`UpdateActivationNameRequest`

| Type | Name | Description |
|----------|------------------|---------------------------------------------------------------------------------------------------|
| `String` | `activationId` | An identifier of an activation. |
| `String` | `externalUserId` | User ID of user who changes the activation. Use null value if activation owner caused the change. |
| `String` | `activationName` | A new value of activation name. |

#### Response

`UpdateActivationNameResponse`

| Type | Name | Description |
|--------------------|--------------------|---------------------------------|
| `String` | `activationId` | An identifier of an activation |
| `String` | `activationName` | A new value of activation name. |
| `ActivationStatus` | `activationStatus` | An activation status. |

### Method 'commitActivation'

Commit activation with given ID. Only non-expired activations in PENDING_COMMIT state can be committed.
Expand Down Expand Up @@ -1166,14 +1196,15 @@ REST endpoint: `POST /rest/v3/activation/history`

`ActivationHistoryResponse.Item`

| Type | Name | Description |
|------|------|-------------|
| `Long` | `id` | Change ID |
| `String` | `activationId` | An identifier of an activation |
| `ActivationStatus` | `activationStatus` | An activation status at the moment of a signature verification |
| `String` | `eventReason` | Reason why this activation history record was created (default: null) |
| `String` | `externalUserId` | User ID of user who modified the activation. Null value is used if activation owner caused the change. |
| `DateTime` | `timestampCreated` | Timestamp when the record was created |
| Type | Name | Description |
|--------------------|--------------------|--------------------------------------------------------------------------------------------------------|
| `Long` | `id` | Change ID |
| `String` | `activationId` | An identifier of an activation |
| `ActivationStatus` | `activationStatus` | An activation status at the moment of a signature verification |
| `String` | `eventReason` | Reason why this activation history record was created (default: null) |
| `String` | `externalUserId` | User ID of user who modified the activation. Null value is used if activation owner caused the change. |
| `String` | `activationName` | Activation name. |
| `DateTime` | `timestampCreated` | Timestamp when the record was created |

## Integration management

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd">

<changeSet id="1" logicalFilePath="powerauth-java-server/1.6.x/20231103-add-activation-name-history.xml" author="Lubos Racansky">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="pa_activation_history" columnName="activation_name" />
</not>
</preConditions>
<comment>Add activation_name column to pa_activation_history</comment>
<addColumn tableName="pa_activation_history">
<column name="activation_name" type="varchar(255)" />
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd">

<include file="20231103-add-activation-name-history.xml" relativeToChangelogFile="true" />

</databaseChangeLog>
Binary file modified docs/images/arch_db_structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<!-- Other Dependencies -->
<commons-text.version>1.10.0</commons-text.version>
<logstash.version>7.4</logstash.version>
<equalsverifier.version>3.15.3</equalsverifier.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -158,6 +159,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>${equalsverifier.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ PrepareActivationResponse prepareActivation(String activationCode, String applic
*/
CreateActivationResponse createActivation(CreateActivationRequest request, MultiValueMap<String, String> queryParams, MultiValueMap<String, String> httpHeaders) throws PowerAuthClientException;

/**
* Update the activation name directly, using the updateActivationName method of the PowerAuth Server interface.
*
* @param request Update activation name request.
* @return Update activation name response.
* @throws PowerAuthClientException In case REST API call fails.
*/
UpdateActivationNameResponse updateActivationName(UpdateActivationNameRequest request) throws PowerAuthClientException;

/**
* Update the activation name directly, using the updateActivationName method of the PowerAuth Server interface.
*
* @param request Update activation request.
* @param queryParams HTTP query parameters.
* @param httpHeaders HTTP headers.
* @return Update activation name response.
* @throws PowerAuthClientException In case REST API call fails.
*/
UpdateActivationNameResponse updateActivationName(UpdateActivationNameRequest request, MultiValueMap<String, String> queryParams, MultiValueMap<String, String> httpHeaders) throws PowerAuthClientException;

/**
* Call the createActivation method of the PowerAuth 3.0 Server interface.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ActivationHistoryItem {
private ActivationStatus activationStatus;
private String eventReason;
private String externalUserId;
private String activationName;
private Date timestampCreated;
private Long version;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* PowerAuth Server and related software components
* Copyright (C) 2023 Wultra s.r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.wultra.security.powerauth.client.model.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Data;

/**
* Model class representing request for updating activation.
*
* @author Lubos Racansky, [email protected]
*/
@Data
public class UpdateActivationNameRequest {

@NotBlank
private String activationId;

@NotBlank
private String activationName;

@NotBlank
private String externalUserId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* PowerAuth Server and related software components
* Copyright (C) 2023 Wultra s.r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.wultra.security.powerauth.client.model.response;

import com.wultra.security.powerauth.client.model.enumeration.ActivationStatus;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

/**
* Model class representing response with updated activation.
*
* @author Lubos Racansky, [email protected]
*/
@Data
public class UpdateActivationNameResponse {

@NotBlank
private String activationId;

@NotBlank
private String activationName;

@NotNull
private ActivationStatus activationStatus;

}
5 changes: 5 additions & 0 deletions powerauth-java-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@
import io.getlime.security.powerauth.app.server.service.exceptions.ActivationRecoveryException;
import io.getlime.security.powerauth.app.server.service.exceptions.GenericServiceException;
import io.getlime.security.powerauth.app.server.service.exceptions.TelemetryReportException;
import io.getlime.security.powerauth.app.server.service.model.ServiceError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.Comparator;
import java.util.stream.Collectors;

/**
* Class used for handling RESTful service errors.
*
Expand Down Expand Up @@ -95,6 +101,30 @@ public class RESTControllerAdvice {
return new ObjectResponse<>("ERROR", error);
}

/**
* Resolver for validation xception.
*
* @param ex Exception.
* @return Activation recovery error.
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler
public @ResponseBody ObjectResponse<PowerAuthError> returnActivationRecoveryError(final MethodArgumentNotValidException ex) {
logger.error("Error occurred while processing the request: {}", ex.getMessage());
logger.debug("Exception details:", ex);

final String message = ex.getBindingResult().getFieldErrors().stream()
.sorted(Comparator.comparing(FieldError::getField))
.map(it -> String.join(" - ", it.getField(), it.getDefaultMessage()))
.collect(Collectors.joining(", "));

final PowerAuthError error = new PowerAuthError();
error.setCode(ServiceError.INVALID_REQUEST);
error.setMessage(message);
error.setLocalizedMessage(message);
return new ObjectResponse<>("ERROR", error);
}

/**
* Resolver for HTTP request message errors.
* @param ex Exception for HTTP message not readable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
import io.getlime.core.rest.model.base.response.Response;
import io.getlime.security.powerauth.app.server.service.PowerAuthService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* Class implementing the RESTful controller for PowerAuth service.
Expand Down Expand Up @@ -171,6 +175,17 @@ public ObjectResponse<GetActivationListForUserResponse> getActivationListForUser
return new ObjectResponse<>("OK", powerAuthService.getActivationListForUser(request.getRequestObject()));
}

/**
* Update the activation name.
*
* @param request This is an {@link ObjectRequest} that contains a {@link UpdateActivationNameRequest}.
* @return This endpoint returns an {@link ObjectResponse} that contains a {@link UpdateActivationNameResponse}.
* @throws Exception In case the service throws an exception, it will be propagated and should be handled by the caller.
*/
@PostMapping("/activation/name/update")
public ObjectResponse<UpdateActivationNameResponse> updateActivation(@Valid @RequestBody ObjectRequest<UpdateActivationNameRequest> request) throws Exception {
return new ObjectResponse<>(powerAuthService.updateActivationName(request.getRequestObject()));
}

/**
* Call {@link PowerAuthService#lookupActivations(LookupActivationsRequest)} method and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public static class Reason {
*/
public static final String ACTIVATION_VERSION_CHANGED = "ACTIVATION_VERSION_CHANGED";

/**
* Logged when the activation name has been updated.
*/
public static final String ACTIVATION_NAME_UPDATED = "ACTIVATION_NAME_UPDATED";

}

private AdditionalInformation() {
Expand Down
Loading

0 comments on commit d46fa95

Please sign in to comment.