Skip to content

Commit

Permalink
Fix #752: Return activation lists with limits and paging
Browse files Browse the repository at this point in the history
- Switch PowerAuthPageableConfiguration to record calss with ConfigurationProperties annotation
  • Loading branch information
jandusil committed Aug 1, 2023
1 parent 9a45b3f commit f4ac9ab
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
20 changes: 11 additions & 9 deletions docs/Configuration-Properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ The PowerAuth Server uses the following public configuration properties:

## Activation and Cryptography Configuration

| Property | Default | Note |
|---------------------------------------------------------------|-----------|---------------------------------------------------------------------------|
| `powerauth.service.crypto.activationValidityInMilliseconds` | `120000` | Default activation validity period in miliseconds |
| `powerauth.service.crypto.signatureMaxFailedAttempts` | `5` | Maximum failed attempts for signature verification |
| `powerauth.service.token.timestamp.validity` | `7200000` | PowerAuth MAC token timestamp validity in miliseconds |
| `powerauth.service.recovery.maxFailedAttempts` | `5` | Maximum failed attempts for activation recovery |
| `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 |
| Property | Default | Note |
|---------------------------------------------------------------|-----------|-----------------------------------------------------------------------------------------|
| `powerauth.service.crypto.activationValidityInMilliseconds` | `120000` | Default activation validity period in miliseconds |
| `powerauth.service.crypto.signatureMaxFailedAttempts` | `5` | Maximum failed attempts for signature verification |
| `powerauth.service.token.timestamp.validity` | `7200000` | PowerAuth MAC token timestamp validity in miliseconds |
| `powerauth.service.recovery.maxFailedAttempts` | `5` | Maximum failed attempts for activation recovery |
| `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-number` | `0` | The default page number when paginated results are requested. Page numbers start from 0 |

## HTTP Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

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

/**
Expand All @@ -30,7 +31,9 @@ public class GetActivationListForUserRequest {

private String userId;
private String applicationId;
@Min(0)
private Integer pageNumber;
@Min(1)
private Integer pageSize;

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.security.Security;
Expand All @@ -33,6 +34,7 @@
@SpringBootApplication
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "10m")
@ConfigurationPropertiesScan
public class Application {

static {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* PowerAuth Server and related software components
* Copyright (C) 2022 Wultra s.r.o.
* 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
Expand All @@ -17,29 +17,24 @@
*/
package io.getlime.security.powerauth.app.server.configuration;

import lombok.Data;
import jakarta.validation.constraints.Min;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
* PowerAuthPageableConfiguration is a configuration class for handling pagination settings.
* Configuration class that handles pagination settings in PowerAuth Server.
* This includes parameters for default page number and page size.
* <p>
* 'defaultPageNumber' is the default page number that is used when no specific
* page number is provided. It has a minimum value of 0.
* <p>
* 'defaultPageSize' is the default number of records per page when no specific
* page size is provided. It has a minimum value of 1.
* <p>
* Both properties are read from the "powerauth.service.pagination" configuration block.
*
* @author Jan Dusil, [email protected]
*
*/
@Configuration
@ConfigurationProperties("powerauth.service.pagination")
@Data
public class PowerAuthPageableConfiguration {

/**
* Default page number for pagination.
*/
private int defaultPageNumber;

/**
* Default page size for pagination.
*/
private int defaultPageSize;
@ConfigurationProperties("powerauth.service.pagination")
public record PowerAuthPageableConfiguration(@Min(0) int defaultPageNumber, @Min(1) int defaultPageSize) {
}

Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public GetActivationListForUserResponse getActivationListForUser(GetActivationLi
try {
final String userId = request.getUserId();
final String applicationId = request.getApplicationId();
final int pageNumber = request.getPageNumber() != null ? request.getPageNumber() : powerAuthPageableConfiguration.getDefaultPageNumber();
final int pageSize = request.getPageSize() != null ? request.getPageSize() : powerAuthPageableConfiguration.getDefaultPageSize();
Pageable pageable = PageRequest.of(pageNumber, pageSize);
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);
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

0 comments on commit f4ac9ab

Please sign in to comment.