Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1702: Use Enum Instead of String for Callback URL Type #1710

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -18,6 +18,7 @@
package com.wultra.security.powerauth.client.model.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

Expand All @@ -36,7 +37,7 @@ public class CallbackUrl {
private String id;
private String applicationId;
private String name;
private String type;
private CallbackUrlType type;
private String callbackUrl;
private List<String> attributes = new ArrayList<>();
private HttpAuthenticationPublic authentication = new HttpAuthenticationPublic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
package com.wultra.security.powerauth.client.model.request;

import com.wultra.security.powerauth.client.model.entity.HttpAuthenticationPrivate;
import com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.hibernate.validator.constraints.time.DurationMin;

Expand All @@ -43,8 +45,8 @@ public class CreateCallbackUrlRequest {
@NotBlank
private String name;

@NotBlank
private String type;
@NotNull
private CallbackUrlType type;
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Shouldn't it be reflected in WebServices-Methods.md?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, added now


@NotBlank
private String callbackUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
package com.wultra.security.powerauth.client.model.request;

import com.wultra.security.powerauth.client.model.entity.HttpAuthenticationPrivate;
import com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.hibernate.validator.constraints.time.DurationMin;

Expand All @@ -46,8 +48,8 @@ public class UpdateCallbackUrlRequest {
@NotBlank
private String name;

@NotBlank
private String type;
@NotNull
private CallbackUrlType type;

@NotBlank
private String callbackUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.wultra.security.powerauth.client.model.entity.HttpAuthenticationPublic;
import com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

Expand All @@ -38,6 +39,7 @@ public class CreateCallbackUrlResponse {
private String id;
private String applicationId;
private String name;
private CallbackUrlType type;
private String callbackUrl;
private List<String> attributes = new ArrayList<>();
private HttpAuthenticationPublic authentication = new HttpAuthenticationPublic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.wultra.security.powerauth.client.model.entity.HttpAuthenticationPublic;
import com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import lombok.Data;
Expand All @@ -40,7 +41,7 @@ public class UpdateCallbackUrlResponse {
private String id;
private String applicationId;
private String name;
private String type;
private CallbackUrlType type;
private String callbackUrl;
private List<String> attributes = new ArrayList<>();
private HttpAuthenticationPublic authentication = new HttpAuthenticationPublic();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* PowerAuth Server and related software components
* Copyright (C) 2024 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.converter;

import io.getlime.security.powerauth.app.server.database.model.enumeration.CallbackUrlType;

/**
* Convertor between CallbackUrlType from client model and CallbackUrlType from database model.
*
* @author Jan Pesek, jan.pesek@wultra.com
*/
public final class CallbackUrlTypeConverter {

public static CallbackUrlType convert(com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType src) {
if (src == null) {
return null;
}

return switch (src) {
case ACTIVATION_STATUS_CHANGE -> CallbackUrlType.ACTIVATION_STATUS_CHANGE;
case OPERATION_STATUS_CHANGE -> CallbackUrlType.OPERATION_STATUS_CHANGE;
};
}

public static com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType convert(CallbackUrlType src) {
if (src == null) {
return null;
}

return switch (src) {
case ACTIVATION_STATUS_CHANGE -> com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType.ACTIVATION_STATUS_CHANGE;
case OPERATION_STATUS_CHANGE -> com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType.OPERATION_STATUS_CHANGE;
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.wultra.security.powerauth.client.model.response.GetCallbackUrlListResponse;
import com.wultra.security.powerauth.client.model.response.RemoveCallbackUrlResponse;
import com.wultra.security.powerauth.client.model.response.UpdateCallbackUrlResponse;
import io.getlime.security.powerauth.app.server.converter.CallbackUrlTypeConverter;
import io.getlime.security.powerauth.app.server.database.model.entity.*;
import io.getlime.security.powerauth.app.server.database.model.enumeration.CallbackUrlType;
import io.getlime.security.powerauth.app.server.database.repository.ApplicationRepository;
Expand Down Expand Up @@ -103,7 +104,7 @@ public CreateCallbackUrlResponse createCallbackUrl(CreateCallbackUrlRequest requ
entity.setId(UUID.randomUUID().toString());
entity.setApplication(applicationEntityOptional.get());
entity.setName(request.getName());
entity.setType(CallbackUrlType.valueOf(request.getType()));
entity.setType(CallbackUrlTypeConverter.convert(request.getType()));
entity.setCallbackUrl(request.getCallbackUrl());
entity.setAttributes(request.getAttributes());
entity.setFailureCount(0);
Expand All @@ -119,6 +120,7 @@ public CreateCallbackUrlResponse createCallbackUrl(CreateCallbackUrlRequest requ
response.setId(entity.getId());
response.setApplicationId(entity.getApplication().getId());
response.setName(entity.getName());
response.setType(CallbackUrlTypeConverter.convert(entity.getType()));
response.setCallbackUrl(entity.getCallbackUrl());
if (entity.getAttributes() != null) {
response.getAttributes().addAll(entity.getAttributes());
Expand Down Expand Up @@ -170,7 +172,7 @@ public UpdateCallbackUrlResponse updateCallbackUrl(UpdateCallbackUrlRequest requ
entity.setName(request.getName());
entity.setCallbackUrl(request.getCallbackUrl());
entity.setAttributes(request.getAttributes());
entity.setType(CallbackUrlType.valueOf(request.getType()));
entity.setType(CallbackUrlTypeConverter.convert(request.getType()));
// Retain existing passwords in case new password is not set
final HttpAuthenticationPrivate authRequest = request.getAuthentication();
final CallbackUrlAuthentication authExisting = callbackUrlAuthenticationCryptor.decrypt(entity);
Expand Down Expand Up @@ -207,7 +209,7 @@ public UpdateCallbackUrlResponse updateCallbackUrl(UpdateCallbackUrlRequest requ
response.setId(entity.getId());
response.setApplicationId(entity.getApplication().getId());
response.setName(entity.getName());
response.setType(entity.getType().toString());
response.setType(CallbackUrlTypeConverter.convert(entity.getType()));
response.setCallbackUrl(entity.getCallbackUrl());
if (entity.getAttributes() != null) {
response.getAttributes().addAll(entity.getAttributes());
Expand Down Expand Up @@ -244,7 +246,7 @@ public GetCallbackUrlListResponse getCallbackUrlList(GetCallbackUrlListRequest r
item.setId(callbackUrl.getId());
item.setApplicationId(callbackUrl.getApplication().getId());
item.setName(callbackUrl.getName());
item.setType(callbackUrl.getType().toString());
item.setType(CallbackUrlTypeConverter.convert(callbackUrl.getType()));
item.setCallbackUrl(callbackUrl.getCallbackUrl());
if (callbackUrl.getAttributes() != null) {
item.getAttributes().addAll(callbackUrl.getAttributes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ void testCallbackUpdate() throws Exception {
updateCallbackUrlRequest.setId(callbackUrlResponse.getId());
updateCallbackUrlRequest.setApplicationId(config.getApplicationId());
updateCallbackUrlRequest.setAuthentication(null);
updateCallbackUrlRequest.setType(CallbackUrlType.ACTIVATION_STATUS_CHANGE.toString());
updateCallbackUrlRequest.setType(CallbackUrlType.ACTIVATION_STATUS_CHANGE);

final UpdateCallbackUrlResponse updateCallbackUrlResponse = powerAuthClient.updateCallbackUrl(updateCallbackUrlRequest);
assertEquals(callbackAttributes, updateCallbackUrlResponse.getAttributes());
Expand Down Expand Up @@ -1106,7 +1106,7 @@ private CreateCallbackUrlRequest createCallbackUrlRequest() {
final CreateCallbackUrlRequest callbackUrlRequest = new CreateCallbackUrlRequest();
callbackUrlRequest.setCallbackUrl(PowerAuthControllerTestConfig.CALLBACK_URL);
callbackUrlRequest.setName(PowerAuthControllerTestConfig.CALLBACK_NAME);
callbackUrlRequest.setType(CallbackUrlType.ACTIVATION_STATUS_CHANGE.name());
callbackUrlRequest.setType(CallbackUrlType.ACTIVATION_STATUS_CHANGE);
callbackUrlRequest.setApplicationId(config.getApplicationId());
callbackUrlRequest.setAttributes(Collections.singletonList("activationId"));
callbackUrlRequest.setAuthentication(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
package io.getlime.security.powerauth.app.server.service.behavior.tasks;

import com.wultra.security.powerauth.client.model.enumeration.CallbackUrlType;
import com.wultra.security.powerauth.client.model.request.UpdateCallbackUrlRequest;
import io.getlime.security.powerauth.app.server.database.model.entity.CallbackUrlEntity;
import io.getlime.security.powerauth.app.server.database.model.enumeration.CallbackUrlType;
import io.getlime.security.powerauth.app.server.service.exceptions.GenericServiceException;
import io.getlime.security.powerauth.app.server.service.model.ServiceError;
import jakarta.persistence.EntityManager;
Expand Down Expand Up @@ -64,7 +64,7 @@ void updateCallbackUrlTest() throws Exception {
request.setCallbackUrl("http://localhost:8080");
request.setAuthentication(null);
request.setName("new-name");
request.setType(CallbackUrlType.OPERATION_STATUS_CHANGE.toString());
request.setType(CallbackUrlType.OPERATION_STATUS_CHANGE);
tested.updateCallbackUrl(request);

final CallbackUrlEntity updated = entityManager.find(CallbackUrlEntity.class, "cafec169-28a6-490c-a1d5-c012b9e3c044");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ public CreateCallbackUrlResponse createCallbackUrl(String applicationId, String
final CreateCallbackUrlRequest request = new CreateCallbackUrlRequest();
request.setApplicationId(applicationId);
request.setName(name);
request.setType(type.toString());
request.setType(type);
request.setCallbackUrl(callbackUrl);
if (attributes != null) {
request.getAttributes().addAll(attributes);
Expand Down Expand Up @@ -899,7 +899,7 @@ public UpdateCallbackUrlResponse updateCallbackUrl(String id, String application
request.setId(id);
request.setApplicationId(applicationId);
request.setName(name);
request.setType(type.toString());
request.setType(type);
request.setCallbackUrl(callbackUrl);
if (attributes != null) {
request.getAttributes().addAll(attributes);
Expand Down