Skip to content

Commit

Permalink
Fix #1216: Modify Paging of Activations (#1219)
Browse files Browse the repository at this point in the history
* Fix #1216: Modify Paging of Activations
  • Loading branch information
banterCZ authored Dec 14, 2023
1 parent 17be0e3 commit b4cad7c
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 140 deletions.
2 changes: 1 addition & 1 deletion docs/Configuration-Properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The PowerAuth Server uses the following public configuration properties:
| `powerauth.service.secureVault.enableBiometricAuthentication` | `false` | Whether biometric authentication is enabled when accessing Secure Vault |
| `powerauth.server.db.master.encryption.key` | `_empty_` | Master DB encryption key for decryption of server private key in database |
| `powerauth.service.proximity-check.otp.length` | `8` | Length of OTP generated for proximity check |
| `powerauth.service.pagination.default-page-size` | `100` | The default number of records per page when paginated results are requested |
| `powerauth.service.pagination.default-page-size` | `500` | The default number of records per page when paginated results are requested |
| `powerauth.service.pagination.default-page-number` | `0` | The default page number when paginated results are requested. Page numbers start from 0 |

## HTTP Configuration
Expand Down
26 changes: 13 additions & 13 deletions docs/WebServices-Methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,21 +656,21 @@ REST endpoint: `POST /rest/v3/activation/list`

`GetActivationListForUserRequest`

| Type | Name | Description |
|----------|------|-------------|
| `String` | `userId` | An identifier of a user |
| `String` | `applicationId` | An identifier of an application |
| `Integer` | `pageNumber` | Optional. The number of the page to fetch in the paginated results. Starts from 0, where 0 refers to the first page. If not provided, defaults to 0. |
| `Integer` | `pageSize` | Optional. The number of records per page in the paginated results. This determines the total number of records shown in each page of results. If not provided, defaults to 100. |
| Type | Name | Description |
|-----------|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `String` | `userId` | An identifier of a user |
| `String` | `applicationId` | An identifier of an application |
| `Integer` | `pageNumber` | Optional. The number of the page to fetch in the paginated results. Starts from 0, where 0 refers to the first page. If not provided, defaults to 0. |
| `Integer` | `pageSize` | Optional. The number of records per page in the paginated results. This determines the total number of records shown in each page of results. If not provided, defaults to 500. |

#### Response

`GetActivationListForUserResponse`

| Type | Name | Description |
|------|------|-------------|
| `String` | `userId` | An identifier of a user |
| `Activation[]` | `activations` | A collection of activations for given user |
| Type | Name | Description |
|----------------|---------------|------------------------------------------------------------------------------------------|
| `String` | `userId` | An identifier of a user |
| `Activation[]` | `activations` | A collection of activations for the given user ordered by `timestampCreated` descending. |

`GetActivationListForUserResponse.Activation`

Expand Down Expand Up @@ -2101,7 +2101,7 @@ REST endpoint: `POST /rest/v3/operation/list/pending`
| `String` | `userId` | The identifier of the user |
| `String` | `applicationId` | The identifier of the application |
| `Integer` | `pageNumber` | Optional. The number of the page to fetch in the paginated results. Starts from 0, where 0 refers to the first page. If not provided, defaults to 0. |
| `Integer` | `pageSize` | Optional. The number of records per page in the paginated results. This determines the total number of records shown in each page of results. If not provided, defaults to 100. |
| `Integer` | `pageSize` | Optional. The number of records per page in the paginated results. This determines the total number of records shown in each page of results. If not provided, defaults to 500. |


#### Response
Expand Down Expand Up @@ -2144,7 +2144,7 @@ REST endpoint: `POST /rest/v3/operation/list`
| `String` | `userId` | The identifier of the user |
| `String` | `applicationId` | The identifier of the application |
| `Integer` | `pageNumber` | Optional. The number of the page to fetch in the paginated results. Starts from 0, where 0 refers to the first page. If not provided, defaults to 0. |
| `Integer` | `pageSize` | Optional. The number of records per page in the paginated results. This determines the total number of records shown in each page of results. If not provided, defaults to 100. |
| `Integer` | `pageSize` | Optional. The number of records per page in the paginated results. This determines the total number of records shown in each page of results. If not provided, defaults to 500. |


#### Response
Expand Down Expand Up @@ -2186,7 +2186,7 @@ REST endpoint: `POST /rest/v3/operation/list/external`
| `String` | `externalId` | The external identifier of the operation |
| `String` | `applicationId` | The identifier of the application |
| `Integer` | `pageNumber` | Optional. The number of the page to fetch in the paginated results. Starts from 0, where 0 refers to the first page. If not provided, defaults to 0. |
| `Integer` | `pageSize` | Optional. The number of records per page in the paginated results. This determines the total number of records shown in each page of results. If not provided, defaults to 100. |
| `Integer` | `pageSize` | Optional. The number of records per page in the paginated results. This determines the total number of records shown in each page of results. If not provided, defaults to 500. |


#### Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.springframework.boot.info.BuildProperties;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -158,7 +159,7 @@ public GetActivationListForUserResponse getActivationListForUser(GetActivationLi
final String applicationId = request.getApplicationId();
final int pageNumber = request.getPageNumber() != null ? request.getPageNumber() : powerAuthPageableConfiguration.defaultPageNumber();
final int pageSize = request.getPageSize() != null ? request.getPageSize() : powerAuthPageableConfiguration.defaultPageSize();
final Pageable pageable = PageRequest.of(pageNumber, pageSize);
final Pageable pageable = PageRequest.of(pageNumber, pageSize, Sort.by("timestampCreated").descending());
logger.info("GetActivationListForUserRequest received, user ID: {}, application ID: {}", userId, applicationId);
final GetActivationListForUserResponse response = behavior.getActivationServiceBehavior().getActivationList(applicationId, userId, pageable);
logger.info("GetActivationListForUserRequest succeeded");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ spring.cloud.vault.enabled=false
spring.cloud.vault.kv.enabled=true

# Configure Spring Pageable properties
powerauth.service.pagination.default-page-size=100
powerauth.service.pagination.default-page-size=500
powerauth.service.pagination.default-page-number=0

# Configure Correlation HTTP Header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
package io.getlime.security.powerauth.app.server;

import com.wultra.security.powerauth.client.model.request.CreateApplicationRequest;
import io.getlime.security.powerauth.app.server.service.exceptions.GenericServiceException;
import io.getlime.security.powerauth.app.server.service.PowerAuthService;
import io.getlime.security.powerauth.app.server.service.exceptions.GenericServiceException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.ActiveProfiles;

import java.util.UUID;

Expand All @@ -37,8 +36,8 @@
* @author Lukas Lukovsky, [email protected]
*/
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class CreateApplicationTest {
@ActiveProfiles("test")
class CreateApplicationTest {

private PowerAuthService powerAuthService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
import com.wultra.security.powerauth.client.model.response.CreateApplicationResponse;
import com.wultra.security.powerauth.client.model.response.GetApplicationDetailResponse;
import io.getlime.security.powerauth.app.server.database.model.entity.ApplicationEntity;
import io.getlime.security.powerauth.app.server.service.exceptions.GenericServiceException;
import io.getlime.security.powerauth.app.server.service.PowerAuthService;
import io.getlime.security.powerauth.app.server.service.exceptions.GenericServiceException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.ActiveProfiles;

import java.util.Collections;

Expand All @@ -41,8 +40,8 @@
* @author Lukas Lukovsky, [email protected]
*/
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class GetApplicationDetailTest {
@ActiveProfiles("test")
class GetApplicationDetailTest {

private PowerAuthService powerAuthService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
package io.getlime.security.powerauth.app.server;

import io.getlime.security.powerauth.app.server.converter.RecoveryPrivateKeyConverter;
import io.getlime.security.powerauth.app.server.database.model.enumeration.EncryptionMode;
import io.getlime.security.powerauth.app.server.database.model.RecoveryPrivateKey;
import io.getlime.security.powerauth.app.server.database.model.enumeration.EncryptionMode;
import io.getlime.security.powerauth.app.server.service.exceptions.GenericServiceException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.ActiveProfiles;

import java.util.Base64;

Expand All @@ -38,8 +37,8 @@
* @author Roman Strobl, [email protected]
*/
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class RecoveryPrivateKeyConverterTest {
@ActiveProfiles("test")
class RecoveryPrivateKeyConverterTest {

private static final String RECOVERY_PRIVATE_KEY_PLAIN = "ALwHHv90Ixaor+8CkBThDQP/8UUm59Bvdod5u7z97zGm";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
package io.getlime.security.powerauth.app.server;

import io.getlime.security.powerauth.app.server.converter.ServerPrivateKeyConverter;
import io.getlime.security.powerauth.app.server.database.model.enumeration.EncryptionMode;
import io.getlime.security.powerauth.app.server.database.model.ServerPrivateKey;
import io.getlime.security.powerauth.app.server.database.model.enumeration.EncryptionMode;
import io.getlime.security.powerauth.app.server.service.exceptions.GenericServiceException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.ActiveProfiles;

import java.util.Base64;

Expand All @@ -38,8 +37,8 @@
* @author Roman Strobl, [email protected]
*/
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class ServerPrivateKeyConverterTest {
@ActiveProfiles("test")
class ServerPrivateKeyConverterTest {

private static final String SERVER_PRIVATE_KEY_PLAIN = "YAJ1A/QtTTB33R3Xnx3q7+QFuth6cRagtCMGTytV9VE=";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -49,6 +50,7 @@
@AutoConfigureMockMvc
@Sql
@Transactional
@ActiveProfiles("test")
class PowerAuthControllerTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;

import java.util.Optional;

Expand All @@ -38,6 +39,7 @@
*/
@DataJpaTest
@Import(ObjectMapper.class)
@ActiveProfiles("test")
class OperationTemplateRepositoryTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 io.getlime.security.powerauth.app.server.service;

import com.wultra.security.powerauth.client.model.entity.Activation;
import com.wultra.security.powerauth.client.model.request.GetActivationListForUserRequest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Test for {@link PowerAuthService}.
*
* @author Lubos Racansky, [email protected]
*/
@SpringBootTest
@Transactional
@ActiveProfiles("test")
class PowerAuthServiceTest {

@Autowired
private PowerAuthService tested;

@Test
@Sql
void testGetActivationListForUser() throws Exception {
final GetActivationListForUserRequest request = new GetActivationListForUserRequest();
request.setUserId("user1");

final List<Activation> result = tested.getActivationListForUser(request).getActivations();

assertEquals(3, result.size());

final List<String> expectedIdOrder = List.of("e43a5dec-afea-4a10-a80b-b2183399f16b", "47cf47b3-c72d-4859-a5f4-51da6d6ad6a3", "0d34cfc4-af98-4eb8-aba5-58f766bd2967");
final List<String> actualIdOrder = result.stream().map(Activation::getActivationId).toList();
assertEquals(expectedIdOrder, actualIdOrder);

final Date timestampCreated1 = result.get(0).getTimestampCreated();
final Date timestampCreated2 = result.get(1).getTimestampCreated();
final Date timestampCreated3 = result.get(2).getTimestampCreated();
assertEquals(1, timestampCreated1.compareTo(timestampCreated2));
assertEquals(1, timestampCreated2.compareTo(timestampCreated3));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.security.KeyPair;
Expand All @@ -57,6 +58,7 @@

@SpringBootTest
@Transactional
@ActiveProfiles("test")
class ActivationServiceBehaviorTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;

import java.util.UUID;
Expand All @@ -41,6 +42,7 @@
@SpringBootTest
@Sql
@Transactional
@ActiveProfiles("test")
class CallbackUrlBehaviorTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;

import java.time.Instant;
Expand All @@ -52,6 +53,7 @@
@SpringBootTest
@Sql
@Transactional
@ActiveProfiles("test")
class OperationServiceBehaviorTest {

private static final String APP_ID = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -33,6 +34,7 @@
* @author Jan Pesek, [email protected]
*/
@SpringBootTest
@ActiveProfiles("test")
class OperationTemplateServiceBehaviorTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.opentest4j.AssertionFailedError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -49,6 +50,7 @@
@SpringBootTest
@Sql
@Transactional
@ActiveProfiles("test")
class SignatureSharedServiceBehaviorTest {

@Autowired
Expand Down
Loading

0 comments on commit b4cad7c

Please sign in to comment.